-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
134 lines (109 loc) · 4.1 KB
/
app.py
File metadata and controls
134 lines (109 loc) · 4.1 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# This would contain all the imports from the individual scripts that is
# for pulling the data
# Our scripts will be stored in the source folder
from json import JSONDecodeError
import time
import sys
import os
sys.path.append('src/')
from src.global_crypto.etl_global_data_bq import global_crypto_main
from src.category_crypto.etl_category_data_bq import category_crypto_main
from src.defillama.etl_defillama_data_bq import defillama_main
from google.cloud import bigquery
## For CLoud SQL or PostGresVM
# from src.global_crypto.etl_global_data import global_crypto_main
# from src.category_crypto.etl_category_data import category_crypto_main
# from src.defillama.etl_defillama_data import defillama_main
from flask import Flask, Response
import requests
# For BQ
# # Turn on this section for Cloud SQL or Postgres VM
app = Flask(__name__)
@app.route("/")
def main():
project_id =''
bq_dataset=''
client = bigquery.Client()
try:
# print("Testing coingecko ping")
# gecko_ping = requests.get('https://api.coingecko.com/api/v3/ping')
# print(gecko_ping.json()['gecko_says'])
# print('Coingecko is ok')
print('Ingesting global crypto data')
global_crypto_main(client, project_id, bq_dataset)
print('Successfully ingested global crypto data')
print('Ingesting category data')
category_crypto_main(client, project_id, bq_dataset)
print('Successfully category data')
print('Ingesting DefiLlama data')
defillama_main(client, project_id, bq_dataset)
print('Successfully ingested Defillama Data!')
except Exception as e:
print('Something has failed, ensuring atomicity. Good bye')
# to intentially break the code for Cloud Scheduler to retry
var1 = var2
return ('Done',200)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0',port=int(os.environ.get("PORT",8080)))
# # Turn on this section for Cloud SQL or Postgres VM
# app = Flask(__name__)
# @app.route("/")
# def main():
# try:
# print("Testing coingecko ping")
# gecko_ping = requests.get('https://api.coingecko.com/api/v3/ping')
# print(gecko_ping.json()['gecko_says'])
# print('Coingecko is ok')
# print('Ingesting global crypto data')
# global_crypto_main()
# print('Successfully ingested global crypto data')
# print('Ingesting category data')
# category_crypto_main()
# print('Successfully category data')
# print('Ingesting DefiLlama data')
# defillama_main()
# print('Successfully ingested Defillama Data!')
# except Exception as e:
# print('Something has failed, ensuring atomicity. Good bye')
# # to intentially break the code for Cloud Scheduler to retry
# var1 = var2
# return ('Done',200)
# if __name__ == '__main__':
# app.run(debug=True, host='0.0.0.0',port=int(os.environ.get("PORT",8080)))
# ## For Local development
# def main():
# # Test if coingecko is working
# try:
# gecko_ping = requests.get('https://api.coingecko.com/api/v3/ping')
# print(gecko_ping.json()['gecko_says'])
# except Exception as e:
# print(str(e))
# print('Coingecko is down')
# # Get global crypto data
# try:
# global_crypto_main()
# except Exception as e:
# print(str(e))
# print('Something wrong with global data coingecko')
# # except JSONDecodeError as je:
# print("global data failed")
# # print('JSONDecodeError, coingecko down')
# pass
# # Get Cateogry Data
# try:
# category_crypto_main()
# # except JSONDecodeError as je:
# except Exception as e:
# print(str(e))
# print('Something wrong with category data CMC')
# # print('JSONDecodeError, CMC down')
# # Get Defi Llama Data
# try:
# defillama_main()
# # except JSONDecodeError as je:
# except Exception as e:
# print(str(e))
# print('Something wrong with Defillama')
# # print('JSONDecodeError, CMC down')
# if __name__ == '__main__':
# main()