~submarine/unity-scope-googlescholar/trunk

« back to all changes in this revision

Viewing changes to src/unity_scholar_daemon.py

  • Committer: Tarmac
  • Author(s): Guillermo Gonzalez
  • Date: 2013-09-21 08:29:13 UTC
  • mfrom: (7.1.2 gscholar-logging)
  • Revision ID: tarmac-20130921082913-gxbjcf42c3vn6ttt
Add basic logging.

Approved by David Callé, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License along
15
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
 
17
import gettext
 
18
import logging
 
19
import urllib.request
 
20
 
 
21
import lxml.html
 
22
 
17
23
from gi.repository import Unity
18
24
from gi.repository import Gio, GLib
19
 
import gettext
20
 
import lxml.html
21
 
import urllib.request
22
25
 
23
26
APP_NAME = 'unity-scope-scholar'
24
27
LOCAL_PATH = '/usr/share/locale/'
48
51
 
49
52
EXTRA_METADATA = []
50
53
 
 
54
logger = logging.getLogger("unity.scope.googlescholar")
51
55
 
52
56
def search(search, filters):
53
57
    '''
68
72
    icon_hint = Gio.ThemedIcon.new("text-html").to_string()
69
73
 
70
74
    try:
 
75
        logger.debug("Request: %s", url)
71
76
        tree = lxml.html.parse(url)
72
77
    except:
 
78
        logger.debug("lxml request failed, using urllib")
73
79
        html = urllib.request.urlopen(url).read()
74
80
        html = html.decode('utf-8')
75
81
        if html.startswith('<?xml version="1.0" encoding="utf-8"?>'):
88
94
        if len(author) > 30:
89
95
            author = author[:26] + " et al"
90
96
        uri = item.xpath("div/h3/a/@href")[0]
91
 
        group = 0
92
97
        icon_hint = Gio.ThemedIcon.new("scholar").to_string()
93
98
        results.append({'uri': str(uri),
94
99
                        'icon': icon_hint,
148
153
                                                  str(i['comment']), str(i['dnd_uri']),
149
154
                                                  i['metadata'])
150
155
                result_set.add_result(result)
151
 
        except Exception as error:
152
 
            print(error)
 
156
        except Exception:
 
157
            logger.exception("Error while building result set.")
153
158
 
154
159
 
155
160
class Scope(Unity.AbstractScope):