-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_token.py
38 lines (27 loc) · 878 Bytes
/
get_token.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
import untappd
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
import re
import sys
import psycopg2
creds = json.load(open('.credentials.json'))
client = untappd.Untappd(
client_id=creds["client_id"],
client_secret=creds["client_secret"],
redirect_url='http://localhost:8083',
user_agent='letmein'
)
conn = psycopg2.connect("postgres:///beer_feed")
hostName = "localhost"
serverPort = 8083
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
code = re.search('code=(.*)', self.path).group(1)
res = client.oauth.get_access_token(code)
with conn.cursor() as cur:
cur.execute("INSERT INTO tokens (token) VALUES(%s)", (res,))
conn.commit()
sys.exit(0)
webServer = HTTPServer((hostName, serverPort), MyServer)
print(client.oauth.get_auth_url())
webServer.serve_forever()