Jump to content
smarg19

ZotQuery: an Alfred workflow for Zotero

Recommended Posts

You need to run z:cache first to create the .json file before you run any of the zot queries. Once you do that, try again.

Share this post


Link to post

Indeed, I forgot that before my last attempt. Did so in the mean time with the same old result:

Here an Alfred2 report from the console:

2014.01.11 23:43:37,789 Alfred 2[234]: [ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=4 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)"
 

Edited by kithairon

Share this post


Link to post

I've had time to give the latest update a whirl. After deleting the former build, installing the latest build, editing the .json file, and updating the cache via z:cache. I'm getting the same results; Alfred returns a fallback search. The link below provides the output.log, debug.log, and a screenshot of what's showing up in my console when I attempted to execute the workflow. I should add that I'm eager to provide any assistance I possibly can in resolving this issue. The benefits this workflow will provide to Mac users (who also happen to do a lot of research/ academic writing) will be manifold and I'm happy to participate in testing. Thanks again smarg19 for making this workflow possible.  

 

https://www.dropbox.com/sh/d5zcnq45dbc9g8x/xkn40iQkSX

Share this post


Link to post

For curiosity's sake, I tried a different Zotero API key after testing the latest update. I used one that already had an established connection to my database rather than the one I generated especially for ZotQuery. It didn't seem to make any difference. 

Share this post


Link to post

Dang. Sorry this isn't working. Can you open the action_update-caches.py file and copy lines 450-460 for me? I'm wondering if you have an older version (I test and change and upload and sometimes forget that I left the debugging code in the original). There was a moment where I had commented out the actual writing to file. If you have these lines, however, in the code in that area:

 

# Write final, formatted json to Alfred cache
cache = alp.cache(join='zotero_db.json')
cache_file = open(cache, 'w+')
cache_file.write(final_json.encode('utf-8'))
cache_file.close()
 
then the script is writing the cache. If that's the case, can you actually go to the cache folder (as your log states, it is here: /Users/matthewculbreath/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/com.hackademic.zotquery/zotero_db.json) and take a screen shot. If the .json file is there, open it. Also, can you try some of the other queries. For each one (zot:t and zot:a in particular), after you run it, screenshot the output.log file (it rewrites each time, so you have to screencapture before you run another query.)

Share this post


Link to post
for jtem in att_res:

if item['id'] == jtem['item']:

item['attachments'].append(jtem['attachment'])

 

try:

final_json = json.dumps(db_res, sort_keys=False, indent=4, separators=(',', ': '))

 

# Write final, formatted json to Alfred cache

cache = alp.cache(join='zotero_db.json')

cache_file = open(cache, 'w+')

cache_file.write(final_json.encode('utf-8'))

Share this post


Link to post

Ok, here's a link to screenshots of how lines 450-460 appear in the script. I was unable to locate any cache file in - /Users/matthewculbreath/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/com.hackademic.zotquery/zotero_db.json

The com.hackademic.zotquery folder was present but appeared to be empty even when I tried to reveal any hidden items with XtraFinder. I looked again using Forklift's "Show Invisible Items" view and got the same result. I've included screenshots of these views as well. Let me know if I'm looking in the wrong place.  

 

https://www.dropbox.com/sh/w5dijv5xkonnvo6/uD9wWr9crc

Edited by culb0743

Share this post


Link to post

I just ran through all of ZotQuery's array of -queries; alas, Alfred's returning a fallback as soon as I enter a search term. Let me know if there's anything else I can do to help out. 

Share this post


Link to post

The problem isn't the API key. The query scripts search the zotero_db.json file, and the error says that it can't find it. In order to debug this, I think we'll need better communication. I'm going to DM you and see if we can do a Google Hangout. We'll need some real-time interaction. I'm stumped to be honest.

Share this post


Link to post

The problem is clearly in the action_update-caches.py script, since the error says that it can't find the cache. But your logs say that it is running properly, which should mean that it is creating the file. Does your workflow folder have a test_space.py script? It should. Try opening it, deleting whatever is in there (this is my debugging script) and paste this code in there and run it?

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import alp
import os
from _zotquery import get_zotero_db
 
zotero_path = get_zotero_db()
clone_database = os.path.join(alp.cache(), "zotquery.sqlite")
 
print zotero_path
print '- - -'
print clone_database
Edited by smarg19

Share this post


Link to post

