| 23 | |
| 24 | # gets data from cloud database and calls 5 min prior the time (from time) allotted in the database |
| 25 | def search(): |
| 26 | calling_time = datetime.now() |
| 27 | one_hours_from_now = (calling_time + timedelta(hours=1)).strftime("%H:%M:%S") |
| 28 | current_date = str(strftime("%d-%m-%Y", gmtime())) |
| 29 | docs = db.collection("on_call").where("date", "==", current_date).stream() |
| 30 | list_of_docs = [] |
| 31 | for doc in docs: |
| 32 | c = doc.to_dict() |
| 33 | if (calling_time).strftime("%H:%M:%S") <= c["from"] <= one_hours_from_now: |
| 34 | list_of_docs.append(c) |
| 35 | print(list_of_docs) |
| 36 | |
| 37 | while list_of_docs: |
| 38 | timestamp = datetime.now().strftime("%H:%M") |
| 39 | five_minutes_prior = (timestamp + timedelta(minutes=5)).strftime("%H:%M") |
| 40 | for doc in list_of_docs: |
| 41 | if doc["from"][0:5] == five_minutes_prior: |
| 42 | phone_number = doc["phone"] |
| 43 | call = client.calls.create( |
| 44 | to=phone_number, |
| 45 | from_="add your twilio number", |
| 46 | url="http://demo.twilio.com/docs/voice.xml", |
| 47 | ) |
| 48 | list_of_docs.remove(doc) |