mirror of
https://github.com/JuanCanham/skill-desktop-launcher.git
synced 2024-11-22 00:40:10 +00:00
Fix code to work with both python2 and python3
Additionally move the imports to the beginning of the file. I would remove the sys.path.append code, but I didn't want to change the behaviour.
This commit is contained in:
parent
ee7dd2bb03
commit
223936a719
25
__init__.py
25
__init__.py
@ -17,7 +17,6 @@
|
||||
|
||||
|
||||
import sys
|
||||
import urllib2
|
||||
import webbrowser
|
||||
import subprocess
|
||||
|
||||
@ -27,6 +26,16 @@ from os.path import dirname, join
|
||||
|
||||
from mycroft.skills.core import MycroftSkill
|
||||
from mycroft.util.log import getLogger
|
||||
if sys.version_info[0] < 3:
|
||||
from urllib import quote
|
||||
try:
|
||||
import gio
|
||||
except ModuleNotFoundError:
|
||||
sys.path.append("/usr/lib/python2.7/dist-packages")
|
||||
import gio
|
||||
else:
|
||||
from urllib.parse import quote
|
||||
from gi.repository import Gio as gio
|
||||
|
||||
logger = getLogger(__name__)
|
||||
__author__ = 'seanfitz'
|
||||
@ -40,16 +49,6 @@ class DesktopLauncherSkill(MycroftSkill):
|
||||
self.appmap = {}
|
||||
|
||||
def initialize(self):
|
||||
try:
|
||||
import gio
|
||||
except:
|
||||
sys.path.append("/usr/lib/python2.7/dist-packages")
|
||||
try:
|
||||
import gio
|
||||
except:
|
||||
logger.error("Could not import gio")
|
||||
return
|
||||
|
||||
tokenizer = EnglishTokenizer()
|
||||
|
||||
for app in gio.app_info_get_all():
|
||||
@ -102,13 +101,13 @@ class DesktopLauncherSkill(MycroftSkill):
|
||||
|
||||
def handle_launch_website(self, message):
|
||||
site = message.data.get("Website")
|
||||
webbrowser.open(IFL_TEMPLATE % (urllib2.quote(site)))
|
||||
webbrowser.open(IFL_TEMPLATE % (quote(site)))
|
||||
|
||||
def handle_search_website(self, message):
|
||||
site = message.data.get("Website")
|
||||
search_terms = message.data.get("SearchTerms")
|
||||
search_str = site + " " + search_terms
|
||||
webbrowser.open(IFL_TEMPLATE % (urllib2.quote(search_str)))
|
||||
webbrowser.open(IFL_TEMPLATE % (quote(search_str)))
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user