-
Notifications
You must be signed in to change notification settings - Fork 5
/
serve.py
64 lines (49 loc) · 1.47 KB
/
serve.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__title__ = 'Metadoc - Postmodern news article metadata service'
__copyright__ = 'Copyright 2016, Paul Solbach'
__author__ = 'Paul Solbach'
__license__ = 'MIT'
import concurrent
import json
import bottle
from bottle import response, request, get, route, run, abort, error
from metadoc import Metadoc
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024 # up max POST payload size to 1MB
@error(404)
def error404(error):
return json.dumps({'code': 404,'message': 'url param is missing.'})
@get('/social')
def social_article():
"""GET data url required"""
response.content_type = 'application/json'
url = request.query.getone("url")
if not url:
abort(404)
metadoc = Metadoc(url=url)
payload = metadoc.query(mode="social", fmt="social")
return json.dumps(payload)
@get('/extract')
def extract_article():
"""GET data url required"""
response.content_type = 'application/json'
url = request.query.getone("url")
if not url:
abort(404)
metadoc = Metadoc(url=url)
metadoc._prepare()
metadoc._query_domain()
metadoc._query_extract()
payload = metadoc._render() # Preserve order
return json.dumps(payload)
@get('/full')
def full_article():
"""GET data url required"""
response.content_type = 'application/json'
url = request.query.getone("url")
if not url:
abort(404)
metadoc = Metadoc(url=url)
payload = metadoc.query()
return json.dumps(payload)
run(host='localhost', reloader=True, port=6060)