-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
39 lines (33 loc) · 1021 Bytes
/
main.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
# -*- coding: utf-8 -*-
# @Date : 2016-11-30 11:12:44
# @Author : fancy ([email protected])
import json
import qrtools
# import urlparse
import requests
from StringIO import StringIO
from flask import Flask, request
app = Flask('decoder')
qr = qrtools.QR()
@app.route('/decode', methods=['GET'])
def decode_img():
try:
result = {'status': 0, 'is_qr': False, 'data': None, 'msg': 'success'}
url = request.args.get('url', None)
if url:
# domain = urlparse.urlsplit(url).netloc
# headers = {'Referer': domain}
resp = requests.get(url) #, headers=headers)
f = StringIO(resp.content)
else:
f = request.files['file']
result['is_qr'] = qr.decode(f)
if result['is_qr']:
result['data'] = qr.data
except Exception, e:
result['status'] = 1
result['msg'] = str(e)
finally:
return json.dumps(result)
if __name__ == '__main__':
app.run(host='0.0.0.0', port='8002')