Open soto97 opened 4 years ago
yeah I'm getting the same error. I'm not sure offhand. Occasionally the CrossRef API goes down. I'll wait a few days and see if it resolves itself first.
the reference importer is not working anymore for me either (on alfred 4.2.1 [1187])
Digging deeper into this, when crossref.py executes this line:
r = requests.get('http://search.crossref.org/dois', params=params)
the result cannot be handled by the json function in models.py.
To test things, right after the value r is populated in crossref.py, but before the for loop where the values of r are split up, I just put this print statement:
print('r = ', r.json['doi'])
Basically, I just wanted to know what the DOI was for the query. I got this error message:
[15:17:11.683] Reference Importer[Script Filter] Queuing argument 'The vertical distribution of Martian aerosol
particle size'
[15:17:12.249] Reference Importer[Script Filter] Script with argv '(null)' finished
[15:17:12.251] ERROR: Reference Importer[Script Filter] Code 1: Traceback (most recent call last):
File "crossref.py", line 34, in <module>
print('r = ', r.json['doi'])
TypeError: 'instancemethod' object has no attribute '__getitem__'
Maybe I am doing something wrong, or maybe there's a miscommunication with CrossRef and they are not sending a properly formatted JSON output? Or did they change that formatting. There are packages in the models.py code that I am not familiar with nor do I know where they are coming from, so I have hit another dead end with this (at least for me).
Note: running the command ref doi_query!!
does work, so I can at least get bibtex entries by entering DOIs. Useful for recent papers, at least.
@andrewning do you have the same problem when you use crossref?
Thanks!
I'm not sure but I think API has changed. Using http://search.crossref.org/dois gives IP block errors.
When I change lines
params = {'q': query, 'rows': '10'}
r = requests.get('http://search.crossref.org/dois', params=params)
to
params = {'query': query, 'rows': '10'}
r = requests.get('https://api.crossref.org/works?', params=params)
I get json response from API.
I couldn't fix the rest though since I'm not very good at Python.
EDIT: I think I fixed it but probably someone can write a better code for this. This is what I have in crossref.py file
# Use crossref metadata search (beta) to get the DOI
params = {'query': query, 'rows': '10'}
r = requests.get('http://api.crossref.org/works', params=params)
data = r.json()
message = list(data.values())[2]
items = list(message.values())[0]
# write results in XML format for Alfred
results = []
for j in items:
doi = j['DOI']
title = j['title'][0]
subtitle = j['container-title'][0]
# info = j['fullCitation']
# entries = info.split('\'')
# subtitle = entries[0]
# if len(entries) > 1:
# subtitle += (''.join(entries[2:])[2:])
# strip out html tag for italic
# subtitle = subtitle.replace('<i>', '')
# subtitle = subtitle.replace('</i>', '')
results.append(alfred.Item(title=title,
subtitle=subtitle,
attributes={'uid': doi, 'arg': doi},
icon='crossref.png'))
yes, I've been aware of the problem and API change for a few weeks, just haven't had time to rework things. Hopefully soon. Looks like @emraher has a good start.
I started with the potential fix that @emraher provided above. That works great.
However, @emraher set the subtitle to the journal name (subtitle = j['container-title'][0]
). Although this is useful, I feel like Reference Importer used to put the author names in that field, which I find more useful for making sure I have the correct reference. When I tried to do that, however, it didn't go well.
In the current Crossref API, the author field is a nested dictionary. The author field looks like this in the raw output:
'author': [{'affiliation': [ ], 'given': [ ], 'family': [ ], 'sequence': [ ]}]
The dictionary includes a number of keys, but only one is required, the 'family' key. Therefore, I replaced the subtitle call with:
subtitle = j['author'][0]['family'][:]
This works, but only partially. When I provided only one word as the search term, for example, ref mar
, I would get a list of papers about Mars with the author given names in the subtitle field. However, once I tried multiple words, for example, ref mars atmosphere
, the query failed. I am stuck now, so I share this with everyone to see if someone else has a solution.
I encourage @emraher to submit their fix as a pull request, because it works and others may want it.
I also ask that if there is a way to put the author info in the subtitle field, I think that would really make the results more useful.
Thanks.
thanks for taking a crack at this! with this update, book
works for me but neither does ref
nor gsref
.
thanks for taking a crack at this! with this update,
book
works for me but neither doesref
norgsref
.
@tobiasgerstenberg have you tried this? What was the error? Also see https://github.com/andrewning/alfred-workflows-scientific/issues/6#issuecomment-357038107
yes, i've tried this one. i don't get an error message when trying to use ref
. the message "searching for matching articles" is displayed for a bit and then alfred just switches to searching via google.
having played around with it for a bit now, it sometimes does work (but not reliably); and it doesn't seem to be dependent on the search query. the same query sometimes works and sometimes doesn't.
@tobiasgerstenberg can you check the log messages in Alfred's debugging mode?
it's working reliably for me now (without me having changed anything). thanks a lot for the update!
@emraher Thanks for the updates that you made. I really like some of the new tweaks.
I did run into one problem: With the version of the workflow in your repository, I got an error for some crossref searches. Here's the error message from the Alfred debugger:
workflow.py:2080 ERROR list indices must be integers, not str
Traceback (most recent call last):
File ".../workflow/workflow.py", line 2073, in run
func(self)
File "crossref.py", line 60, in main
journal = item['institution']['name']
TypeError: list indices must be integers, not str
(Note: I removed some details of the file path (where I wrote "...") for workflow.py because they are not important and are specific to my machine.)
There was an easy fix for this: I just changed line 60 in crossref.py (the line called out in the error message above) to the following:
journal = item['institution'][0]
Basically, I replaced 'name'
with 0
. So far this seems to work great, with the matches showing paper title, author names and the citation source (i.e., the journal). Hopefully, the edit I made won't cause some other problem down the line.
Again, thanks for sharing this fix to respond to the changes in the CrossRef API.
As of today, the reference importer workflow for Alfred is not working for me. I type 'ref' followed by search terms and then I get nothing. Below I have the debug log output from Alfred. You will see me try to different searches. The first one, I just copied and pasted in the query. The second one, I typed the query terms, so you see the queuing working correctly. In both cases the workflow fails and the error message says,
ValueError: No JSON object could be decoded
.Does anyone have any idea what is going on and how to fix it?
Note: I am running on Catalina and I have the most recent version of Reference Importer installed on Alfred 4.1.1.