-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_dao_report.py
62 lines (49 loc) · 1.96 KB
/
generate_dao_report.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import logging
import os
import pandas as pd
from components.utils import get_db_connection, save_to_csv
from datetime import datetime
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def fetch_dao_references():
"""Fetch all records from the database that mention 'DAO'."""
try:
conn = get_db_connection()
if conn is None:
return pd.DataFrame()
cur = conn.cursor()
query = """
SELECT date, source, headline, sentiment, sentiment_score, label, link
FROM crypto_news
WHERE LOWER(headline) LIKE '%dao%';
"""
cur.execute(query)
df = pd.DataFrame(cur.fetchall(), columns=['Date', 'Source', 'Headline', 'Sentiment', 'Sentiment Score', 'Label', 'Link'])
cur.close()
conn.close()
return df
except Exception as e:
logging.error(f"Error fetching DAO references: {e}")
return pd.DataFrame()
def generate_dao_report(df, output_dir):
"""Generate and save the DAO report."""
if not df.empty:
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)
# Generate a unique filename based on the current date and time
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
output_file = os.path.join(output_dir, f"dao_report_{timestamp}.csv")
save_to_csv(df, output_file)
logging.info(f"DAO report generated and saved to {output_file}.")
else:
logging.warning("No DAO references found in the database.")
def main():
"""Main function to fetch, generate, and save the DAO report."""
df_dao = fetch_dao_references()
if not df_dao.empty:
output_dir = '/media/boilerrat/Bobby/CryptoData/BlockScent/csv'
generate_dao_report(df_dao, output_dir)
else:
logging.warning("No DAO references found; report generation skipped.")
if __name__ == "__main__":
main()