Skip to content

Instantly share code, notes, and snippets.

@sagoyanfisic
Created March 16, 2018 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagoyanfisic/ce47792e70051ea2a76560fe5e10f1de to your computer and use it in GitHub Desktop.
Save sagoyanfisic/ce47792e70051ea2a76560fe5e10f1de to your computer and use it in GitHub Desktop.
import webapp2
import json
from google.appengine.ext.webapp import template
import os
import requests
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
class PrincipalPage(webapp2.RequestHandler):
def get(self):
template_values = dict()
path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html')
self.response.out.write(template.render(path, template_values))
class ResponseExample(webapp2.RequestHandler):
def get(self, **kwargs):
html = '<a href="%s">test item</a>' % self.url_for('view', item='test')
self.response.out.write(html)
class ExampleJsonpi(webapp2.RequestHandler):
def get(self):
url = ('https://www.lima-airport.com/_vti_bin/portal/services.svc/vuelos/')
data = {'fecha':'','operacion':'L','origen':'','vuelo':'','destino':''}
self.response.headers['Content-Type'] = 'application/json'
self.response.headers.add_header('Access-Control-Allow-Origin', '*')
self.response.write(json.dumps(data))
class ExampleApiJson2(webapp2.RequestHandler):
def get(self,date_flight,):
url = ('https://www.lima-airport.com/_vti_bin/portal/services.svc/vuelos/')
data = {'fecha':'','operacion':'L','origen':'','vuelo':'','destino':''}
data.update({"fecha":date_flight})
rsp = requests.post(url, data=json.dumps(data),
headers={
'Content-type': 'application/json', 'Accept': 'text/plain'
},
verify=False)
self.response.headers['Content-Type'] = 'application/json'
self.response.headers.add_header('Access-Control-Allow-Origin', '*')
self.response.write(responses.json(json.dumps(rsp)))
app = webapp2.WSGIApplication([
# SALIDAS
# salidas/nacional/dia/
('/v1/', ExampleJsonpi),
('/v2/(\d{4}-\d{2}-\d{2})/', ExampleApiJson2),
('/', MainPage),
], debug=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment