Skip to content

Commit 9428b5c

Browse files
authored
Merge pull request #5 from capjamesg/master
Enable experimental alt text attribute, bump versions, add new debug mode for local coding
2 parents 85250f8 + 9ef9c03 commit 9428b5c

File tree

5 files changed

+78
-62
lines changed

5 files changed

+78
-62
lines changed

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: gunicorn app:app --log-file -
1+
web: gunicorn app:app

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,39 @@ https://python.microformats.io
88

99
All commits to the `master` branch get auto-deployed to the live website (running on [Heroku](https://python.microformats.io))
1010

11+
## Getting Started
1112

12-
## Requirements
13-
14-
- Python 2.7
15-
13+
This website is built using Python Flask.
1614

17-
## Installation
18-
19-
Clone the repo:
15+
To start working with this project, first clone the repository for this project:
2016

2117
```
2218
git clone https://github.com/indieweb/microformats-python-parser-website.git
2319
cd microformats-python-parser-website
2420
```
2521

26-
Install the dependencies:
22+
Next, install the required dependencies:
2723

2824
```
29-
TODO
25+
pip3 install -r requirements.txt
3026
```
3127

32-
Start the server:
28+
Next, start the server. You can do this in either debugging mode (where `debug=True`) in Flask or in production mode using Gunicorn.
3329

3430
```
35-
TODO
31+
python3 app.py --debug (debug mode)
32+
gunicorn app:app (production mode)
3633
```
3734

38-
Open the site in your browser:
35+
You can view your running local application at this URL:
3936

4037
```
41-
TODO
38+
http://localhost:8080
4239
```
4340

41+
## Requirements
4442

45-
## Authors
46-
47-
- Kyle Mahan / [@kylewm](https://github.com/kylewm)
43+
- Python 3.9
4844

4945
## Contributions
5046

@@ -58,9 +54,13 @@ TODO
5854
If you find bugs, have feature requests or questions, please
5955
[file an issue](https://github.com/indieweb/microformats-parser-website-python/issues).
6056

61-
6257
## License
6358

6459
Microformats Python Parser Website is dedicated to the public domain using Creative Commons -- CC0 1.0 Universal.
6560

6661
http://creativecommons.org/publicdomain/zero/1.0
62+
63+
## Contributors
64+
65+
- Kyle Mahan / [@kylewm](https://github.com/kylewm) (Author)
66+
- [@capjamesg](https://github.com/capjamesg) (Contributor)

app.py

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,74 @@
1-
import collections
21
import json
3-
import sys
42
import traceback
3+
from collections import OrderedDict
4+
from optparse import OptionParser
55

66
import mf2py
77
import mf2util
8-
from flask import Flask, render_template, jsonify, request, make_response
8+
from flask import Flask, jsonify, make_response, render_template, request
9+
10+
parser = OptionParser()
11+
12+
parser.add_option(
13+
"-d",
14+
"--debug",
15+
action="store_true",
16+
default=False,
17+
help="Run application in debug mode",
18+
)
19+
20+
(options, args) = parser.parse_args()
921

1022
app = Flask(__name__)
1123

1224
mf2py.Parser.user_agent = "python.microformats.io (mf2py/" + mf2py.__version__ + ") Mozilla/5.0 Chrome/29.0.1547.57 Safari/537.36"
13-
mf2py.Parser.dict_class = collections.OrderedDict
25+
mf2py.Parser.dict_class = OrderedDict
26+
mf2py.Parser.img_with_alt = True
1427

15-
@app.route('/', methods=['GET', 'POST'])
28+
@app.route("/", methods=["GET", "POST"])
1629
def index():
1730
try:
18-
util = request.args.get('util') or request.form.get('util')
19-
url = request.args.get('url') or request.form.get('url')
20-
doc = request.args.get('doc') or request.form.get('doc')
21-
parser = request.args.get('parser') or request.form.get('parser')
22-
callback = request.args.get('callback') or request.form.get('callback')
31+
util = request.args.get("util") or request.form.get("util")
32+
url = request.args.get("url") or request.form.get("url")
33+
doc = request.args.get("doc") or request.form.get("doc")
34+
parser = request.args.get("parser") or request.form.get("parser")
35+
callback = request.args.get("callback") or request.form.get("callback")
2336

2437
cached_mf2 = {}
2538

2639
def fetch_mf2(url):
2740
if url in cached_mf2:
2841
return cached_mf2[url]
29-
p = mf2py.parse(
30-
url=url, html_parser=parser or None)
42+
p = mf2py.parse(url=url, html_parser=parser or None)
3143
cached_mf2[url] = p
3244
return p
3345

3446
if url or doc:
35-
p = mf2py.parse(url=url or None,
36-
doc=doc or None,
37-
html_parser=parser or None)
47+
p = mf2py.parse(
48+
url=url or None, doc=doc or None, html_parser=parser or None
49+
)
3850
if util:
39-
if any('h-feed' in item['type'] for item in p['items']):
51+
if any("h-feed" in item["type"] for item in p["items"]):
4052
p = mf2util.interpret_feed(
41-
p, url, want_json=True, fetch_mf2_func=fetch_mf2)
53+
p, url, want_json=True, fetch_mf2_func=fetch_mf2
54+
)
4255
else:
4356
p = mf2util.interpret(
44-
p, url, want_json=True, fetch_mf2_func=fetch_mf2)
57+
p, url, want_json=True, fetch_mf2_func=fetch_mf2
58+
)
4559
if callback:
46-
response = make_response('{}({})'.format(callback, json.dumps(p)), 200)
47-
response.headers['Content-Type'] = 'text/javascript'
60+
response = make_response("{}({})".format(callback, json.dumps(p)), 200)
61+
response.headers["Content-Type"] = "text/javascript"
4862
else:
4963
response = make_response(json.dumps(p, indent=True), 200)
50-
response.headers['Content-Type'] = 'application/json'
64+
response.headers["Content-Type"] = "application/json"
5165
return response
5266

53-
return render_template('index.jinja2',
54-
mf2py_version=mf2py.__version__)
67+
return render_template("index.jinja2", mf2py_version=mf2py.__version__)
5568
except BaseException as e:
5669
traceback.print_exc()
57-
return jsonify(error='%s: %s' % (type(e).__name__, e)), 400
70+
return jsonify(error="%s: %s" % (type(e).__name__, e)), 400
71+
72+
73+
if options.debug:
74+
app.run(debug=True, port=8080)

requirements.txt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
appdirs==1.4.3
2-
beautifulsoup4==4.6.0
3-
certifi==2017.4.17
4-
chardet==3.0.3
5-
Flask==0.10.1
6-
gunicorn==19.7.1
7-
html5lib==0.999999999
8-
idna==2.5
9-
itsdangerous==0.24
10-
Jinja2==2.8
11-
MarkupSafe==0.23
12-
mf2py==1.1.2
13-
mf2util==0.5.0
14-
packaging==16.8
15-
pyparsing==2.2.0
16-
requests==2.16.4
17-
six==1.10.0
18-
urllib3==1.21.1
1+
beautifulsoup4==4.11.1
2+
certifi==2022.9.14
3+
charset-normalizer==2.1.1
4+
click==8.1.3
5+
Flask==2.2.2
6+
gunicorn==20.1.0
7+
html5lib==1.1
8+
idna==3.4
9+
itsdangerous==2.1.2
10+
Jinja2==3.1.2
11+
MarkupSafe==2.1.1
12+
mf2py==1.1.0
13+
mf2util==0.5.1
14+
requests==2.28.1
15+
six==1.16.0
16+
soupsieve==2.3.2.post1
17+
urllib3==1.26.12
1918
webencodings==0.5.1
20-
Werkzeug==0.11.3
19+
Werkzeug==2.2.2

runtime.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-2.7.15
1+
python-3.9.14

0 commit comments

Comments
 (0)