Skip to content

Instantly share code, notes, and snippets.

@justgrimes
Created December 16, 2024 20:33
Show Gist options
  • Save justgrimes/e7a1c1d96c65aaf605c575ca8b61c4ab to your computer and use it in GitHub Desktop.
Save justgrimes/e7a1c1d96c65aaf605c575ca8b61c4ab to your computer and use it in GitHub Desktop.
Screenshots for federal domains using pikwy api
#Loop thru csv of federal domains, write screenshots
#!/usr/bin/python3
import csv
import urllib.request
import urllib.parse
import time
from datetime import datetime
#CISA list of Federal domains https://raw.githubusercontent.com/cisagov/dotgov-data/main/current-federal.csv
with open('current-federal.csv', 'r') as csvfile:
next(csvfile, None) # skip the headers
# Return a reader object which will
# iterate over lines in the given csvfile
csv_reader = csv.reader(csvfile)
# convert string to list
#list_of_csv = list(csv_reader)
#print(list_of_csv)
for row in csv_reader:
url = 'https://www.' + row[0]
url_name = row[0]
#agency_name = row[2].replace(" ", "") #remove spaces in agency name for file name
#time.sleep(5) #add a delay - dont need delay
# python3 api example from pikwy https://pikwy.com/api#codeexample
def generate_screenshot_api_url(token, options):
api_url = 'https://api.pikwy.com/?token=' + token
if token:
api_url = api_url + '&url=' + options.get('url')
api_url = api_url + '&width=' + options.get('width')
api_url = api_url + '&height=' + options.get('height')
api_url = api_url + '&response_type=' + options.get('response_type')
return api_url;
token = 'INSERT TOKEN'
options = {
'url': url,
'width': '1280',
'height': '2000',
'response_type': 'image'
}
api_url = generate_screenshot_api_url(token, options)
print(api_url)
timestamp = datetime.now().strftime('%Y%m%d%H%M')
opener = urllib.request.build_opener()
urllib.request.install_opener(opener)
output = url_name + '-' + timestamp + '.png'
urllib.request.urlretrieve(api_url, output)
@justgrimes
Copy link
Author

Output examples acus gov-202412161154
consumerprotection gov-202412161205
mimm gov-202412161206
poolsafely gov-202412161208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment