-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_extractor.py
More file actions
42 lines (33 loc) · 1.56 KB
/
data_extractor.py
File metadata and controls
42 lines (33 loc) · 1.56 KB
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
import requests
import csv
class Crypto_Fetcher:
def __init__(self, target_coins):
self.coins_string = ",".join(target_coins)
self.raw_data = {}
def fetch_data(self):
url = f'https://api.coingecko.com/api/v3/simple/price?ids={self.coins_string}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true'
print('Fathom OS is connecting to the API for target data....')
response = requests.get(url)
if response.status_code == 200:
self.raw_data = response.json()
print('[+] data extracted successfully!')
else:
print(f'[-] FATHOM OS ERROR: Target server returned code: {response.status_code}')
def export_to_csv(self):
if not self.raw_data:
print('[-] no data export')
return
print('[+] generatinf Fathom os Spreadsheet.....')
with open('crypto_report.csv', mode='w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['Asset Name', 'Price (USD)', '24h Volume', 'Market Cap'])
for coin, stats in self.raw_data.items():
price = stats['usd']
volume = stats['usd_24h_vol']
market_cap = stats['usd_market_cap']
writer.writerow([coin.capitalize(), price, volume, market_cap])
print('[$$$] BREACH SUCCESS: crypto_report.csv has been saved to your vault.')
targets = ['solana', 'bitcoin', 'ethereum']
analyzer = Crypto_Fetcher(targets)
analyzer.fetch_data()
analyzer.export_to_csv()