-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (56 loc) · 2.29 KB
/
main.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
63
64
65
66
67
68
69
import time
from datetime import datetime
import os
from crypto_analyzer import CryptoAnalyzer
def main():
"""
Main function to run the cryptocurrency tracking system.
Fetches data every 5 minutes, updates Excel, and generates analysis.
"""
# Initialize the analyzer
analyzer = CryptoAnalyzer(
excel_file='crypto_data.xlsx',
report_file='analysis_report.md'
)
# Set update interval (5 minutes)
update_interval = 300
print("\n=== Cryptocurrency Tracker Starting ===")
print(f"Update Interval: {update_interval} seconds")
print(f"Excel File: {os.path.abspath(analyzer.excel_file)}")
print(f"Report File: {os.path.abspath(analyzer.report_file)}")
print("=====================================\n")
while True:
try:
# Get current timestamp
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"\nStarting update at {current_time}")
# 1. Fetch cryptocurrency data
print("Fetching cryptocurrency data...")
crypto_data = analyzer.fetch_crypto_data()
if crypto_data is not None:
# 2. Analyze the data
print("Analyzing data...")
analysis = analyzer.analyze_data(crypto_data)
# 3. Update Excel file
print("Updating Excel file...")
analyzer.update_excel(crypto_data)
# 4. Generate analysis report
print("Generating report...")
analyzer.generate_report()
print(f"Update completed successfully")
else:
print("Failed to fetch data")
# Wait for next update
print(f"Waiting {update_interval} seconds until next update...")
time.sleep(update_interval)
except KeyboardInterrupt:
print("\nProgram stopped by user")
print("Generating final report...")
analyzer.generate_report()
break
except Exception as e:
print(f"\nError occurred: {str(e)}")
print("Retrying in 60 seconds...")
time.sleep(60)
if __name__ == "__main__":
main()