diff --git a/.vscode/launch.json b/.vscode/launch.json index 9a3dfce..e429905 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,10 +10,11 @@ "request": "launch", "module": "flask", "env": { - "FLASK_APP": "app.py", "FLASK_DEBUG": "1", }, "args": [ + "--app", + "wikimore", "run", "--no-debugger", "--no-reload", diff --git a/README.md b/README.md index 3d5cba4..f3b7f60 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,84 @@ # Wikimore - A simple frontend for Wikimedia projects +[![Support Private.coffee!](https://shields.private.coffee/badge/private.coffee-support%20us!-pink?logo=coffeescript)](https://private.coffee) +[![Matrix](https://shields.private.coffee/badge/Matrix-join%20us!-blue?logo=matrix)](https://matrix.pcof.fi/#/#wikimore:private.coffee) +[![PyPI](https://shields.private.coffee/pypi/v/wikimore)](https://pypi.org/project/wikimore/) +[![PyPI - Python Version](https://shields.private.coffee/pypi/pyversions/wikimore)](https://pypi.org/project/wikimore/) +[![PyPI - License](https://shields.private.coffee/pypi/l/wikimore)](https://pypi.org/project/wikimore/) +[![Latest Git Commit](https://shields.private.coffee/gitea/last-commit/privatecoffee/wikimore?gitea_url=https://git.private.coffee)](https://git.private.coffee/privatecoffee/wikimore) + Wikimore is a simple frontend for Wikimedia projects. It uses the MediaWiki API to fetch data from Wikimedia projects and display it in a user-friendly way. It is built using Flask. This project is still in development and more features will be added in the future. It is useful for anyone who wants to access Wikimedia projects with a more basic frontend, or to provide access to Wikimedia projects to users who cannot access them directly, for example due to state censorship. ## Features -- Multi-language support (currently English and German, more can and will be added) -- Multi-project support (currently Wikipedia and Wiktionary, more can and will be added) +- Supports all Wikimedia projects in all languages - Search functionality - Proxy support for Wikimedia images +## Instances + +| URL | Provided by | Country | Comments | +| ----------------------------------------------------------- | ----------------------------------------- | ------- | -------- | +| [wikimore.private.coffee](https://wikimore.private.coffee/) | [Private.coffee](https://private.coffee/) | Austria | | + +If you operate a public instance of Wikimore and would like to have it listed here, please open an issue or a pull request. + ## Installation +### Production + +1. Create a virtual environment and activate it + +```bash +python3 -m venv venv +source venv/bin/activate +``` + +2. Install the package from PyPI + +```bash +pip install wikimore +``` + +3. Run the application + +```bash +wikimore +``` + +4. Open your browser and navigate to `http://localhost:8109` + +## Development + 1. Clone the repository -2. Install the required packages using `pip install -r requirements.txt` -3. Run the app using `python app.py` -## Usage +```bash +git clone https://git.private.coffee/privatecoffee/wikimore.git +cd wikimore +``` -1. Open your browser and navigate to `http://localhost:5000` -2. Use the search bar to search for articles on a given Wikimedia project, in a given language +2. Create a virtual environment and activate it + +```bash +python3 -m venv venv +source venv/bin/activate +``` + +3. Install the package in editable mode + +```bash +pip install -e . +``` + +4. Run the application + +```bash +flask --app wikimore run +``` + +5. Open your browser and navigate to `http://localhost:5000` ## License diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6fd7268 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "wikimore" +version = "0.1.0" +authors = [{ name = "Private.coffee Team", email = "support@private.coffee" }] +description = "A simple frontend for Wikimedia wikis" +readme = "README.md" +license = { file = "LICENSE" } +requires-python = ">=3.10" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", +] +dependencies = ["flask", "bs4"] + +[project.scripts] +wikimore = "wikimore.app:main" + +[project.urls] +"Homepage" = "https://git.private.coffee/privatecoffee/wikimore" +"Bug Tracker" = "https://git.private.coffee/privatecoffee/wikimore/issues" +"Source Code" = "https://git.private.coffee/privatecoffee/wikimore" diff --git a/src/wikimore/__init__.py b/src/wikimore/__init__.py new file mode 100644 index 0000000..34f275e --- /dev/null +++ b/src/wikimore/__init__.py @@ -0,0 +1,3 @@ +from .app import app + +__all__ = ["app"] diff --git a/app.py b/src/wikimore/app.py similarity index 95% rename from app.py rename to src/wikimore/app.py index c80c3f3..5519a7c 100644 --- a/app.py +++ b/src/wikimore/app.py @@ -3,6 +3,7 @@ import urllib.request from urllib.parse import urlencode, urlparse from html import escape import json +import os import logging from bs4 import BeautifulSoup @@ -208,7 +209,15 @@ def search_redirect(project, lang, query): app.wikimedia_projects, app.languages = get_wikimedia_projects() -print(len(app.wikimedia_projects), len(app.languages)) +logger.debug( + f"Loaded {len(app.wikimedia_projects)} Wikimedia projects and {len(app.languages)} languages" +) + +def main(): + port = int(os.environ.get("PORT", 8109)) + host = os.environ.get("HOST", "0.0.0.0") + debug = os.environ.get("DEBUG", False) + app.run(port=port, host=host, debug=debug) if __name__ == "__main__": - app.run(debug=True) + main() \ No newline at end of file diff --git a/templates/article.html b/src/wikimore/templates/article.html similarity index 100% rename from templates/article.html rename to src/wikimore/templates/article.html diff --git a/templates/base.html b/src/wikimore/templates/base.html similarity index 100% rename from templates/base.html rename to src/wikimore/templates/base.html diff --git a/templates/home.html b/src/wikimore/templates/home.html similarity index 100% rename from templates/home.html rename to src/wikimore/templates/home.html diff --git a/templates/search_results.html b/src/wikimore/templates/search_results.html similarity index 100% rename from templates/search_results.html rename to src/wikimore/templates/search_results.html