-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (40 loc) · 1.44 KB
/
app.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
from time import time, sleep
from Pool_Data_Scraper import scrape_data
from pool import Pool
from mongo_server import MongoServer
from mongodb_error import MongoDBException
def main():
db_client = MongoServer()
attempts = 0
while True:
try:
wait_time = 60
print(wait_time - time() % wait_time)
sleep(wait_time - time() % wait_time)
# do work
'''
call function to scrape data from coin gecko and other site to then push to DB
'''
pools = scrape_data()
print("{} number of pools with data to update".format(len(pools)))
for pool in pools:
response = db_client.update_pool(pool)
if response != 0:
response = db_client.insert_pool(pool)
if response != 0:
raise MongoDBException(
"Error pushing data: pool: {} ({}) could not be updated or inserted".format(
pool.get_protocol(), pool.get_assets()))
attempts = 0
except Exception as e:
attempts += 1
# send notification to admin with error
db_client.write_log("Exception thrown: {}".format(e))
# continue for 3 attempts
if attempts == 3:
break
else:
continue
return
if __name__ == "__main__":
main()