-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_from_GH.py
48 lines (43 loc) · 1.38 KB
/
example_from_GH.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import webbrowser
from credentials import Credentials
from shapeways.client import Client
client = Client(
consumer_key=Credentials["Consumer_Key"],
consumer_secret=Credentials["Consumer_Secret"],
callback_url="http://localhost:3000/callback"
)
def application(environ, start_response):
url = environ["PATH_INFO"]
if url.startswith("/favicon.ico"):
start_response("204 No Content", [])
return [""]
elif url.startswith("/login"):
url = client.connect()
start_response("302 Found", [
("Location", str(url)),
])
return [""]
elif url.startswith("/callback"):
client.verify_url(environ["QUERY_STRING"])
start_response("302 Found", [
("Location", "http://localhost:3000/"),
])
return [""]
else:
#this is where steps after verification goes
response = client.get_api_info()
start_response("200 Ok", [
("Content-Type", "application/json"),
])
return [json.dumps(response)]
if __name__ == "__main__":
from wsgiref.simple_server import make_server
try:
httpd = make_server("", 3000, application)
print "Tracking Server Listening on Port 3000..."
url=client.connect()
webbrowser.open(url,new=2)
httpd.serve_forever()
except KeyboardInterrupt:
print "Exiting..."