From a6c86a4753d292717935ac9b017fc8ab0a7f4ac5 Mon Sep 17 00:00:00 2001 From: Francisco Sandoval Date: Wed, 13 Dec 2023 10:15:53 -0300 Subject: [PATCH] agrego nombre de archivo proto para omitir escritura si es la misma informacion --- main.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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