-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (54 loc) · 1.93 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
70
71
72
73
74
import etherscan
import time
import os
import json
from dotenv import load_dotenv
from config.config import Config
from utils import utils
config = Config()
def initialize_etherscan_client():
return etherscan.Client(
api_key=os.getenv("API_KEY"),
cache_expire_after=5,
)
def retrieve_donut_transactions(es, reddit_user, input_data):
name = reddit_user["username"]
blockchain_address = reddit_user["address"]
input_data["api_calls"] = utils.freeze_process(input_data["api_calls"])
print(f"Retrieving data from: {name}")
donut_transactions = es.get_token_transactions(
contract_address=config.donut_contract,
address=blockchain_address,
)
input_data["api_calls"] += 1
return donut_transactions
def process_reddit_user(reddit_user, donut_transactions, input_data):
if donut_transactions:
reddit_user = utils.calculate_special_membership(
reddit_user,
donut_transactions,
utils.get_limit_timestamp(input_data),
)
return reddit_user
def main(input_data):
start_time = time.time()
es = initialize_etherscan_client()
sp_memb_data = []
with open(config.special_membership_file_path, "r") as file:
reddit_users = json.load(file)
for reddit_user in reddit_users:
if reddit_user["activeMembership"]:
donut_transactions = retrieve_donut_transactions(
es, reddit_user, input_data
)
reddit_user = process_reddit_user(
reddit_user, donut_transactions, input_data
)
sp_memb_data.append(reddit_user)
if len(sp_memb_data) > 0:
utils.save_data(sp_memb_data, input_data)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"The process took {elapsed_time:.2f} seconds to complete.")
load_dotenv()
main({"isRedditSunset": False, "api_calls": 0})