1. Cédric Bonhomme
  2. bPlog

Commits

Cédric Bonhomme  committed 061ada4

Remove print from pygeocoder. Bug fix: undefined variabale.

  • Participants
  • Parent commits ab7dde6
  • Branches default

Comments (0)

Files changed (2)

File index.cgi

View file
  • Ignore whitespace
 # -*- coding: utf-8 -*-
 import cgi
 from datetime import datetime
-from operator import itemgetter
 
 import utils
 from pygeocoder import Geocoder
 
 locations = utils.get_locations()
 
-print "<h1>Last location</h1>"
-google_map_url = "http://maps.google.com/maps/api/staticmap?center=" + \
-                locations[0][1] + "," + locations[0][0] + "&zoom=14&size=512x512&maptype=roadmap&sensor=false"
-print '<div align="center"><img src="' + google_map_url + '" align="center" /></div>'
-print 'Time: ' + datetime.fromtimestamp(float(history[0][2])).isoformat()
+if locations != []:
+    print "<h1>Last location</h1>"
+    google_map_url = "http://maps.google.com/maps/api/staticmap?center=" + \
+                    locations[0][1] + "," + locations[0][0] + "&zoom=14&size=512x512&maptype=roadmap&sensor=false"
+    print '<div align="center"><img src="' + google_map_url + '" align="center" /></div>'
+    print 'Time: ' + datetime.fromtimestamp(float(locations[0][2])).isoformat()
 
 
 
-gcoder = Geocoder()
-print "<h1>History</h1>"
-print '<table border="1" width="100%">'
-for elem in locations[:10]:
-    if elem[0] != '(none)':
-        try:
-            addresses = gcoder.reverse_geocode(float(elem[1]), float(elem[0]))
-            country = addresses[0]['address_components'][4]['long_name']
-            area = addresses[0]['address_components'][3]['long_name']
-            city = addresses[0]['address_components'][1]['long_name']
-        except Exception, e:
-            print e
-            city, country = "", ""
+    gcoder = Geocoder()
+    print "<h1>History</h1>"
+    print '<table border="1" width="100%">'
+    for elem in locations[:10]:
+        if elem[0] != '(none)':
+            try:
+                addresses = gcoder.reverse_geocode(float(elem[1]), float(elem[0]))
+                country = addresses[0]['address_components'][4]['long_name']
+                area = addresses[0]['address_components'][3]['long_name']
+                city = addresses[0]['address_components'][1]['long_name']
+            except Exception, e:
+                city, country = "", ""
 
-        google_map_url = "http://maps.google.com/maps/api/staticmap?center=" + elem[1] + \
-                        "," + elem[0] + "&zoom=14&size=512x512&maptype=roadmap&sensor=false"
-        print "<tr><td>" + city + ', ' + country + \
-                        '<br />(<a href=' + google_map_url  +  '>map</a>)</td>'
-        print "<td align='center'>" + str(elem[1]) + "</td><td align='center'>" + str(elem[0]) + \
-                        "</td><td align='center'>" +  datetime.fromtimestamp(float(elem[2])).isoformat() + "</td></tr>"
-print "</table>"
-print "<hr /><p align='center'>Data from Android.</p>"
-print "</body></html>"
+            google_map_url = "http://maps.google.com/maps/api/staticmap?center=" + elem[1] + \
+                            "," + elem[0] + "&zoom=14&size=512x512&maptype=roadmap&sensor=false"
+            print "<tr><td>" + city + ', ' + country + \
+                            '<br />(<a href=' + google_map_url  +  '>map</a>)</td>'
+            print "<td align='center'>" + str(elem[1]) + "</td><td align='center'>" + str(elem[0]) + \
+                            "</td><td align='center'>" +  datetime.fromtimestamp(float(elem[2])).isoformat() + "</td></tr>"
+    print "</table>"
+
+else:
+    print "No locations in the database."
+
+
+print "<hr /><p align='center'>Data from Android.</p>\n"
+print "</body>\n</html>\n"

File utils.py

View file
  • Ignore whitespace
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 import sqlite3
+from operator import itemgetter
 
 def create_base():
     """
     try:
         conn = sqlite3.connect("./locations.db", isolation_level = None)
         c = conn.cursor()
-        locationss = c.execute("SELECT * FROM longitude").fetchall()
+        locations = c.execute("SELECT * FROM longitude").fetchall()
     except:
         pass
     return sorted(locations, key=itemgetter(2), reverse=True)