Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import os
- import requests
- supbase_url = "https://pxidrgkatumlvfqaxcll.supabase.co/rest/v1/"
- supbase_anon_api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InB4aWRyZ2thdHVtbHZmcWF4Y2xsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njg5OTUzOTgsImV4cCI6MTk4NDU3MTM5OH0.d_yYtASLzAoIIGdXUBIgRAGLBnNow7JG2SoaNMQ8ySg"
- def gen_dict_extract(key, var): #https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-dictionaries-and-lists
- if hasattr(var,'items'):
- for k, v in var.items():
- if k == key:
- yield v
- if isinstance(v, dict):
- for result in gen_dict_extract(key, v):
- yield result
- elif isinstance(v, list):
- for d in v:
- for result in gen_dict_extract(key, d):
- yield result
- trustworthy_usernames = [
- 'Manifold',
- 'memestiny',
- 'BTE',
- 'jack',
- 'Yev',
- 'itsTomekK',
- 'MattP',
- 'egroj',
- 'dreev',
- 'MartinRandall',
- 'LivInTheLookingGlass',
- 'LarsDoucet',
- 'Conflux',
- 'NcyRocks',
- 'MichaelWheatley',
- 'dglid',
- 'yaboi69',
- 'TheSkeward',
- 'Duncn',
- 'a',
- 'NuñoSempere',
- 'CarsonGale',
- 'Tetraspace',
- 'BoltonBailey',
- 'MatthewBarnett',
- 'Jacy',
- 'Gabrielle',
- 'KatjaGrace',
- 'AndrewG',
- 'MarcusAbramovitch',
- 'KevinBurke',
- 'PeterWildeford',
- 'ScottLawrence',
- 'NoaNabeshima',
- 'Mira',
- 'evergreenemily',
- 'SneakySly',
- 'IsaacKing' # added
- ]
- def load_users():
- local_file = f"buffer/users.json"
- if os.path.isfile(local_file):
- with (open(local_file, encoding="utf-8") as json_file):
- return json.load(json_file)
- assembled_url = supbase_url + (f"users"
- f"?select=*"
- f"&apikey={supbase_anon_api_key}")
- loaded_users = requests.get(assembled_url).json()
- with open(local_file, 'w', encoding="utf-8") as outfile:
- json.dump(loaded_users, outfile)
- return loaded_users
- users = load_users()
- def get_user_by_username(username):
- return [x for x in users if x["username"] == username][0]
- def get_trustworthy_users():
- return [x for x in users if x["username"] in trustworthy_usernames]
- def get_user_by_id(user_id):
- return [x for x in users if x["id"] == user_id][0]
- def get_username_by_id(user_id):
- return get_user_by_id(user_id)["username"]
- def get_comments_by_user_id(user_id):
- local_file = f"buffer/{user_id}_comments.json"
- if os.path.isfile(local_file):
- with (open(local_file, encoding="utf-8") as json_file):
- return json.load(json_file)
- assembled_url = supbase_url + (f"contract_comments"
- f"?select=*"
- f"&user_id=eq.{user_id}"
- f"&apikey={supbase_anon_api_key}")
- loaded_comments = requests.get(assembled_url).json()
- with open(local_file, 'w', encoding="utf-8") as outfile:
- json.dump(loaded_comments, outfile)
- return loaded_comments
- search_string = "unresolved markets policy"
- def find_valid_comments():
- total_valid = 0
- trustworthy_users = get_trustworthy_users()
- for trustworthy_user in trustworthy_users:
- user_comments = get_comments_by_user_id(trustworthy_user["id"])
- comment_texts = [" ".join(gen_dict_extract("text", x["data"]["content"])) for x in user_comments if "data" in x and "content" in x["data"]]
- valid_comments = [x for x in comment_texts if search_string in x]
- print(f"Tound {len(valid_comments)} by {trustworthy_user['username']}.")
- total_valid += len(valid_comments)
- print(f"In total {total_valid}.")
- if __name__ == '__main__':
- find_valid_comments()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement