__syntax='<% %> % [[ ]]'# Replace bottle's default template key with [[]] - {{}} is used by Angular and will conflict
__indextemplate=SimpleTemplate(name='index',lookup=['views'],syntax=__syntax)# Basic configuration of template to use views/index.tpl and custom syntax above
savedir=os.path.abspath(config['savedir'])# Find absolute path to savedir
bigData=[]
defparseFiles():
print'Parsing the CSV files to save only the columns we want:\n Connect/Disconnect Times, Call Origin, Username, Calling Number, Called Number'
foriinos.walk(savedir,topdown=False):
fordini[2]:# For each file inside the savedir
withopen(os.path.join(savedir,d),'r')asreader:# Open the file as read-only
read=csv.reader(reader)# Read it as a CSV file
forrinread:
try:
row={
"connect":r[9],
"disconnect":r[10],
"origin":r[13],
"username":r[20],
"calling":r[21],
"called":r[22]
}
# Store the row in a dictionary and append that row to the bigData list
bigData.append(row)
exceptIndexError,e:# Out of range
# This is usually caused by log entries that only have r[0] (UNIX timestamp)
printr
reader.close()# Close the files when we don't need them anymore
@route('/')# Simple site, no links or other routes other than the index
defindex():
parseFiles()# Be Greedy. This reparses all of the files in savedir on every page load
# Return the rendered template and pass bigData and page variables