-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
131 lines (103 loc) · 3.73 KB
/
index.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from flask import Flask, request
from util import convert
from flask_cors import CORS
from flask import jsonify
from flask import make_response
# from html2image import Html2Image
from read_meta_data import readMeta
app = Flask(__name__)
CORS(app, resources={r"/api/*": {"origins": "*"}})
@app.route('/')
def home():
return "Hello, World!"
@app.route("/api")
def api():
response = make_response(jsonify({"data": "some data"}))
response.headers['Cache-Control'] = 'public, max-age=300'
return response
# @app.route("/api/meta")
# def linkMetaPreview():
# url = request.args.get('url')
# if url is None:
# return {'error': 'url is missing in params'}, 400
# url = convert(url)
# json = readMeta(url)
# return render_template("image.html", data=json)
@app.route("/api/img")
def api_image():
url = request.args.get('url')
if url is None:
return {'error': 'url is missing in params'}, 400
url = convert(url)
# hti = Html2Image(temp_path="./tmp")
# list = hti.screenshot(url=url, size=(720, 454),)
# print(list)
return {'result': 'success'}
@app.route('/api/read_url_meta')
def read_url_meta():
# Get urls from params
url = request.args.get('url')
if url is None:
return {'error': 'url is missing in params'}, 400
url = convert(url)
print(url)
result = readMeta(url)
response = make_response(jsonify({'result': result}))
# Add cache control headers to response. This will cache the response for 365 days
response.headers['Cache-Control'] = 'public, max-age=31536000'
# Add expires header to response. This will cache the response for 30 days
response.headers['Expires'] = '31536000'
return response
@app.route('/api/meta/nostra')
def nostraMeta():
# Get urls from params
url = request.args.get('url')
if url is None:
return {'error': 'url is missing in params'}, 400
url = convert(url)
print(url)
result = readMeta(url)
response = make_response(jsonify({'result': result}))
# Add cache control headers to response. This will cache the response for 365 days
response.headers['Cache-Control'] = 'public, max-age=31536000'
# Add expires header to response. This will cache the response for 30 days
response.headers['Expires'] = '31536000'
return response
@app.route('/api/meta/pensil')
def pensilMeta():
# Get urls from params
url = request.args.get('url')
if url is None:
return {'error': 'url is missing in params'}, 400
url = convert(url)
print(url)
result = readMeta(url)
response = make_response(jsonify({'result': result}))
# Add cache control headers to response. This will cache the response for 365 days
response.headers['Cache-Control'] = 'public, max-age=31536000'
# Add expires header to response. This will cache the response for 30 days
response.headers['Expires'] = '31536000'
return response
@app.route('/api/meta/humbl')
def humblMeta():
# Get urls from params
url = request.args.get('url')
if url is None:
return {'error': 'url is missing in params'}, 400
url = convert(url)
print(url)
result = readMeta(url)
response = make_response(jsonify({'result': result}))
# Add cache control headers to response. This will cache the response for 365 days
response.headers['Cache-Control'] = 'public, max-age=31536000'
# Add expires header to response. This will cache the response for 30 days
response.headers['Expires'] = '31536000'
return response
@app.errorhandler(404)
def handle_exception(e):
print('\nERROR:', e)
return {'error': 'Not found'}, 404
@app.errorhandler(Exception)
def handle_exception(e):
print('\nERROR:', e)
return {'error': 'something went wrong'}, 500