Skip to content

Instantly share code, notes, and snippets.

@cwlau
Last active November 27, 2017 15:43
Show Gist options
  • Save cwlau/02e511cb3f23a2dc9c44 to your computer and use it in GitHub Desktop.
Save cwlau/02e511cb3f23a2dc9c44 to your computer and use it in GitHub Desktop.
Geolocation demo for Google App Engine
# demo from blog.cwlau.com
import os
os.environ.get('HTTP_X_APPENGINE_CITY', 'unknown city')
# demo from blog.cwlau.com
import os
os.environ.get('HTTP_X_APPENGINE_COUNTRY', 'unknown country')
# demo from blog.cwlau.com
import webapp2
import os
class Demo(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
self.response.write('<html>')
self.response.write('<title>Geolocation Demo on Google App Engine</title>')
self.response.write('<body>')
self.response.write('Current City: ' + os.environ.get('HTTP_X_APPENGINE_CITY', 'Unknown City'))
self.response.write('<br/>')
self.response.write('Current Country: ' + os.environ.get('HTTP_X_APPENGINE_COUNTRY', 'Unknown Country'))
self.response.write('</body>')
self.response.write('</html>')
app = webapp2.WSGIApplication([
('/geolocation', Demo),
], debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment