Skip to content

Instantly share code, notes, and snippets.

@nickjevershed
Created October 31, 2020 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickjevershed/f058390484f3b99bd4718faac2c35ce6 to your computer and use it in GitHub Desktop.
Save nickjevershed/f058390484f3b99bd4718faac2c35ce6 to your computer and use it in GitHub Desktop.
getFiles.py
import requests
from zipfile import ZipFile
from io import BytesIO
import os
import time
from datetime import datetime
import schedule
timestamp = datetime.strftime(datetime.now(), '%Y%m%d%H%M%S')
url = "https://resultsxml.elections.qld.gov.au/Upload/publicResults.zip"
# Fetching the URL with requests
def getXml():
r = requests.get(url, allow_redirects=False)
print("getting", url, "at", timestamp)
print("status", r.status_code)
if r.status_code != 200:
print("can't get")
if r.status_code == 200:
strFile = BytesIO()
strFile.write(r.content)
with open('files/{timestamp}.zip'.format(timestamp=timestamp), 'wb') as f:
f.write(r.content)
print("done")
# input_zip = ZipFile('files/{timestamp}.zip'.format(timestamp=timestamp), 'r')
# ex_file = input_zip.open("")
# content = ex_file.read()
getXml()
schedule.every(5).minutes.do(getXml)
while True:
schedule.run_pending()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment