patch
parent
fbd02757c4
commit
42afbdc590
|
@ -110,17 +110,11 @@ services:
|
|||
- 4005:4000
|
||||
environment:
|
||||
- TZ=America/Santiago
|
||||
- PORT=4000
|
||||
- DBHOST=db
|
||||
- DBPORT=4080
|
||||
- DBNAME=database
|
||||
- DBSCHEMA=desarrollo1
|
||||
- DBUSER=postgres
|
||||
- DBPASS=password
|
||||
|
||||
- DB_REDIS_HOST=dbredis
|
||||
- DB_REDIS_PORT=4081
|
||||
- SECRET_JWT="kf6Jc!f30Z!1k1N0#!%#"
|
||||
|
||||
- INTERVAL=20
|
||||
- BACKEND=http://swarm01.tdtp.ilab.cl:4001/gtfs-rt/api/concepcion
|
||||
|
||||
- SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://dev_feed:testing99901@db01.tdtp.ilab.cl/devrt
|
||||
- TIMEOUT=1200
|
||||
|
|
|
@ -1,11 +1,45 @@
|
|||
# coding: utf-8
|
||||
from apscheduler.schedulers.background import BlockingScheduler
|
||||
from main import main as rutina_principal
|
||||
from main import read_file_proto_x_stop, r
|
||||
import logging
|
||||
import os
|
||||
|
||||
sched = BlockingScheduler()
|
||||
sched.add_job(rutina_principal, 'interval', seconds=int(os.environ.get('INTERVAL'))) #will do the print_t work for every 30 seconds
|
||||
|
||||
def rutina_principal():
|
||||
print(datetime.now(tz))
|
||||
|
||||
fileproto = download_file_backend()
|
||||
if fileproto == None:
|
||||
return False
|
||||
|
||||
namefile = r.get('fileproto')
|
||||
if namefile == fileproto['name']:
|
||||
print(namefile, flush=True)
|
||||
return
|
||||
|
||||
# eliminar toda la informacion actual
|
||||
r.flushdb()
|
||||
|
||||
r.set('fileproto', fileproto['name'])
|
||||
print(fileproto['name'], flush=True)
|
||||
data = read_file_proto_x_stop(fileproto['content'])
|
||||
|
||||
# save data to redis db
|
||||
for key in data:
|
||||
r.set(key, json.dumps(data[key]))
|
||||
|
||||
# print(json.dumps(data['route:549-1'], indent=4))
|
||||
|
||||
|
||||
def download_file_backend():
|
||||
response = requests.get(os.environ.get('BACKEND'))
|
||||
if response.status_code == 200:
|
||||
content_disposition = response.headers['Content-Disposition']
|
||||
nombre_archivo = content_disposition.split('filename=')[1]
|
||||
return { 'name': nombre_archivo, 'content': response.content }
|
||||
return None
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db(db, engine)
|
||||
|
|
Loading…
Reference in New Issue