diff --git a/main.py b/main.py index d6e1f55..4e48804 100644 --- a/main.py +++ b/main.py @@ -15,11 +15,18 @@ def main(): print(datetime.now(tz)) # print("hola") - content = download_file_proto() - if content == None: + fileproto = download_file_proto() + if fileproto == None: return False + + namefile = r.get('fileproto') + if namefile == fileproto['name']: + print(namefile) + return - data = read_file_proto_x_stop(content) + r.set('fileproto', fileproto['name']) + print(fileproto['name']) + data = read_file_proto_x_stop(fileproto['content']) # save data to redis db for key in data: @@ -31,7 +38,9 @@ def main(): def download_file_proto(): response = requests.get('https://app.ilab.cl/gtfs-rt/api/concepcion') if response.status_code == 200: - return response.content + content_disposition = response.headers['Content-Disposition'] + nombre_archivo = content_disposition.split('filename=')[1] + return { 'name': nombre_archivo, 'content': response.content } return None