def write( spots, site_dir=None, dev_mode=False ): if site_dir is None: site_dir = os.getcwd() # Put the data in a table tabHtml = """ <html> <head> <meta http-equiv="refresh" content="60" /> <title>Lot Status</title> <script type="text/javascript" src="sorttable.js"> </script> <style type="text/css"> th, td { padding: 3px !important; } /* Sortable tables */ table.sortable thead { background-color: #333; color: #cccccc; font-weight: bold; cursor: default; } th { font-size: 100%; } </style> </head> <table border="1" class="sortable">""" tabHtml += ("<tr><th>Space Number</th>" "<th>Occupied</th>" "<th>Time Present</th>" "<th>Paid</th>" "<th>Paid Start Time</th>" "<th>Paid End Time</th>" "<th>License Number</th>" "<th>License State</th>" "<th>Monthly</th>" "<th>Occupation Start Time</th>" "<th>Occupation End Time</th>" "</tr>") n_remaining = len(spots) # Make a separate table like normal, with paids only ptabHtml = tabHtml for s in spots: spot = spots[s] # Occupied once past presence threshold # -- Can be occupied and not paid for # -- duration of 'freeTime' or 'violationThresh' # -- before marked as violating. # -- Which is NOT what we want to indicate when # -- presenting the number of spots available occupied = spot.timeOccupied > 0 deduct = occupied or spot.monthly deduct = deduct or spot.faultyCamera deduct = deduct or spot.handicap n_remaining -= deduct # Default row to white rcolor = '#FFFFFF' # Black out if camera is failed if spot.faultyCamera: rcolor = '#000000' if spot.violation: rcolor = '#FF0000' elif spot.failedDetection: rcolor = '#FF7F00' elif spot.monthly: rcolor = '#0000FF' elif spot.paid: rcolor = '#00FF00' elif spot.handicap: rcolor = '#FFFF00' rowsty = 'style="background-color:%s"' % rcolor row = '<tr %s>' % rowsty spaceText = 'Space ' + str(s) imname = 'imgs/spot%d.jpg' % spot.number linkText = '<a href="' + imname + '">' + spaceText + '</a>' spaceCell = '<td>' + linkText + '</td>' occCell = '<td> ' + str(occupied) + '</td>' presCell = '<td> ' + str(spot.tPresent) + '</td>' paidCell = '<td> ' + str(spot.paid) + '</td>' if spot.payStartTime: pst_lt = time.localtime(spot.payStartTime) pst_str = time.asctime(pst_lt) else: pst_str = '' if spot.payEndTime: pet_lt = time.localtime(spot.payEndTime) pet_str = time.asctime(pet_lt) else: pet_str = '' pstCell = '<td> ' + pst_str + '</td>' petCell = '<td> ' + pet_str + '</td>' lpnCell = '<td> ' + str(spot.lpn) + '</td>' lpsCell = '<td> ' + str(spot.lps) + '</td>' mnthCell = '<td> ' + str(spot.monthly) + '</td>' ost_lt = time.localtime(spot.occupationStartTime) oet_lt = time.localtime(spot.occupationEndTime) ostCell = '<td> ' + time.asctime(ost_lt) + '</td>' oetCell = '<td> ' + time.asctime(oet_lt) + '</td>' row += spaceCell row = row + occCell + presCell + paidCell row = row + pstCell + petCell row = row + lpnCell + lpsCell row += mnthCell row = row + ostCell + oetCell row += '</tr>' tabHtml += row # Only populate subtable with what's certain cases showMe = spot.paid == 1 or spot.violation dontShowMe = spot.monthly if showMe and not dontShowMe: ptabHtml += row endHtml = """ </table> </html>""" tabHtml += endHtml ptabHtml += endHtml with open('table.html','w') as f: f.write(tabHtml) with open('paidTable.html','w') as f: f.write(ptabHtml) nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining ho.write_page( 'n_avail.html', 'Available Spots', 30, nHtml ) if not dev_mode: target = os.path.join(site_dir,'newtable/index.html') os.rename("table.html",target) target = os.path.join(site_dir,'whospaid/index.html') os.rename("paidTable.html",target) target = os.path.join(site_dir,'n_spots_available/index.html') os.rename("n_avail.html",target) else: print 'WARNING: html products not going to served site location!' return
def writeTable(spots): # Put the data in a table tabHtml = """ <html> <head> <meta http-equiv="refresh" content="60" /> <title>Lot Status</title> <script type="text/javascript" src="sorttable.js"> </script> <style type="text/css"> th, td { padding: 3px !important; } /* Sortable tables */ table.sortable thead { background-color: #333; color: #cccccc; font-weight: bold; cursor: default; } th { font-size: 100%; } </style> </head> <table border="1" class="sortable">""" tabHtml += ("<tr><th>Space Number</th>" "<th>Occupied</th>" "<th>Time Present</th>" "<th>Paid</th>" "<th>Paid Start Time</th>" "<th>Paid End Time</th>" "<th>License Number</th>" "<th>License State</th>" "<th>Monthly</th>" "<th>Occupation Start Time</th>" "<th>Occupation End Time</th>" "</tr>") n_remaining = len(spots) # Make a separate table like normal, with paids only ptabHtml = tabHtml for s in spots: spot = spots[s] # Occupied once past presence threshold # -- Can be occupied and not paid for # -- duration of 'freeTime' or 'violationThresh' # -- before marked as violating. # -- Which is NOT what we want to indicate when # -- presenting the number of spots available occupied = spot['timeOccupied'] > 0 deduct = occupied or spot['monthly'] deduct = deduct or spot['faultyCamera'] deduct = deduct or spot['handicap'] n_remaining -= deduct # Default row to white rcolor = '#FFFFFF' # Assign row color if spot['violation']: rcolor = '#FF0000' elif spot['failedDetection']: rcolor = '#FF7F00' elif spot['monthly']: rcolor = '#0000FF' elif spot['paid']: rcolor = '#00FF00' elif spot['handicap']: rcolor = '#FFFF00' # Gray out if camera is failed if spot['faultyCamera']: rcolor = '#808080' rowsty = 'style="background-color:%s"' % rcolor row = '<tr %s>' % rowsty spaceText = 'Space ' + str(s) linkText = '<a href="' + spot['url'] + '">' + spaceText + '</a>' spaceCell = '<td>' + linkText + '</td>' occCell = '<td> ' + str(occupied) + '</td>' presCell = '<td> ' + str(spot['timePresent']) + '</td>' paidCell = '<td> ' + str(spot['paid']) + '</td>' if spot['payStartTime']: pst_lt = time.localtime(spot['payStartTime']) pst_str = time.asctime(pst_lt) else: pst_str = '' if spot['payEndTime']: pet_lt = time.localtime(spot['payEndTime']) pet_str = time.asctime(pet_lt) else: pet_str = '' pstCell = '<td> ' + pst_str + '</td>' petCell = '<td> ' + pet_str + '</td>' lpnCell = '<td> ' + str(spot['lpn']) + '</td>' lpsCell = '<td> ' + str(spot['lps']) + '</td>' mnthCell = '<td> ' + str(spot['monthly']) + '</td>' ost_lt = time.localtime(spot['occupationStartTime']) oet_lt = time.localtime(spot['occupationEndTime']) ostCell = '<td> ' + time.asctime(ost_lt) + '</td>' oetCell = '<td> ' + time.asctime(oet_lt) + '</td>' row += spaceCell row = row + occCell + presCell + paidCell row = row + pstCell + petCell row = row + lpnCell + lpsCell row += mnthCell row = row + ostCell + oetCell row += '</tr>' tabHtml += row # Only populate subtable with what's certain cases showMe = spot['paid'] == 1 or spot['violation'] dontShowMe = spot['monthly'] if showMe and not dontShowMe: ptabHtml += row endHtml = """ </table> </html>""" tabHtml += endHtml ptabHtml += endHtml with open('table.html', 'w') as f: f.write(tabHtml) with open('paidTable.html', 'w') as f: f.write(ptabHtml) #os.rename("table.html","/var/www/html/newtable/index.html") #os.rename("paidTable.html","/var/www/html/whospaid/index.html") print 'WARNING: table webpage is not going to served site location!' nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining ho.write_page('n_avail.html', 'Available Spots', 30, nHtml) #os.rename("n_avail.html","/var/www/html/n_spots_available/index.html") print 'WARNING: number webpage is not going to served site location!' return
occCell = '<td> ' + str(spots[spot]['occupied']) + '</td>' paidCell = '<td> ' + str(spots[spot]['paid']) + '</td>' pstCell = '<td> ' + str(spots[spot]['startTime']) + '</td>' petCell = '<td> ' + str(spots[spot]['endTime']) + '</td>' lpnCell = '<td> ' + str(spots[spot]['lpn']) + '</td>' lpsCell = '<td> ' + str(spots[spot]['lps']) + '</td>' mnthCell = '<td> ' + str(spots[spot]['monthly']) + '</td>' row += spaceCell row = row + occCell + paidCell row = row + pstCell + petCell row = row + lpnCell + lpsCell row += mnthCell row += '</tr>' tabHtml += row tabHtml += '</table>' ho.write_page('table.html', 'Lot Status', 15, tabHtml) os.rename("table.html", "/var/www/html/table/index.html") nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining ho.write_page('n_avail.html', 'Available Spots', 15, nHtml) os.rename("n_avail.html", "/var/www/html/n_spots_not_paid/index.html")
row = row + pstCell + petCell row += mnthCell row += '</tr>' tabHtml += row if spot['paid']: ptabHtml += row endHtml = """ </table""" tabHtml += endHtml ptabHtml += endHtml tname = 'tablePassport.html' ho.write_page( tname, 'Lot Status', 60, tabHtml ) #os.rename(tname,"/var/www/html/reston/table/index.html") tname = 'paidtablePassport.html' ho.write_page( tname, 'Lot Status', 60, ptabHtml ) #os.rename(tname,"/var/www/html/reston/whospaid/index.html") nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining nname = 'n_availPassport.html'
def writeTable( spots ): # Put the data in a table tabHtml = """ <html> <head> <meta http-equiv="refresh" content="60" /> <title>Lot Status</title> <script type="text/javascript" src="sorttable.js"> </script> <style type="text/css"> th, td { padding: 3px !important; } /* Sortable tables */ table.sortable thead { background-color: #333; color: #cccccc; font-weight: bold; cursor: default; } th { font-size: 100%; } </style> </head> <table border="1" class="sortable">""" tabHtml += ("<tr><th>Space Number</th>" "<th>Occupied</th>" "<th>Time Present</th>" "<th>Paid</th>" "<th>Paid Start Time</th>" "<th>Paid End Time</th>" "<th>License Number</th>" "<th>License State</th>" "<th>Monthly</th>" "<th>Occupation Start Time</th>" "<th>Occupation End Time</th>" "</tr>") n_remaining = len(spots) # Make a separate table like normal, with paids only ptabHtml = tabHtml for s in spots: spot = spots[s] # Occupied once past presence threshold # -- Can be occupied and not paid for # -- duration of 'freeTime' or 'violationThresh' # -- before marked as violating. # -- Which is NOT what we want to indicate when # -- presenting the number of spots available occupied = spot['timeOccupied'] > 0 deduct = occupied or spot['monthly'] deduct = deduct or spot['faultyCamera'] deduct = deduct or spot['handicap'] n_remaining -= deduct # Default row to white rcolor = '#FFFFFF' # Assign row color if spot['violation']: rcolor = '#FF0000' elif spot['failedDetection']: rcolor = '#FF7F00' elif spot['monthly']: rcolor = '#0000FF' elif spot['paid']: rcolor = '#00FF00' elif spot['handicap']: rcolor = '#FFFF00' # Gray out if camera is failed if spot['faultyCamera']: rcolor = '#808080' rowsty = 'style="background-color:%s"' % rcolor row = '<tr %s>' % rowsty spaceText = 'Space ' + str(s) linkText = '<a href="' + spot['url'] + '">' + spaceText + '</a>' spaceCell = '<td>' + linkText + '</td>' occCell = '<td> ' + str(occupied) + '</td>' presCell = '<td> ' + str(spot['timePresent']) + '</td>' paidCell = '<td> ' + str(spot['paid']) + '</td>' if spot['payStartTime']: pst_lt = time.localtime(spot['payStartTime']) pst_str = time.asctime(pst_lt) else: pst_str = '' if spot['payEndTime']: pet_lt = time.localtime(spot['payEndTime']) pet_str = time.asctime(pet_lt) else: pet_str = '' pstCell = '<td> ' + pst_str + '</td>' petCell = '<td> ' + pet_str + '</td>' lpnCell = '<td> ' + str(spot['lpn']) + '</td>' lpsCell = '<td> ' + str(spot['lps']) + '</td>' mnthCell = '<td> ' + str(spot['monthly']) + '</td>' ost_lt = time.localtime(spot['occupationStartTime']) oet_lt = time.localtime(spot['occupationEndTime']) ostCell = '<td> ' + time.asctime(ost_lt) + '</td>' oetCell = '<td> ' + time.asctime(oet_lt) + '</td>' row += spaceCell row = row + occCell + presCell + paidCell row = row + pstCell + petCell row = row + lpnCell + lpsCell row += mnthCell row = row + ostCell + oetCell row += '</tr>' tabHtml += row # Only populate subtable with what's certain cases showMe = spot['paid'] == 1 or spot['violation'] dontShowMe = spot['monthly'] if showMe and not dontShowMe: ptabHtml += row endHtml = """ </table> </html>""" tabHtml += endHtml ptabHtml += endHtml with open('table.html','w') as f: f.write(tabHtml) with open('paidTable.html','w') as f: f.write(ptabHtml) #os.rename("table.html","/var/www/html/newtable/index.html") #os.rename("paidTable.html","/var/www/html/whospaid/index.html") print 'WARNING: table webpage is not going to served site location!' nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining ho.write_page( 'n_avail.html', 'Available Spots', 30, nHtml ) #os.rename("n_avail.html","/var/www/html/n_spots_available/index.html") print 'WARNING: number webpage is not going to served site location!' return
pstCell = '<td> ' + str(spots[spot]['startTime']) + '</td>' petCell = '<td> ' + str(spots[spot]['endTime']) + '</td>' lpnCell = '<td> ' + str(spots[spot]['lpn']) + '</td>' lpsCell = '<td> ' + str(spots[spot]['lps']) + '</td>' mnthCell = '<td> ' + str(spots[spot]['monthly']) + '</td>' row += spaceCell row = row + occCell + paidCell row = row + pstCell + petCell row = row + lpnCell + lpsCell row += mnthCell row += '</tr>' tabHtml += row tabHtml += '</table>' ho.write_page( 'table.html', 'Lot Status', 15, tabHtml ) os.rename("table.html","/var/www/html/table/index.html") nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining ho.write_page( 'n_avail.html', 'Available Spots', 15, nHtml ) os.rename("n_avail.html","/var/www/html/n_spots_not_paid/index.html")
row = row + pstCell + petCell row += mnthCell row += '</tr>' tabHtml += row if spot['paid']: ptabHtml += row endHtml = """ </table""" tabHtml += endHtml ptabHtml += endHtml tname = 'tablePassport.html' ho.write_page(tname, 'Lot Status', 60, tabHtml) #os.rename(tname,"/var/www/html/reston/table/index.html") tname = 'paidtablePassport.html' ho.write_page(tname, 'Lot Status', 60, ptabHtml) #os.rename(tname,"/var/www/html/reston/whospaid/index.html") nHtml = """\ <div> <font size="7"> %d </font> </div> """ % n_remaining nname = 'n_availPassport.html'
outdir = '/tmp/get_payer_output' if not os.path.exists(outdir): os.makedirs(outdir) outfile = os.path.join(outdir, 'bp_pmAPI.log') with open(outfile, 'a') as out: print >> out, dt.datetime.now() pp.pprint(data, stream=out) # Finish the table tabHtml += '</table>' # Write the full page html ho.write_page('bpark_table.html', 'Paid Spots', 60, tabHtml) # Move it to the right spot #os.rename("bpark_table.html","/var/www/html/bpark/table/index.html") os.rename("bpark_table.html", "/tmp/bptab.html") ###################### # How many unpaid spots remain n_remaining = nSpots - nPaidSpots nHtml = """\ <div> <font size="7"> %d </font>
if not os.path.exists(outdir): os.makedirs(outdir) outfile = os.path.join(outdir,'bp_pmAPI.log') with open(outfile,'a') as out: print >> out, dt.datetime.now() pp.pprint( data, stream=out ) # Finish the table tabHtml += '</table>' # Write the full page html ho.write_page( 'bpark_table.html', 'Paid Spots', 60, tabHtml ) # Move it to the right spot #os.rename("bpark_table.html","/var/www/html/bpark/table/index.html") os.rename("bpark_table.html","/tmp/bptab.html") ###################### # How many unpaid spots remain n_remaining = nSpots - nPaidSpots nHtml = """\ <div> <font size="7"> %d </font>