projects-jenz/nosteam_verificiation/python/update_sb.py

45 lines
3.0 KiB
Python
Raw Normal View History

import time
import requests
2022-04-09 21:52:08 +02:00
from settings import (get_connection, key)
def main():
with get_connection() as conn:
with conn.cursor() as cur:
sql_statement = """
select *
from `unloze_anti-spoofing`.sb_bans_shortened sb
left outer join `unloze_anti-spoofing`.connect_restriction cr on
sb.steam_id = cr.steam_id
where cr.asn is null
"""
cur.execute(sql_statement)
res = cur.fetchall()
for index, r in enumerate(res):
steam_id = r[0]
ip = r[1]
2022-04-09 21:52:08 +02:00
url = f"https://proxycheck.io/v2/{ip}?key={key}&asn=1"
jrequest = requests.get(url).json()
#print(jrequest)
d = jrequest[ip]
try:
asn = d["asn"]
provider = d["provider"]
country = d["country"]
except Exception:
print(f'failed: {jrequest}')
continue
with get_connection() as conn:
with conn.cursor() as cur:
sql_statement = """
insert ignore into `unloze_anti-spoofing`.connect_restriction
(country, asn, provider, steam_id, ipv4)
values (%s, %s, %s, %s, %s)
"""
cur.execute(sql_statement, [country, asn, provider, steam_id, ip])
conn.commit()
time.sleep(2.5)
print(f'at {index + 1}/{len(res)}')
if __name__ == '__main__':
main()