commit c12ae73a062ad9b28d3e2e25524b95cdd31c937d Author: Lars Date: Fri Jul 5 22:15:09 2024 +0200 Initial commit diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..f8abe32 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + tags: + - '*' +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9.19' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r ./requirements.txt -t ./lib + mkdir uploads + zip -r uploads/Flow.Launcher.Plugin.OSRSSearch-${{ env.GITHUB_REF_NAME }}.zip . -x '*.git*' '*.forgejo*' + - name: Create release + uses: actions/forgejo-release@v1 + with: + direction: upload + url: https://git.lrsb.nl + release-dir: uploads + token: ${{ secrets.ACCESS_TOKEN }} + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fcf2e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,124 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Flox library folder +flox + +# VScode + +.vscode/ +bin/ + +scripts/test.json \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..6b028b3 Binary files /dev/null and b/icon.png differ diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..88a44e2 --- /dev/null +++ b/plugin.json @@ -0,0 +1,12 @@ +{ + "ID": "060347D7D8A8070255342938D465B04F", + "ActionKeyword": "osrs", + "Name": "OSRSSearch", + "Description": "Searches OSRS Wiki", + "Author": "Lars", + "Version": "0.0.4", + "Language": "python", + "Website": "https://git.lrsb.nl/lars/osrssearch", + "IcoPath": "./icon.png", + "ExecuteFileName": "run.py" +} \ No newline at end of file diff --git a/plugin/osrswiki.py b/plugin/osrswiki.py new file mode 100644 index 0000000..33d3b91 --- /dev/null +++ b/plugin/osrswiki.py @@ -0,0 +1,25 @@ +import json +import os +import shutil +import requests + +BASE_URL = 'https://oldschool.runescape.wiki/api.php?action=query&list=search&srwhat=text&format=json&srsearch=' + +class OSRSSearch(object): + def __init__(self): + self._session = requests.Session() + + def request(self, method, url, params=None, verify_ssl=True, timeout=60): + response = self._session.request(method, url, params=params, verify=verify_ssl, timeout=timeout) + response.raise_for_status() + return response + + def search(self, query): + if not query: + query = '' + params = { + ('srsearch', query) + } + response = self.request("get", BASE_URL, params) + return response.json() + \ No newline at end of file diff --git a/plugin/searchwiki.py b/plugin/searchwiki.py new file mode 100644 index 0000000..d02324b --- /dev/null +++ b/plugin/searchwiki.py @@ -0,0 +1,34 @@ +import webbrowser +import re +import os +import tempfile +from flox import Flox +from osrswiki import OSRSSearch, BASE_URL + +WIKI_URL = 'https://oldschool.runescape.wiki/w/' + +class OSRSSearcher(Flox): + def __init__(self): + self.OSRSWIKI = OSRSSearch() + super().__init__() + + def query(self, query): + results = self.OSRSWIKI.search(query)["query"]["search"] + for result in results: + openurl = f"{WIKI_URL}{result['title'].replace(' ', '_')}" + self.add_item( + title=result['title'].replace('"', ''), + subtitle="Open OSRS Wiki", + method='open_url', + parameters=[openurl] + ) + return + + def context_menu(self, data): + pass + + def open_url(self, url): + webbrowser.open(url) + +if __name__ == "__main__": + OSRSSearcher() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..998f4da --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.25.1 +flox-lib==0.19.6 \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..e4dc7d3 --- /dev/null +++ b/run.py @@ -0,0 +1,12 @@ +import sys +import os + +plugindir = os.path.abspath(os.path.dirname(__file__)) +sys.path.append(plugindir) +sys.path.append(os.path.join(plugindir, "lib")) +sys.path.append(os.path.join(plugindir, "plugin")) + +from plugin.searchwiki import OSRSSearcher + +if __name__ == "__main__": + OSRSSearcher() \ No newline at end of file