-
Notifications
You must be signed in to change notification settings - Fork 0
/
cryptostats_treasuries.py
80 lines (60 loc) · 1.8 KB
/
cryptostats_treasuries.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
70
71
72
73
74
75
76
77
78
79
80
#! Python3
"""
File name: treasuries.py
Author: Jonathan Snow
Date created: 10/21/2022
Python Version: 3.9.x
File Details:
Purpose: A series of functions to determine balances of Protocol treasuries.
"""
# Imports
import requests
from modules import data
##################################################
def main():
"""
Function to gather treasury addresses from Cryptostats.
"""
# Get list of DAOs to process
treasuries = get_treasuries()
output_data = []
# Process protocol treasury data
for key in treasuries:
output = []
output.append(key)
for address in treasuries[key]:
output.append(address)
output_data.append(output)
# Dump treasury data to CSV
output_path = "files/output"
output_name = "treasury_addresses.csv"
data.save(output_data, output_path, output_name,
["name", "ta-1", "ta-2", "ta-3", "ta-4", "ta-5", "ta-6", "ta-7", "ta-8"]
)
##################################################
def get_treasuries():
"""
Function to fetch a list of treasuries from
the CryptoStats API.
"""
url = "https://api.cryptostats.community/api/v1/treasuries/currentTreasuryUSD"
# Get list of treasuries
treasuries = get_data(url)["data"]
output = {}
# Simplify treasury data
for treasury in treasuries:
tid = treasury["id"]
output[tid] = treasury["metadata"]["treasuries"]
return output
##################################################
def get_data(url):
"""
Function to fetch data from URL and return JSON
"""
with requests.Session() as s:
response = s.get(url)
return response.json()
##################################################
# Runtime Entry Point
if __name__ == "__main__":
main()