Skip to content
Permalink
56ea65fb0f
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
39 lines (33 sloc) 1.59 KB
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'
class LocationsWebsite(object):
@cherrypy.expose
@cherrypy.tools.gzip()
def index(self):
template = JINJA_ENVIRONMENT.get_template('index.html')
template_values = {'locations': self.get_locations()} #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
def get_locations(self):
locations = self.get_filtered_data()
return locations
def get_filtered_data(self):
all_data = []
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: #rename vals to actual
lon = val1
lat = val2
d8t = str(time.strftime('%Y-%m-%d', time.localtime(val3)))
thime = str(time.strftime('%H:%M:%S', time.localtime(val4)))
tid = val5
all_data.append([lon,lat,d8t,thime,tid])
return all_data
if __name__ == '__main__':
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.config.update({'server.socket_port': 3000})
cherrypy.quickstart(LocationsWebsite(), '/', {'/': {'tools.gzip.on': True}})