-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.py
executable file
·46 lines (43 loc) · 1.74 KB
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from pymongo import MongoClient;
from bson.objectid import ObjectId
from twilio.rest import Client
import datetime
class Trash:
def __init__(self):
self.mongo_url = "mongodb://arihantsaiparuchuru:Arihant123@ds041157.mlab.com:41157/trash-capacity-notifier"
self.mongo_db = "trash-capacity-notifier"
self.mongo_db_collection = "TrashCapacity"
self.bin_id = "5bfeef7033a5340fd7215b7a"
self.bin_max_height = 300
self.bin_location = "MLK Library"
self.client = MongoClient(self.mongo_url)
self.db = self.client[self.mongo_db]
self.collection = self.db[self.mongo_db_collection]
def sendMessage(self,height):
account_sid = 'AC23077766b89b43b4b33b5dd31e396dab'
auth_token = '4885dc1d2ac83e2abbc00ba725f88ada'
client = Client(account_sid, auth_token)
msg = "The bin placed at "+self.bin_location+" is about to get completely filled. It needs assitance."
message = client.messages.create(body=msg,from_='+19133183697',to='+16692138942')
print("Message SID :",message.sid)
def updateBin(self,height):
now = datetime.datetime.now().isoformat().split(".")[0]
d={"height":height,"timestamp":now}
try:
self.collection.update_one({"_id":ObjectId(self.bin_id)},{ "$addToSet": { "capacity": d } })
if(abs(self.bin_max_height-height)<20):
self.sendMessage(height)
except:
with open("bin.log","a+") as f:
f.write("Connection Error on : "+now+" | "+str(d)+"\n")
""""
new_data = [
{"location":"MLK Floor 1","max_height":"200","capacity":[]},
{"location":"MLK Floor 2","max_height":"200","capacity":[]}
]
"""
"""
bin = Trash()
for i in range(300,320):
bin.updateBin(i)
"""