Skip to content

Instantly share code, notes, and snippets.

@simonmikkelsen
Created June 21, 2017 13:08
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 simonmikkelsen/ed6a4c9c7edd6b03ee47d1c5bfd10b4a to your computer and use it in GitHub Desktop.
Save simonmikkelsen/ed6a4c9c7edd6b03ee47d1c5bfd10b4a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from wsgiref.simple_server import make_server
from cgi import parse_qs, escape
import sys
import json
import urllib
import httplib
try:
import requests
except ImportError:
print("requests not found - please run: pip install requests")
sys.exit()
def application (environ, start_response):
# Returns a dictionary in which the values are lists
query_params = parse_qs(environ['QUERY_STRING'])
# New test
client_id = 'Y...0'
client_secret = 'N...='
url = 'http://www.mapillary.com/connect?'+urllib.urlencode({'client_id':client_id, 'response_type':'token', 'scope':'user:read', 'state':'return', 'redirect_uri':'http://localhost:7788/api'})
if len(environ['QUERY_STRING']) == 0:
response_headers = [
('Location', url)
]
status = '302 Moved Temporary'
start_response(status, response_headers)
response_body = ''
return [response_body]
access_token = query_params['access_token'][0]
url = "/v3/me?client_id=" + client_id + "&token=" + access_token
h = httplib.HTTPSConnection('a.mapillary.com')
h.request('GET', url)
r = h.getresponse()
resp = r.read()
status = '200 OK'
response_body = str(resp)
# Now content type is text/html
response_headers = [
('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))
]
start_response(status, response_headers)
return [response_body]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment