def hello(): db = dbQueries(path) data = db.get_all_names() # change list of tuples to list formatted = [tuple[0] for tuple in data] return render_template("home.html", mdata=formatted)
def test_num_bikes(address): db = dbQueries(path) mdata = db.get_all_names() # change list of tuples to list formatted = [tuple[0] for tuple in mdata] address = address.replace("-", " ") id = db.station_to_ID(address) banking = db.take_credit(id) if banking == True: banking = "Yes" else: banking = "No" count = db.get_valid_real_time_count() # check if there was valid real_time data if count == 0: # fetch data from api data = helpers.request_new_data() db.insert_new_real_time_values(data, True) # fetch all data to send back real_time = db.get_real_time(id) data = real_time[0] return render_template('station.html', Data=data, Address=address, mdata=formatted, Banking=banking)
def test_num_bikes(address): db = dbQueries("bikes.db") mdata = db.get_all_names() # change list of tuples to list formatted = [tuple[0] for tuple in mdata] address = address.replace("-", " ") id = db.station_to_ID(address) banking = db.take_credit(id) if banking == True: banking = "Yes" else: banking = "No" count = db.get_valid_real_time_count() # check if there was valid real_time data if count == 0: # fetch data from api data = helpers.request_new_data() db.insert_new_real_time_values(data, True) # fetch all data to send back real_time = db.get_real_time(id) data = real_time[0] return render_template('station.html', Data=data, Address = address, mdata = formatted, Banking = banking )
def hello(): db = dbQueries("bikes.db") data = db.get_all_names() # change list of tuples to list formatted = [tuple[0] for tuple in data] return render_template("home.html" ,mdata = formatted)
def real_time_by_station(id): db = dbQueries(path) count = db.get_valid_real_time_count() # check if there was valid real_time data if count == 0: # fetch data from api data = helpers.request_new_data() db.insert_new_real_time_values(data, True) # fetch all data to send back real_time = db.get_real_time(id) # send results back return json.dumps(real_time)
def real_time_by_station(id): db = dbQueries("bikes.db") count = db.get_valid_real_time_count() # check if there was valid real_time data if count == 0: # fetch data from api data = helpers.request_new_data() db.insert_new_real_time_values(data, True) # fetch all data to send back real_time = db.get_real_time(id) # send results back return json.dumps(real_time)
def station(name): """ Gets station information based on the address and loads the appropriate static template """ db = dbQueries(path) # convert name to address name = helpers.url_to_name(name) info = db.static_info_by_name(name) if (len(info) == 0): error = "That station does not appear to exist" return render_template('404.html', mdata=error), 404 return json.dumps(info)
def station(name): """ Gets station information based on the address and loads the appropriate static template """ db = dbQueries("bikes.db") # convert name to address name = helpers.url_to_name(name) info = db.static_info_by_name(name) if (len(info) == 0): error = "That station does not appear to exist" return render_template('404.html', mdata=error), 404 return json.dumps(info)
def to_static_template(location): ''' Used for passing information to the static template ''' database = dbQueries("bikes.db") name = location id = station_to_ID(name) address = station_address_by_ID(id) position = station_coordinates_by_ID(id) available_bikes = available_bike_stands(id, time) available_bike_stands = available_bike_stands(id, time) take_credit = take_credit(id) return render_template('static-template.html', name=tempName, address=tempAddress, position=tempPosition, available_bikes=availableBikes, available_bike_stands=availableBikeStands)
def real_time(): db = dbQueries("bikes.db") count = db.get_valid_real_time_count() # check if there was valid real_time data print(count) if count == 0: # fetch data from api print("no valid data. Fetching new data") data = helpers.request_new_data() db.insert_new_real_time_values(data) # fetch all data to send back real_time = db.get_real_time() db.close_connection() # send results back return json.dumps(real_time)
def api(): return "usage:<br> api/station\ <br> api/static/YOUR_STATION_ID/YOUR_DAY\ <br> api/real-time\ <br> api/real-time/station/YOUR_STATION_ID" # db has to be inside function otherwise error about db being created in another thread db = dbQueries("bikes.db") racknum = request.args.get('racknum') max_racknum = db.num_bike_stations() if int(racknum) > max_racknum: # http://flask.pocoo.org/docs/0.10/patterns/errorpages/ # return render_template('test.html', mData = data) error = "station number out of range. Max is " + (str)(max_racknum) return render_template('404.html', mdata=error), 404 # return render_template('404.html'), 404 else: return racknum
def api(): return "usage:<br> api/station\ <br> api/static/YOUR_STATION_ID/YOUR_DAY\ <br> api/real-time\ <br> api/real-time/station/YOUR_STATION_ID" # db has to be inside function otherwise error about db being created in another thread db = dbQueries(path) racknum = request.args.get('racknum') max_racknum = db.num_bike_stations() if int(racknum) > max_racknum: # http://flask.pocoo.org/docs/0.10/patterns/errorpages/ # return render_template('test.html', mData = data) error = "station number out of range. Max is " + (str)(max_racknum) return render_template('404.html', mdata=error), 404 # return render_template('404.html'), 404 else: return racknum
def real_time(): f = open("/tmp/db.log", "a") f.write("server.py " + path + "\n") f.close() db = dbQueries(path) count = db.get_valid_real_time_count() # check if there was valid real_time data print(count) if count == 0: # fetch data from api print("no valid data. Fetching new data") data = helpers.request_new_data() db.insert_new_real_time_values(data) # fetch all data to send back real_time = db.get_real_time() db.close_connection() # send results back return json.dumps(real_time)
def historical_data(id, day=None): """ gets historical data for a station by id. Used by the client side """ # get all station information by id. db = dbQueries("bikes.db") max_station = db.max_station() if day is not None: if 0 < (int)(id) <= max_station and 0 <= (int)(day) <= 6: info = db.get_historical_info_by_id_and_day(id, day) else: error = "Station must be between 1 and " + (str)(max_station) + ". Day must be between 0 and 6" return render_template('404.html', mdata=error), 404 else: if 0 < (int)(id) <= max_station: info = db.get_historical_info_by_id(id) else: error = "Station must be between 0 and " + (str)(max_station) return render_template('404.html', mdata=error), 404 return json.dumps(info)
def setup_db(): db = dbQueries(path) db.setup_db() return "setting up database"
def setup_db(): db = dbQueries("bikes.db") db.setup_db() return "setting up database"
# Reference: # Nose.readthedocs.org. 'Writing Tests - Nose 1.3.7 Documentation', available: # https://nose.readthedocs.org/en/latest/writing_tests.html [Accessed: 25/03/16] __author__ = "Ellen Rushe" from src.dbQueries import dbQueries # Test using 'bikes' database. dbq = dbQueries('bikes.db') def test_station_to_ID(): assert dbq.station_to_ID('BLACKHALL PLACE') == 88 def test_station_address_by_name(): assert dbq.station_address_by_name('BLACKHALL PLACE') == 'Blackhall Place' def test_station_address_by_ID(): assert dbq.station_address_by_ID('88') == 'Blackhall Place' def test_station_coordinates_by_name(): assert dbq.station_coordinates_by_name('BLACKHALL PLACE') == (-6.281637, 53.3488) def test_station_coordinates_by_ID(): assert dbq.station_coordinates_by_ID('88') == (-6.281637, 53.3488)
# Reference: # Nose.readthedocs.org. 'Writing Tests - Nose 1.3.7 Documentation', available: # https://nose.readthedocs.org/en/latest/writing_tests.html [Accessed: 25/03/16] __author__ = "Ellen Rushe" from src.dbQueries import dbQueries # Test using 'bikes' database. dbq = dbQueries('bikes.db') def test_station_to_ID(): assert dbq.station_to_ID('BLACKHALL PLACE')==88 def test_station_address_by_name(): assert dbq.station_address_by_name('BLACKHALL PLACE')== 'Blackhall Place' def test_station_address_by_ID(): assert dbq.station_address_by_ID('88')== 'Blackhall Place' def test_station_coordinates_by_name(): assert dbq.station_coordinates_by_name('BLACKHALL PLACE')== (-6.281637, 53.3488) def test_station_coordinates_by_ID (): assert dbq.station_coordinates_by_ID('88')== (-6.281637, 53.3488) def test_available_bike_stands(): assert dbq.available_bike_stands('42', '1457367302')== 18 def test_available_bikes():