Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14.2
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ cd microformats-python-parser-website
Next, install the required dependencies:

```
pip3 install -r requirements.txt
uv sync
```

Next, start the server. You can do this in either debugging mode (where `debug=True`) in Flask or in production mode using Gunicorn.

```
python3 app.py --debug (debug mode)
gunicorn app:app (production mode)
uv run -- app.py --debug (debug mode)
uv run -- gunicorn --bind localhost:8080 app:app (production mode)
```

You can view your running local application at this URL:
Expand Down
33 changes: 16 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import json
import traceback
from collections import OrderedDict
from optparse import OptionParser

import mf2py
import mf2util
from flask import Flask, jsonify, make_response, render_template, request

parser = OptionParser()

parser.add_option(
"-d",
"--debug",
action="store_true",
default=False,
help="Run application in debug mode",
)

(options, args) = parser.parse_args()

app = Flask(__name__)

mf2py.Parser.user_agent = "python.microformats.io (mf2py/" + mf2py.__version__ + ") Mozilla/5.0 Chrome/29.0.1547.57 Safari/537.36"
Expand All @@ -38,13 +25,13 @@ def index():
def fetch_mf2(url):
if url in cached_mf2:
return cached_mf2[url]
p = mf2py.parse(url=url, html_parser=parser or None, img_with_alt = True)
p = mf2py.parse(url=url, html_parser=parser or None)
cached_mf2[url] = p
return p

if url or doc:
p = mf2py.parse(
url=url or None, doc=doc or None, html_parser=parser or None, img_with_alt = True
url=url or None, doc=doc or None, html_parser=parser or None
)
if util:
if any("h-feed" in item["type"] for item in p["items"]):
Expand All @@ -68,6 +55,18 @@ def fetch_mf2(url):
traceback.print_exc()
return jsonify(error="%s: %s" % (type(e).__name__, e)), 400

if __name__ == "__main__":
from optparse import OptionParser

parser = OptionParser()
parser.add_option(
"-d",
"--debug",
action="store_true",
default=False,
help="Run application in debug mode",
)
(options, args) = parser.parse_args()

if options.debug:
app.run(debug=True, port=8080)
if options.debug:
app.run(debug=True, port=8080)
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "microformats-parser-website"
version = "1.0.0"
description = "A web interface for parsing microformats using mf2py"
readme = "README.md"
license = "CC0-1.0"
requires-python = "==3.14.2"
dependencies = [
"flask==3.1.2",
"gunicorn==24.1.1",
"lxml==6.0.2",
"mf2py==2.0.1",
"mf2util==0.5.2",
]
19 changes: 0 additions & 19 deletions requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion runtime.txt

This file was deleted.