Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -7,6 +7,7 @@ cp browser.py ~/.local/share/profanity/plugins/.
|
|||||||
cp platform-info.py ~/.local/share/profanity/plugins/.
|
cp platform-info.py ~/.local/share/profanity/plugins/.
|
||||||
cp say.py ~/.local/share/profanity/plugins/.
|
cp say.py ~/.local/share/profanity/plugins/.
|
||||||
cp whoami.py ~/.local/share/profanity/plugins/.
|
cp whoami.py ~/.local/share/profanity/plugins/.
|
||||||
|
cp wikipedia-prof.py ~/.local/share/profanity/plugins/.
|
||||||
cp tests/python-test.py ~/.local/share/profanity/plugins/.
|
cp tests/python-test.py ~/.local/share/profanity/plugins/.
|
||||||
|
|
||||||
cd pid
|
cd pid
|
||||||
|
|||||||
29
syscmd.py
29
syscmd.py
@@ -20,7 +20,10 @@ def create_win():
|
|||||||
prof.win_create(system_win, _handle_win_input)
|
prof.win_create(system_win, _handle_win_input)
|
||||||
|
|
||||||
def _cmd_system(arg1=None, arg2=None):
|
def _cmd_system(arg1=None, arg2=None):
|
||||||
if arg1 == "send":
|
if not arg1:
|
||||||
|
create_win()
|
||||||
|
prof.win_focus(system_win)
|
||||||
|
elif arg1 == "send":
|
||||||
if arg2 == None:
|
if arg2 == None:
|
||||||
prof.cons_bad_cmd_usage("/system")
|
prof.cons_bad_cmd_usage("/system")
|
||||||
else:
|
else:
|
||||||
@@ -32,26 +35,30 @@ def _cmd_system(arg1=None, arg2=None):
|
|||||||
else:
|
else:
|
||||||
result = _get_result(arg2)
|
result = _get_result(arg2)
|
||||||
prof.send_line(u'\u000A' + result)
|
prof.send_line(u'\u000A' + result)
|
||||||
|
elif arg1 == "exec":
|
||||||
|
if arg2 == None:
|
||||||
|
prof.cons_bad_cmd_usage("/system")
|
||||||
|
else:
|
||||||
|
create_win()
|
||||||
|
prof.win_focus(system_win)
|
||||||
|
_handle_win_input(system_win, arg2)
|
||||||
else:
|
else:
|
||||||
create_win()
|
prof.cons_bad_cmd_usage("/system")
|
||||||
prof.win_focus(system_win)
|
|
||||||
if arg1:
|
|
||||||
_handle_win_input(system_win, arg1)
|
|
||||||
|
|
||||||
def prof_init(version, status):
|
def prof_init(version, status):
|
||||||
synopsis = [
|
synopsis = [
|
||||||
"/system",
|
"/system",
|
||||||
"/system <command>",
|
"/system exec <comman>",
|
||||||
"/system send <command>"
|
"/system send <command>"
|
||||||
]
|
]
|
||||||
description = "Run a system command, calling with no arguments will open or focus the system window."
|
description = "Run a system command, calling with no arguments will open or focus the system window."
|
||||||
args = [
|
args = [
|
||||||
[ "send <command>", "Send the result of the command to the current recipient or room" ],
|
[ "exec <command>", "Execute a command" ],
|
||||||
[ "<command>", "The system command to run" ]
|
[ "send <command>", "Send the result of the command to the current recipient or room" ]
|
||||||
]
|
]
|
||||||
examples = [
|
examples = [
|
||||||
"/system \"ls -l\"",
|
"/system exec ls -l",
|
||||||
"/system send \"uname -a\""
|
"/system send uname -a"
|
||||||
]
|
]
|
||||||
prof.register_command("/system", 0, 2, synopsis, description, args, examples, _cmd_system)
|
prof.register_command("/system", 0, 2, synopsis, description, args, examples, _cmd_system)
|
||||||
prof.register_ac("/system", [ "send" ])
|
prof.register_ac("/system", [ "exec", "send" ])
|
||||||
|
|||||||
226
wikipedia-prof.py
Normal file
226
wikipedia-prof.py
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
"""
|
||||||
|
Requires wikipedia API
|
||||||
|
pip install wikipedia
|
||||||
|
|
||||||
|
Example theme options:
|
||||||
|
|
||||||
|
[wikipedia]
|
||||||
|
error=red
|
||||||
|
search=bold_green
|
||||||
|
search.noresult=red
|
||||||
|
search.results=green
|
||||||
|
summary.nopage=red
|
||||||
|
summary.title=bold_green
|
||||||
|
summary.url=magenta
|
||||||
|
summary.text=cyan
|
||||||
|
page.nopage=red
|
||||||
|
page.title=bold_green
|
||||||
|
page.text=cyan
|
||||||
|
images.nopage=red
|
||||||
|
images=bold_green
|
||||||
|
images.url=magenta
|
||||||
|
links.nopage=red
|
||||||
|
links=bold_green
|
||||||
|
links.link=green
|
||||||
|
refs.nopage=red
|
||||||
|
refs=bold_green
|
||||||
|
refs.url=magenta
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import prof
|
||||||
|
|
||||||
|
import wikipedia
|
||||||
|
import os
|
||||||
|
import webbrowser
|
||||||
|
import requests
|
||||||
|
|
||||||
|
win = "Wikipedia"
|
||||||
|
page_ac = []
|
||||||
|
link_ac = []
|
||||||
|
|
||||||
|
def _open_browser(url):
|
||||||
|
savout = os.dup(1)
|
||||||
|
saverr = os.dup(2)
|
||||||
|
os.close(1)
|
||||||
|
os.close(2)
|
||||||
|
os.open(os.devnull, os.O_RDWR)
|
||||||
|
try:
|
||||||
|
webbrowser.open(url, new=2)
|
||||||
|
finally:
|
||||||
|
os.dup2(savout, 1)
|
||||||
|
os.dup2(saverr, 2)
|
||||||
|
|
||||||
|
def _handle_win_input():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def create_win():
|
||||||
|
if prof.win_exists(win) == False:
|
||||||
|
prof.win_create(win, _handle_win_input)
|
||||||
|
|
||||||
|
def _update_autocomplete():
|
||||||
|
prof.register_ac("/wikipedia page", page_ac)
|
||||||
|
prof.register_ac("/wikipedia summary", page_ac)
|
||||||
|
prof.register_ac("/wikipedia images", page_ac)
|
||||||
|
prof.register_ac("/wikipedia links", page_ac)
|
||||||
|
prof.register_ac("/wikipedia refs", page_ac)
|
||||||
|
|
||||||
|
def _search(search_terms):
|
||||||
|
global page_ac
|
||||||
|
|
||||||
|
results = wikipedia.search(search_terms)
|
||||||
|
create_win()
|
||||||
|
if len(results) > 0:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "search", None, "Search results for \"" + search_terms + "\":")
|
||||||
|
for index, result in enumerate(results):
|
||||||
|
page_ac.append(result.encode("utf-8"))
|
||||||
|
prof.win_show_themed(win, "wikipedia", "search.results", None, result.encode("utf-8"))
|
||||||
|
_update_autocomplete()
|
||||||
|
else:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "search.noresults", None, "No search results found for \"" + search_terms + "\"")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def _summary(page_str):
|
||||||
|
global link_ac
|
||||||
|
|
||||||
|
page = wikipedia.page(page_str)
|
||||||
|
create_win()
|
||||||
|
if not page:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "summary.nopage", None, "No such page: \"" + page_str + "\"")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
return
|
||||||
|
|
||||||
|
link_ac.append(page.url.encode("utf-8"))
|
||||||
|
prof.register_ac("/wikipedia open", link_ac)
|
||||||
|
|
||||||
|
prof.win_show_themed(win, "wikipedia", "summary.title", None, page.title.encode("utf-8"))
|
||||||
|
prof.win_show_themed(win, "wikipedia", "summary.url", None, page.url.encode("utf-8"))
|
||||||
|
|
||||||
|
summary = wikipedia.summary(page_str)
|
||||||
|
prof.win_show_themed(win, "wikipedia", "summary.text", None, summary.encode("utf-8"))
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def _page(page_str):
|
||||||
|
page = wikipedia.page(page_str)
|
||||||
|
create_win()
|
||||||
|
if not page:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "page.nopage", None, "No such page: \"" + page_str + "\"")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
return
|
||||||
|
|
||||||
|
prof.win_show_themed(win, "wikipedia", "page.title", None, page.title.encode("utf-8"))
|
||||||
|
prof.win_show_themed(win, "wikipedia", "page.text", None, page.content.encode("utf-8"))
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def _images(page_str):
|
||||||
|
global link_ac
|
||||||
|
|
||||||
|
page = wikipedia.page(page_str)
|
||||||
|
create_win()
|
||||||
|
if not page:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "images.nopage", None, "No such page: \"" + page_str + "\"")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
return
|
||||||
|
|
||||||
|
prof.win_show_themed(win, "wikipedia", "images", None, "Images for " + page_str)
|
||||||
|
for image in page.images:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "images.url", None, image.encode("utf-8"))
|
||||||
|
link_ac.append(image.encode("utf-8"))
|
||||||
|
prof.register_ac("/wikipedia open", link_ac)
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def _links(page_str):
|
||||||
|
global page_ac
|
||||||
|
|
||||||
|
page = wikipedia.page(page_str)
|
||||||
|
create_win()
|
||||||
|
if not page:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "links.nopage", None, "No such page: \"" + page_str + "\"")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
return
|
||||||
|
|
||||||
|
prof.win_show_themed(win, "wikipedia", "links", None, "Links for " + page_str)
|
||||||
|
|
||||||
|
for link in page.links:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "links.link", None, link.encode("utf-8"))
|
||||||
|
page_ac.append(link.encode("utf-8"))
|
||||||
|
_update_autocomplete()
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def _refs(page_str):
|
||||||
|
global link_ac
|
||||||
|
|
||||||
|
page = wikipedia.page(page_str)
|
||||||
|
create_win()
|
||||||
|
if not page:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "refs.nopage", None, "No such page: \"" + page_str + "\"")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
return
|
||||||
|
|
||||||
|
prof.win_show_themed(win, "wikipedia", "refs", None, "References for " + page_str)
|
||||||
|
for ref in page.references:
|
||||||
|
prof.win_show_themed(win, "wikipedia", "refs.url", None, ref.encode("utf-8"))
|
||||||
|
link_ac.append(ref.encode("utf-8"))
|
||||||
|
prof.register_ac("/wikipedia open", link_ac)
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def cmd_wp(subcmd, arg):
|
||||||
|
try:
|
||||||
|
if subcmd == "search": _search(arg)
|
||||||
|
elif subcmd == "summary": _summary(arg)
|
||||||
|
elif subcmd == "page": _page(arg)
|
||||||
|
elif subcmd == "images": _images(arg)
|
||||||
|
elif subcmd == "links": _links(arg)
|
||||||
|
elif subcmd == "refs": _refs(arg)
|
||||||
|
elif subcmd == "open": _open_browser(arg)
|
||||||
|
except wikipedia.exceptions.WikipediaException as e:
|
||||||
|
create_win()
|
||||||
|
prof.win_show_themed(win, "wikipedia", "error", None, str(e))
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
create_win()
|
||||||
|
prof.win_show_themed(win, "wikipedia", "error", None, "Connection Error")
|
||||||
|
prof.win_show(win, "")
|
||||||
|
prof.win_focus(win)
|
||||||
|
|
||||||
|
def prof_init(version, status):
|
||||||
|
synopsis = [
|
||||||
|
"/wikipedia search <text>",
|
||||||
|
"/wikipedia summary <title>",
|
||||||
|
"/wikipedia page <title>",
|
||||||
|
"/wikipedia images <title>",
|
||||||
|
"/wikipedia links <title>",
|
||||||
|
"/wikipedia refs <title>",
|
||||||
|
"/wikipedia open <url>"
|
||||||
|
]
|
||||||
|
description = "Interact with wikipedia."
|
||||||
|
args = [
|
||||||
|
[ "search <text>", "Search for pages" ],
|
||||||
|
[ "summary <title>", "Show summary for page" ],
|
||||||
|
[ "page <title>", "Show the whole page" ],
|
||||||
|
[ "images <title>", "Show images URLs for page" ],
|
||||||
|
[ "links <title>", "Show links to other pages from page" ],
|
||||||
|
[ "refs <title>", "Show external references for page" ],
|
||||||
|
[ "open <url>", "Open the a URL in the browser" ]
|
||||||
|
]
|
||||||
|
examples = [
|
||||||
|
"/wikipedia search Iron Maiden"
|
||||||
|
]
|
||||||
|
|
||||||
|
prof.register_command("/wikipedia", 2, 2, synopsis, description, args, examples, cmd_wp)
|
||||||
|
|
||||||
|
prof.register_ac("/wikipedia",
|
||||||
|
[ "search", "summary", "page", "images", "links", "refs", "open" ]
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user