Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import os.path
import cherrypy
import jinja2
import sqlite3 as sql
import math, os
import time
JINJA_ENVIRONMENT = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__),'templates')),extensions=['jinja2.ext.autoescape'])
DB = 'locations.db'
def get_filtered_data():
locations = []
with sql.connect(DB) as cur:
results = cur.execute('''SELECT * FROM Location GROUP BY longitude, latitude, date,tid ORDER BY tid DESC,time;''')
for val1,val2,val3,val4,val5, in results:
lon = val1
lat = val2
d8t = str(time.strftime('%Y-%m-%d', time.localtime(val3)))
thime = str(time.strftime('%H:%M:%S', time.localtime(val4)))
timeStamp = val4
tid = val5
locations.append([lon,lat,d8t,thime,tid,timeStamp])
return locations
class homePage:
@cherrypy.expose
@cherrypy.tools.gzip()
def index(self):
template = JINJA_ENVIRONMENT.get_template('homepage.html')
template_values = {'locations': get_filtered_data()} #template_values is a dict. key is 'locations', values is a list of lists of two items (long, lat)
return template.render(template_values) #make and serve the webpage
class mapPage:
@cherrypy.expose
@cherrypy.tools.gzip()
def index(self):
template = JINJA_ENVIRONMENT.get_template('map.html')
template_values = {'locations': get_filtered_data()} #template_values is a dict. key is 'locations', values is a list of lists of two items (long, lat)
return template.render(template_values) #make and serve the webpage
class loginPage:
@cherrypy.expose
@cherrypy.tools.gzip()
def index(self):
template = JINJA_ENVIRONMENT.get_template('login.html')
template_values = {'locations': get_filtered_data()} #template_values is a dict. key is 'locations', values is a list of lists of two items (long, lat)
return template.render(template_values) #make and serve the webpage
class databasePage:
@cherrypy.expose
@cherrypy.tools.gzip()
def index(self):
template = JINJA_ENVIRONMENT.get_template('database.html')
template_values = {'locations': get_filtered_data()} #template_values is a dict. key is 'locations', values is a list of lists of two items (long, lat)
return template.render(template_values) #make and serve the webpage
root = homePage()
root.map = mapPage() # Here we mount request handler objects
root.login = loginPage()
root.database = databasePage()
if __name__ == '__main__':
# CherryPy always starts with app.root when trying to map request URIs
# to objects, so we need to mount a request handler root.
# Instead of calling a particular class, we call root
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.config.update({'server.socket_port': 3000})
cherrypy.quickstart(root, '/', {'/': {'tools.gzip.on': True}})