- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
executable file
·76 lines (57 loc) · 2.05 KB
/
Copy pathapp.py
File metadata and controls
executable file
·76 lines (57 loc) · 2.05 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
importstring
importrandom
importjson
importrequests
fromurllibimporturlencode
importflask
fromflaskimportFlask, render_template, redirect, url_for
fromflaskimportrequest, jsonify
app=Flask(__name__)
# === task settings =================================================
# yelp URL for OAuth2.0 toke:
YELP_AUTH_URL="https://api.yelp.com/oauth2/token"
# path to credentials file (see credentials sample file):
CRED_FILE="static/assets/docs/credentials"
# length you want your salt to be
SALT_LEN=64
# ===================================================================
deffetchCredentials():
withopen(CRED_FILE) ascredentials:
creds=json.load(credentials)
returncreds
defgetBearerToken():
creds=fetchCredentials()
data=urlencode({
'client_id': creds['YELP_CLIENT_ID'],
'client_secret': creds['YELP_CLIENT_SECRET'],
'grant_type': 'client_credentials',
})
headers= {
'content-type': 'application/x-www-form-urlencoded',
}
response=requests.request('POST', YELP_AUTH_URL, data=data, headers=headers)
response=response.json()
returnresponse['access_token']
defmakeSalt(len,chars):
salt=''.join(random.choice(chars) forxinrange(len))
salt='-'+salt+'_'
returnsalt
@app.route('/')
defmain():
globalBEARER_TOKEN
globalSALT
globalSALTED_TOKEN
BEARER_TOKEN=getBearerToken()
SALT=makeSalt(SALT_LEN, string.ascii_letters+string.digits)
SALTED_TOKEN=BEARER_TOKEN[0:int(len(BEARER_TOKEN)/2)] +SALT+\
BEARER_TOKEN[int(len(BEARER_TOKEN)/2):len(BEARER_TOKEN)]
returnrender_template('index.html')
@app.route('/saltydog', methods=['POST'])
defgiveItUp():
outgoing= [{'term1': SALTED_TOKEN},
{'term2': SALT}]
returnjson.dumps(outgoing)
if__name__=='__main__':
app.secret_key='super_secret_key'
app.debug=True
app.run(host='0.0.0.0', port= ) # choose your port