forked from codearranger/denylist_checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_denylist.py
31 lines (25 loc) · 1.26 KB
/
check_denylist.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
from github import Github
import time, os, requests, csv
# Get a token from https://github.com/settings/tokens
# You can do 30 requests per minute (2 second sleep time) when authenticating with a token
# Without authentication you can do 10 requests per minute(6 second sleep time)
GITHUB_TOKEN=os.getenv('GITHUB_TOKEN', None)
g = Github(GITHUB_TOKEN)
sleep_time = 2 if GITHUB_TOKEN else 6
HOTSPOTS_TXT=os.getenv('HOTSPOTS', "hotspots.txt")
DENYLIST_URL='https://raw.githubusercontent.com/helium/denylist/main/denylist.csv'
print("Getting denylist")
res = requests.get(DENYLIST_URL)
decoded_content = res.content.decode('utf-8')
cr = csv.reader(decoded_content.splitlines(), delimiter=',')
deny_list = [hotspot[0] for hotspot in cr]
print("Loading hotspots")
with open(HOTSPOTS_TXT) as file:
hotspots = [line.rstrip() for line in file if not (line.isspace() or line.startswith('#'))]
for addr in hotspots:
print("Checking " + addr)
if (addr in deny_list): print ("Found {addr} in published denylist {url}".format(addr = addr, url=DENYLIST_URL))
issues = g.search_issues("is:open repo:helium/denylist " + addr)
for issue in issues:
print("Found {addr} in {url}".format(addr = addr, url=issue.html_url))
if addr != hotspots[-1]: time.sleep(sleep_time)