forked from render-examples/flask-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbsandbox.py
More file actions
40 lines (28 loc) · 994 Bytes
/
Copy pathdbsandbox.py
File metadata and controls
40 lines (28 loc) · 994 Bytes
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
from pprint import pprint
from pymongo import MongoClient
from datetime import datetime
import pytz
from apscheduler.schedulers.background import BackgroundScheduler
import time
#NOTE : Need this package for MongoClient init
#Without it, SSL CERTIFICATE VERIFY FAILED EXCEPTION
#Should find a better solution but i got fed up lol
import certifi
# import database
CONNECTION_STRING = "mongodb+srv://smartplugadmin:uodqp8ln7wOyKSMV@cluster0.gu6op.mongodb.net/SmartPlugDatabase?retryWrites=true&w=majority"
print("Doing sandbox stuff with database")
sched = BackgroundScheduler(daemon=True)
def myTask():
print("Running scheduled task!")
sched.add_job(myTask,'cron',minute=7)
sched.start()
for i in range(0, 60):
print("Waiting")
time.sleep(1)
sched.shutdown()
exit()
client = MongoClient(CONNECTION_STRING, tlsCAFile=certifi.where()) #overhead setup
db = client.SmartPlugDatabase
userscollection = db.users
plugscollection = db.plugs
pricescollection = db.prices