-
Notifications
You must be signed in to change notification settings - Fork 0
/
friends_process.py
48 lines (38 loc) · 1.16 KB
/
friends_process.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
#! Python3
from modules import db2
from time import sleep
import requests
import sys
SESSION = requests.Session()
API = "https://prod-api.kosetto.com/users/"
##################################################
def main():
"""
Function to look for unprocessed users and then process.
"""
address = db2.get_unprocessed_user()
if address is None:
print("No addresses to process. Sleeping for 60s...")
sleep(60)
return
print("Processing: " + address)
metadata = get_metadata(address)
if metadata.get("message") is not None:
db2.flag_friendtech_user(address)
else:
db2.add_friendtech_metadata(address, metadata["id"], metadata["twitterUsername"], metadata["twitterUserId"])
def get_metadata(address):
"""
Function to fetch metadata from friend.tech API.
"""
response = SESSION.get(API + address)
if response.status_code in [200, 404]:
return response.json()
else:
print("Request Error: " + str(response.status_code))
sys.exit(0)
##################################################
# Runtime Entry Point
if __name__ == "__main__":
while True:
main()