Wait. When you run z:cache, what does the Notification say?

 

If it doesn't say "Final Success! Created JSON cache of Zotero database.", then re-install the new workflow on the GitHub page and try running z:cache again. 

Edited by smarg19

Share this post


Link to post

Ok. re-install the workflow, I think I've fixed it. When you have the newest version installed, run z:cache and see if the Notification is as I said above. If it is, then try a query. Let me know the results ASAP

Share this post


Link to post

YES!! Tomorrow I'll explain the error (for posterity's sake again), but I'm quite thrilled to have it worked out. Thank you so much for your help. It was invaluable.

Share this post


Link to post

Delighted to see you working hard and to find updates this morning. Sorry to report though that I'm now getting a "Setup failed! Cannot locate and clone Zotero database" in Output. Have reinstalled the workflow, changed the .json file with my ID and key and run z:cache. Have also deleted contents of the test_space.py with what you posted in the thread – no difference. (My Zotero is fine, database accessible). Culb0743 is using OS 10.9, I'm still on 10.8.5. Let me know if you have any further ideas.

Share this post


Link to post

Hmm. This means that there is an error in these three lines:

zotero_path = get_zotero_db()
clone_database = os.path.join(alp.cache(), "zotquery.sqlite")
shutil.copyfile(zotero_path, clone_database)
 
My guess would be the first. Can you put this code in the test_space.py script and run it, then tell me exactly what the console reports:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import alp
import os
from _zotquery import get_zotero_db
 
zotero_path = get_zotero_db()
clone_database = os.path.join(alp.cache(), "zotquery.sqlite")
 
print clone_database
print '- - -'
print zotero_path

Share this post


Link to post

Here my console output after pasting your code into my test_space.py

2014.01.12 10:46:50,902 system_profiler[26763]: Error -50 (ffffffce) occurred reading DPCD register data in System Profiler.
2014.01.12 10:46:50,903 system_profiler[26763]: Error -50 (ffffffce) occurred reading DPCD register data in System Profiler.
2014.01.12 10:46:50,903 system_profiler[26763]: Error -50 (ffffffce) occurred reading HDCP register data in System Profiler.
2014.01.12 10:47:17,014 nvALT[226]: remote: 0 updates
 

Share this post


Link to post

Smarg,

 

Thanks for posting this on Packal. Now, everyone can view the project there: Zot Query on Packal. And there should always be an up-to-date copy of the workflow linked from the page with all the screenshots.

 

I'm happy to see people using the repo!

Share this post


Link to post

kithairon. Those errors are truly odd. Typically, when a script has an error and you run it, the error is reported in a line number. For example:

Traceback (most recent call last):
  File "/Users/smargheim/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.E127B2CC-1F13-4485-AF32-4022D5E52A6F/test_space.py", line 10, in <module>
    print clone_database
NameError: name 'clone_database' is not defined

What you have copied doesn't report any line numbers and is truly vague (i.e., I'm guessing, system level). Are you certain you are attempting to execute the test_space.py script in a program that can run Python scripts, such as TextMate, Sublime Text, or CodeRunner (these are all the ones I've used in the past). If you're not, you can download a free version of Sublime Text via their website and run it there. 

 

I honestly cannot help you if these are the errors the script is producing, as these are not errors in the workflow, but in the system (i.e. on you Mac, not in the Alfred system). My guess is, tho, that these are errors in execution, not your Mac, and we can find a better way to debug.

 

- - -

@Shawn Rice, 

Thanks for Packal! I'm actually uploading an updated version now with better icons (each item type (article, book, chapter, conference, etc) now has its own +attachment icon, instead of a single attachment icon) as well as some bug fixes. For all interested in this workflow, please download from Packal and check for updates. I'm a tinkerer who is generally always looking to improve, so having an easy way to upgrade the workflow will be in your best interest.

Share this post


Link to post

One of the main reasons I wanted to make Packal was just so that people could have a canonical place to find workflows and easily find updates without having to constantly troll the forums. When I finish the update-workflow, then things should become much, much easier for everyone; sadly, that project needs to go on hold for at least a week or two so I can write a dissertation chapter or two. Damn important things getting in the way of more fun things.

Share this post


Link to post

Ain't that the truth. My grad classes start back up on Wednesday, and things will slow down on the tinkering/coding front then. Which is sad. But I'm just glad that I got this finished before then, because I'm going to use the hell out of this.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×