<commit_before>from flask import Flask, render_template, jsonify, request, g, session
from flask_googlemaps import GoogleMaps
from flask_googlemaps import Map

from transit import get_gtfs_data
from transit import get_real_time_data_request_response
from transit import get_bus_list
from transit import get_all_current_position_markers

import requests
import json
from collections import namedtuple
import datetime
import os
import pandas as pd

from helper import merge_two_dicts

DEFAULT_LOCATION = {u'lat': 39.7433814, u'lng': -104.98910989999999}

app = Flask(__name__, template_folder="./templates")
GoogleMaps(app)

@app.route("/update")
def update():
    get_gtfs_data(force=True)
    return("Update complete")

@app.route("/data")
def data():

    print(request.args)

    data_info = request.args.get('info', None)

    if data_info == 'bus_list':
        get_gtfs_data()
        all_buses_df = pd.read_csv('trips.txt')
        return json.dumps({'bus_list': get_bus_list(all_buses_df)})

    if data_info == 'set_position':
        print('inside set_position')
        current_location = json.loads(request.args.get('data'))
        # session['current_location'] = current_location
        return(json.dumps({'position': current_location}))

    if data_info == 'request':
        route = request.args.get('data')
        print(route)
        current_location = DEFAULT_LOCATION
        data = get_all_current_position_markers(route, current_location)
        print(data)
        data['routes'] = [route]
        return(json.dumps(data))


@app.route("/")
def mapview():
    # creating a map in the view

    headers = get_real_time_data_request_response(header=True)
    last_modified = headers['Last-Modified']

    UTC_OFFSET = 7
    dt = datetime.datetime.strptime(last_modified, '%a, %d %b %Y %H:%M:%S GMT')
    dt = dt - datetime.timedelta(hours=UTC_OFFSET)
    last_modified = dt.strftime('%a, %d %b %Y %H:%M:%S MST')

    return render_template('map.html', last_modified=last_modified, json_api_key=os.getenv('JSON_API'))

if __name__ == "__main__":
    app.secret_key = os.getenv('SECRET_KEY', 'SECRET_KEY')
    app.debug = os.getenv('DEBUG', False)
    app.threaded = os.getenv('THREADED', False)
    app.run()<commit_msg>Begin reimagining of implementation of the Flask api<commit_after>from flask import Flask, render_template, jsonify, request, g, session
from flask_googlemaps import GoogleMaps
from flask_googlemaps import Map

from transit import get_gtfs_data
from transit import get_real_time_data_request_response
from transit import get_bus_list
from transit import get_all_current_position_markers

import requests
import json
from collections import namedtuple
import datetime
import os
import pandas as pd

from helper import merge_two_dicts

DEFAULT_LOCATION = {u'lat': 39.7433814, u'lng': -104.98910989999999}

app = Flask(__name__, template_folder="./templates")
GoogleMaps(app)

@app.route("/bus/", defaults={'route_number': None, 'route_name': None} )
@app.route("/bus/<route_number>/<route_name>")
def bus_info(route_number, route_name):
    data = {
            'route': {'number': route_number, 
                    'name': route_name}
            }
    return(json.dumps(data))

@app.route("/")
def mapview():
    return render_template('map.html', json_api_key=os.getenv('JSON_API'))

if __name__ == "__main__":
    app.secret_key = os.getenv('SECRET_KEY', 'SECRET_KEY')
    app.debug = os.getenv('DEBUG', False)
    app.threaded = os.getenv('THREADED', False)
    app.run()
{'fraction_non_alphanumeric': 0.11824900511654349, 'fraction_numerical': 0.015065378055713473, 'mean_word_length': 4.422187981510016, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2697148', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1135, 'n_words': 263}