jiarongqiu commited on
Commit
e87b320
·
1 Parent(s): 6226c78
Files changed (3) hide show
  1. service/api.py +14 -0
  2. service/scheduler.py +8 -5
  3. util/time.py +22 -0
service/api.py CHANGED
@@ -6,6 +6,7 @@ from typing import Any
6
  from .llm import search_bot
7
  from .vector_store import vector_store
8
  from .logger import logger
 
9
 
10
 
11
  class API():
@@ -69,5 +70,18 @@ class API():
69
  except Exception as e:
70
  print(e)
71
  return data
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  api = API()
 
6
  from .llm import search_bot
7
  from .vector_store import vector_store
8
  from .logger import logger
9
+ from util.time import TimeUtil
10
 
11
 
12
  class API():
 
70
  except Exception as e:
71
  print(e)
72
  return data
73
+
74
+ def get_filecoin_deposit(self):
75
+ url="https://api.spacescope.io/v2/fvm/defi/all_protocol_flow?start_date={}&end_date={}".format(TimeUtil.get_date(offset=-2),TimeUtil.get_date(offset=-1))
76
+ headers = {
77
+ 'authorization': f'Bearer {os.environ["SPACESCOPE_API_KEY"]}'
78
+ }
79
+ data = None
80
+ try:
81
+ response = requests.get(url, headers=headers)
82
+ data = json.loads(response.text)['data'][-1]['total_inflow_fil']
83
+ except Exception as e:
84
+ print(e)
85
+ return data
86
 
87
  api = API()
service/scheduler.py CHANGED
@@ -10,18 +10,21 @@ class Scheduler:
10
 
11
  def __init__(self):
12
  self.scheduler = BackgroundScheduler()
13
- self.jobs = [self.update_filecoin_price]
14
 
15
  def run(self):
16
  for job in self.jobs:
17
  self.scheduler.add_job(job, 'interval', minutes=5)
18
  self.scheduler.start()
19
 
20
- def update_filecoin_price(self):
21
  price = api.get_filecoin_price()
22
- if price is None:
23
- return
24
- text = "The price of filecoin(FIL) is currently ${} USD.".format(price)
 
 
25
  vector_store.upsert(text,"dataset_1")
 
26
 
27
 
 
10
 
11
  def __init__(self):
12
  self.scheduler = BackgroundScheduler()
13
+ self.jobs = [self.update_filecoin_stat]
14
 
15
  def run(self):
16
  for job in self.jobs:
17
  self.scheduler.add_job(job, 'interval', minutes=5)
18
  self.scheduler.start()
19
 
20
+ def update_filecoin_stat(self):
21
  price = api.get_filecoin_price()
22
+ deposit = api.get_filecoin_deposit()
23
+ text = """
24
+ The price of filecoin(FIL) is currently ${} USD.
25
+ The Total DeFi Net Deposits of filecoin(FIL) is {} FIL.
26
+ """.format(price,deposit)
27
  vector_store.upsert(text,"dataset_1")
28
+
29
 
30
 
util/time.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytz
2
+ from datetime import datetime,timedelta
3
+
4
+
5
+ class TimeUtil:
6
+
7
+ @staticmethod
8
+ def get_date(offset=None):
9
+ beijing_tz = pytz.timezone('Asia/Shanghai')
10
+ time = datetime.now(beijing_tz)
11
+ if offset:
12
+ time = time +timedelta(days=offset)
13
+ format_date = time.strftime('%Y-%m-%d')
14
+ return format_date
15
+
16
+ @staticmethod
17
+ def get_time():
18
+ beijing_tz = pytz.timezone('Asia/Shanghai')
19
+ beijing_time = datetime.now(beijing_tz)
20
+ format_time = beijing_time.strftime('%Y-%m-%d %H:%M:%S')
21
+ return format_time
22
+