Setup initial CI gating on tests and add linting tests (#85)

* add flake, black, mypy, and bandit to run

* fixes issues flake and black complained about

* make mypy run successfully, add configuration files rather than specifying in ci

* respond to feedback

* configure bandit, ignore a file used only in local development
This commit is contained in:
Logan McDonald 2022-08-26 12:36:02 -04:00 committed by GitHub
parent e288578028
commit 8f41050f76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 124 additions and 71 deletions

View file

@ -11,25 +11,29 @@ NOTE: This requries python-whois and argparse to be installed.
import csv
import requests
import whois # this is python-whois
import whois # this is python-whois
import argparse
import sys
from pathlib import Path
GOV_URLS_CSV_URL = "https://raw.githubusercontent.com/GSA/govt-urls/master/1_govt_urls_full.csv"
GOV_URLS_CSV_URL = (
"https://raw.githubusercontent.com/GSA/govt-urls/master/1_govt_urls_full.csv"
)
data = requests.get(GOV_URLS_CSV_URL).text
csv_data = list(csv.reader(data.splitlines(), delimiter=','))
csv_data = list(csv.reader(data.splitlines(), delimiter=","))
domains = csv_data[1:]
fields = csv_data[0] + ['Registrar']
fields = csv_data[0] + ["Registrar"]
def check_registration(name):
try:
domain_info = whois.whois(name)
return domain_info['registrar']
return domain_info["registrar"]
except KeyboardInterrupt:
sys.exit(1)
except:
print(f'Something went wrong with that domain lookup for {name}, continuing...')
print(f"Something went wrong with that domain lookup for {name}, continuing...")
def main(domain):
@ -40,7 +44,11 @@ def main(domain):
else:
for idx, domain in enumerate(domains):
domain_name = domain[0].lower()
if domain_name.endswith('.com') or domain_name.endswith('.edu') or domain_name.endswith('.net'):
if (
domain_name.endswith(".com")
or domain_name.endswith(".edu")
or domain_name.endswith(".net")
):
print(idx)
print(domain_name)
registrar = check_registration(domain_name)
@ -48,15 +56,17 @@ def main(domain):
Path("../data").mkdir(exist_ok=True)
with open('../data/registrar_data.csv', 'w') as f:
with open("../data/registrar_data.csv", "w") as f:
writer = csv.writer(f)
writer.writerow(fields)
writer.writerows(full_data)
if __name__ == '__main__':
if __name__ == "__main__":
cl = argparse.ArgumentParser(description="This performs ICANN lookups on domains.")
cl.add_argument("--domain", help="finds the registrar for a single domain", default=None)
cl.add_argument(
"--domain", help="finds the registrar for a single domain", default=None
)
args = cl.parse_args()
sys.exit(main(args.domain))