Created
October 31, 2020 08:18
-
-
Save nickjevershed/f058390484f3b99bd4718faac2c35ce6 to your computer and use it in GitHub Desktop.
getFiles.py
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 | |
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