This commit is contained in:
commit
c12ae73a06
8 changed files with 238 additions and 0 deletions
25
plugin/osrswiki.py
Normal file
25
plugin/osrswiki.py
Normal 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
34
plugin/searchwiki.py
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue