Skip to content

Instantly share code, notes, and snippets.

@nickjevershed
Last active October 31, 2020 09:10
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/b9751d4197eafb21193fb90fa49fdab0 to your computer and use it in GitHub Desktop.
Save nickjevershed/b9751d4197eafb21193fb90fa49fdab0 to your computer and use it in GitHub Desktop.
import requests
from zipfile import ZipFile
from io import BytesIO
import os
import time
from datetime import datetime
import schedule
url = "https://resultsxml.elections.qld.gov.au/Upload/publicResults.zip"
# Fetching the URL with requests
def getXml():
timestamp = datetime.strftime(datetime.now(), '%Y%m%d%H%M%S')
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