-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
43 lines (38 loc) · 1.09 KB
/
server.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
import requests, urllib, json, yaml
from flask import Flask, request
from two1.lib.wallet import Wallet
from two1.lib.bitserv.flask import Payment
from flask import send_from_directory
app = Flask(__name__)
API_KEY = json.load(open('geocode-api.json')).get('key')
wallet = Wallet()
payment = Payment(app, wallet)
@app.route('/geocode', methods=['POST'])
# @payment.required(1) #For testing
@payment.required(1000)
def geocode():
'''
Geocodes an address
'''
params = {
'address': request.form.get('address'),
'key': API_KEY
}
r = requests.get('https://maps.googleapis.com/maps/api/geocode/json?' + urllib.parse.urlencode(params))
return r.text
@app.route('/manifest')
def docs():
'''
Provides the app manifest to the 21 crawler.
'''
with open('manifest.yaml', 'r') as f:
manifest_yaml = yaml.load(f)
return json.dumps(manifest_yaml)
@app.route('/client')
def client():
'''
Provides an example client script.
'''
return send_from_directory('static', 'client.py')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)