ourloc/main.py
2018-03-24 17:58:52 +03:00

53 lines
1.9 KiB
Python

from parse import *
from db import DbHandler
import log
logfile = 'log.txt'
db = DbHandler('77.73.65.40', 'root', 'lfrjnf1961', 'ourloc')
log.log(log.LOG_LEVEL_INFO, 'successfuly connected to the database')
df = parse_domodedovo()
log.log(log.LOG_LEVEL_INFO, "parsed {} flights for domodedovo", len(df), out_file=logfile)
sf = parse_sheremetyevo()
log.log(log.LOG_LEVEL_INFO, "parsed {} flights for sheremetyevo", len(sf), out_file=logfile)
vf = parse_vnukovo()
log.log(log.LOG_LEVEL_INFO, "parsed {} flights for vnukovo", len(vf), out_file=logfile)
query = '''\
INSERT INTO schedule(airport_id, flight_num, direction, planned_time,\
status, descr, rank) values (%s, %s, %s, %s, %s, %s, %s)'''
db.query('UPDATE schedule SET oldnew=0 WHERE airport_id=1 AND oldnew=1')
for flight in df:
idx = 0
db.query(query, (1, flight['flight_id'],
flight['from_city'], flight['time'],
flight['status'], "", idx))
idx += 1
db.query('DELETE FROM schedule WHERE airport_id=1 and oldnew=0')
log.log(log.LOG_LEVEL_INFO, "inserted domodedovo flights", out_file=logfile)
db.query('UPDATE schedule SET oldnew=0 WHERE airport_id=2 AND oldnew=1')
for flight in sf:
idx = 0
db.query(query, (2, flight['flight_id'],
flight['from_city'], flight['time'],
flight['status'], flight['terminal'], idx))
idx += 1
db.query('DELETE FROM schedule WHERE airport_id=2 and oldnew=0')
log.log(log.LOG_LEVEL_INFO, "inserted sheremetyevo flights", out_file=logfile)
db.query('UPDATE schedule SET oldnew=0 WHERE airport_id=3 AND oldnew=1')
for flight in vf:
idx = 0
db.query(query, (3, flight['flight_id'],
flight['from_city'], flight['time'],
flight['status'], flight['terminal'], idx))
idx += 1
db.query('DELETE FROM schedule WHERE airport_id=3 and oldnew=0')
log.log(log.LOG_LEVEL_INFO, "inserted vnukovo flights", out_file=logfile)
db.close()