@@ -36,6 +36,28 @@ def init_Mongo():
36
36
#get sendgrid key
37
37
key = Credential .get_sg_key ()
38
38
39
+ def iterate_all_users (db , col ):
40
+
41
+ returnData = {}
42
+
43
+ for x in col .find ():
44
+
45
+ complaints = getUIDNewComplaints (db , col , x )
46
+ if complaints :
47
+ open_complaints = complaints [0 ]
48
+ closed_complaints = complaints [1 ]
49
+ number = complaints [2 ]
50
+
51
+ emaillist = list (x ['email' ])
52
+
53
+ returnData ["open_complaints" ] = open_complaints
54
+ returnData ["closed_complaints" ] = closed_complaints
55
+ returnData ["number" ] = number
56
+
57
+ if returnData :
58
+ Communications .send_email (key , emaillist , '311 Notification – New Complaint(s) Filed' , returnData )
59
+
60
+
39
61
#remove user from database (only for unit testing purposes)
40
62
def DB_remove_user (col , email ):
41
63
cursor = col .find ({'email' : email })
@@ -110,17 +132,18 @@ def getUIDComplaints(db, col, user_id):
110
132
return "No Complaints Found"
111
133
112
134
#get complaints for a given user based on the current date
113
- def getUIDNewComplaints (db , col , user_id ):
114
- cursor = col .find ({'id' : user_id })
135
+ def getUIDNewComplaints (db , col , doc ):
115
136
start_date = datetime .datetime .now ()
116
137
end_date = datetime .datetime .now () + datetime .timedelta (1 )
117
- start_date = start_date .strftime ("%m/%d/%Y" )
118
- end_date = end_date .strftime ("%m/%d/%Y" )
119
- for x in cursor :
120
- bbl = x ['bbl' ]
121
- result = NYCDBWrapper .findNewComplaints (bbl , start_date , end_date )
122
- return result
123
- return "No Complaints Found"
138
+ #start_date = start_date.strftime("%m/%d/%Y")
139
+ #end_date = end_date.strftime("%m/%d/%Y")
140
+
141
+ bbl = str (doc ['bbl' ])
142
+ print (bbl )
143
+ result = NYCDBWrapper .findDailyComplaints (bbl )
144
+ return result
145
+
146
+ #return "No Complaints Found"
124
147
125
148
#get address for a given user ID
126
149
def getAddress (db , col , UID ):
0 commit comments