forked from benoitfragit/google2ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoogle2ubuntu.py
executable file
·47 lines (38 loc) · 1.43 KB
/
google2ubuntu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from subprocess import *
from os.path import expanduser
import sys, subprocess, os, json, urllib2, unicodedata, time, gettext, locale
sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/librairy')
from interface import interface
from localehelper import LocaleHelper
localeHelper = LocaleHelper()
lang = localeHelper.getLocale()
t=gettext.translation('google2ubuntu',os.path.dirname(os.path.abspath(__file__))+'/i18n/',languages=[lang])
t.install()
# pause media player if necessary
config = expanduser('~')+'/.config/google2ubuntu/google2ubuntu.conf'
paused = False
haskey = False
key = ''
try:
with open(config,"r") as f:
for line in f.readlines():
line = line.strip('\n')
field = line.split('=')
if field[0] == 'pause' and field[1].replace('"','') != '':
os.system(field[1].replace('"','')+' &')
paused = True
elif field[0] == 'play':
play_command = field[1].replace('"','')
elif field[0] == 'key' and field[1].replace('"','') != '':
key = field[1].replace('"','')
haskey = True
except Exception:
print 'Error reading google2ubuntu.conf file'
if haskey == True:
# launch the recognition
g2u = interface(key)
# restore media player state
if paused:
os.system(play_command+' &')