Commits

Jure Žbontar  committed c50096e

Fixed error when article not found on google scholar

  • Participants
  • Parent commits 8691f59

Comments (0)

Files changed (2)

File src/gui_vim.py

 def fetch_bibtex():
     doc = parse_info()
     doc['bibtex'] = ref.fetch_bibtex(doc['title'])
+    if not doc['bibtex']:
+        print 'Fetch failed'
+        return
     doc.update(ref.parse_bibtex(doc['bibtex']))
     save_info(doc)
     write_info(doc)
     doc['rating'] = 'U'
     if fetch:
         doc['bibtex'] = fetch_bibtex(doc['title'])
+        if not doc['bibtex']:
+            doc['bibtex'] = '@{{\n  title={}\n}}\n'.format(doc['title'])
         doc.update(parse_bibtex(doc['bibtex']))
     
     try:
     try:
         url = '/scholar?q=allintitle:' + urllib2.quote(title)
         match = re.search(r'<a href="(/scholar.bib[^"]+)', scholar_read(url))
-        if not match:
-            raise ValueError('Title not found')
         return scholar_read(match.group(1))
-    except (urllib2.HTTPError, urllib2.URLError):
-        return '@{{\n  title={}\n}}\n'.format(title)
+    except (urllib2.HTTPError, urllib2.URLError, AttributeError):
+        return
 
 
 def delay(n, interval):