-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaidy.py
47 lines (36 loc) · 1.44 KB
/
aidy.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
import os
from datetime import datetime
from hashlib import sha256
from typing import List
from dotenv import load_dotenv
import requests
from logger import Logger
load_dotenv()
# Set up logging
logging = Logger.setup_logger(__name__)
AIDY_API_URL = os.environ.get('AIDY_API_URL') + "/api/topics/summarizer"
AIDY_TOPICS = os.environ.get('AIDY_TOPICS').split(",")
def pull_from_aidy(already_pushed: list[str]) -> List[str]:
aidy_queue = []
try:
for topic in AIDY_TOPICS:
logging.info(f"Requesting bills for topic: {topic}")
# Make API request
response = requests.get(f"{AIDY_API_URL}/{topic}")
response.raise_for_status() # Will raise HTTPError if the status code is 4xx, 5xx
response = response.json()
summary = response["current_summary"]
created_id = sha256(response["current_summary"].encode()).hexdigest()
if created_id in already_pushed:
logging.info(f"Already pushed {created_id}")
continue
logging.info("Successfully retrieved response from AIDY API.")
aidy_queue.append(summary)
already_pushed.append(created_id)
return aidy_queue
except requests.exceptions.RequestException as req_err:
logging.error(f"Request error: {req_err}")
except Exception as e:
logging.error(f"An error occurred: {str(e)}")
# raise e
return aidy_queue