-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconf.py
49 lines (40 loc) · 1.13 KB
/
conf.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
47
48
49
# -*- coding:utf8 -*-
import requests
import time
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["test"]
myinfo = mydb['info']
myreview = mydb['review']
mydata = mydb['data']
lastTime = time.time()
waitTime = 5*60.0/195
def send_req(url, wait = True):
global lastTime
global waitTime
retryTimes = 1
response = None
result = None
while retryTimes > 0:
try:
response = requests.get(url)
if response:
result = response.json()
except Exception as e:
print(e)
print(time.strftime('%Y-%m-%d %H:%M:%S'))
sleepTime = lastTime + waitTime - time.time()
if(sleepTime > 0 and wait):
print(time.strftime('%Y-%m-%d %H:%M:%S sleep for' + str(sleepTime)))
time.sleep(sleepTime)
lastTime = time.time()
retryTimes -= 1
return result
def merge_two_dicts(x, y):
if not x:
return y
elif not y:
return x
z = x.copy() # start with x's keys and values
z.update(y) # modifies z with y's keys and values & returns None
return z