diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..c47b345 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14.2 \ No newline at end of file diff --git a/README.md b/README.md index 40bb79d..4d81456 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/app.py b/app.py index c2a370e..808c04c 100644 --- a/app.py +++ b/app.py @@ -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" @@ -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"]): @@ -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) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..08ff6ec --- /dev/null +++ b/pyproject.toml @@ -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", +] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e3bbed6..0000000 --- a/requirements.txt +++ /dev/null @@ -1,19 +0,0 @@ -beautifulsoup4==4.11.1 -certifi==2022.9.14 -charset-normalizer==2.1.1 -click==8.1.3 -Flask==2.2.2 -gunicorn==20.1.0 -html5lib==1.1 -idna==3.4 -itsdangerous==2.1.2 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -mf2py==1.1.2 -mf2util==0.5.1 -requests==2.28.1 -six==1.16.0 -soupsieve==2.3.2.post1 -urllib3==1.26.12 -webencodings==0.5.1 -Werkzeug==2.2.2 diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index 25fd1e5..0000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -python-3.9.14 \ No newline at end of file