Esempio n. 1
0
def get_direct_trains():
    src = str(request.args['src']).split('-')[-1]
    dst = str(request.args['dst']).split('-')[-1]
    jdate = str(request.args['jdate'])
    jclass = str(request.args['jclass'])
    db = connect_to(CREDS_FILE)
    with db.cursor() as cur:
        head, body = fetch_data(src, dst, jdate, jclass, direct_query, cur)
    offset = str(request.args['offset'])
    db = connect_to(CREDS_FILE)
    with db.cursor() as cur:
        head, body = fetch_data(src, dst, jdate, jclass, direct_query, cur,
                                offset)
    db.close()
    response = {}
    response['head'] = head
    response['body'] = body
    response['type'] = 1
    return json.dumps(response, default=str)
Esempio n. 2
0
def get_registered():
    print(request.form)
    src = str(request.form['src']).split('-')[-1]
    dst = str(request.form['dst']).split('-')[-1]
    jdate = str(request.form['jdate'])
    jclass = str(request.form['jclass'])
    sub_str = str(request.form['sub'])
    quota = str(request.form['quota'])
    cur_date = int(float(request.form['cur_date']))
    db = connect_to(CREDS_FILE)
    with db.cursor() as cur:
        head, body = fetch_data(src, dst, jdate, jclass, direct_query, cur)
    db.close()
    trn_idx = list(head).index('Train_No')
    dt_idx = list(head).index('Dept_Time')
    trains = [row[trn_idx] for row in body]
    max_timestamp = max([time.mktime(row[dt_idx].timetuple()) for row in body])
    check_cnt = (1 if ((max_timestamp - cur_date) %
                       (900)) > 0 else 0) + (max_timestamp - cur_date) // (900)
    Thread(target=curravail_thread,
           args=(list(trains), src, dst, jclass, quota, jdate, check_cnt,
                 sub_str)).start()
    send_push(sub_str, "trains checked" + ",".join(trains))
    return "Registered Successfully!!"