File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
scraper_service/shovel_tao_price Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 1
1
import requests
2
2
import logging
3
3
import os
4
- from datetime import datetime
4
+ from datetime import datetime , timedelta
5
5
6
6
CMC_TAO_ID = 22974
7
7
CMC_TOKEN = os .getenv ("CMC_TOKEN" )
@@ -18,15 +18,30 @@ def fetch_cmc_data(params, endpoint):
18
18
return response .json (), response .status_code
19
19
20
20
def get_price_by_time (timestamp ):
21
+
22
+
23
+ # Calculate the time 48 hours ago from now
24
+ time_48_hours_ago = datetime .now () - timedelta (hours = 48 )
25
+
26
+ # Determine the interval based on the timestamp
27
+ if datetime .fromtimestamp (timestamp ) > time_48_hours_ago :
28
+ interval = '5m'
29
+ else :
30
+ interval = '24h'
31
+
21
32
parameters = {
22
33
'id' : CMC_TAO_ID ,
23
34
'convert' : 'USD' ,
24
- 'interval' : '24h' ,
35
+ 'interval' : interval ,
25
36
'time_start' : timestamp ,
26
37
'count' : 1
27
38
}
28
39
29
- data , status_code = fetch_cmc_data (parameters , 'historical' )
40
+ try :
41
+ data , status_code = fetch_cmc_data (parameters , 'historical' )
42
+ except Exception as e :
43
+ logging .error ("Error fetching CMC data: %s" , str (e ))
44
+ return None
30
45
31
46
if status_code == 200 and 'data' in data and 'quotes' in data ['data' ]:
32
47
quote = data ['data' ]['quotes' ][0 ]
You can’t perform that action at this time.
0 commit comments