Last active
October 31, 2020 09:10
-
-
Save nickjevershed/b9751d4197eafb21193fb90fa49fdab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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