Initial commit

This commit is contained in:
Lars 2024-07-05 22:15:09 +02:00
commit fe860b5f70
8 changed files with 238 additions and 0 deletions

View file

@ -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 }}

124
.gitignore vendored Normal file
View file

@ -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

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

12
plugin.json Normal file
View file

@ -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"
}

25
plugin/osrswiki.py Normal file
View file

@ -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()

34
plugin/searchwiki.py Normal file
View file

@ -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()

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
requests==2.25.1
flox-lib==0.19.6

12
run.py Normal file
View file

@ -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()