Jump to content
smarg19

ZotQuery: an Alfred workflow for Zotero

Recommended Posts

Copied the your code into test_space.py and ran it in Terminal. Here is what I got. Guess I just ran my first python script...

Hope this helps. Sent you the wrong sort of output – indeed it was system level stuff.

 

Last login: Sun Jan 12 23:11:17 on ttys000
amw-5:~ amw$ python /Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py
Traceback (most recent call last):
  File "/Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py", line 8, in <module>
    clone_database = os.path.join(alp.cache(), "zotquery.sqlite")
  File "/Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/alp/core.py", line 59, in cache
    bundleID = bundle()
  File "/Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/alp/core.py", line 32, in bundle
    raise Exception("info.plist missing.")
Exception: info.plist missing.
amw-5:~ amw$
 

Edited by kithairon

Share this post


Link to post

hmm... The error says that when alp (the Python module I use to interact with Alfred) looks for the `info.plist` file in the workflow folder, it can't find it. This is truly odd. I'm wondering if it might have something to do with the file path. Your Terminal says you are running code from "/Users/[username]/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/", while the standard location that Alfred downloads workflows is "/Users/[username]/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/". Since you are running the script from the Backup, instead of the standard path, you probably are missing the "meat" of the workflow, which is the .plist file. See if you can find the ZotQuery workflow in the path above. Also, open Alfred's preferences, go to the ZotQuery workflow, double click a script filter, and click "Open Workflow Folder" in the bottom right. What is the path of that folder? Is there an "info.plist" file there?

Share this post


Link to post

Have re-installed Alfred and my paths are now vanilla; did the usual user & key-customization in the settings.json, tried running z:cache ("Setup failed"). When I open the workflow's folder, the info-plist is where expected (49 kb). Run the test_space.py with your code in the thread above – here the output of my console:

 

Last login: Sun Jan 12 23:15:12 on ttys000
amw-5:~ amw$ python /Users/amw/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py
Traceback (most recent call last):
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py", line 8, in <module>
    clone_database = os.path.join(alp.cache(), "zotquery.sqlite")
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/alp/core.py", line 59, in cache
    bundleID = bundle()
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/alp/core.py", line 32, in bundle
    raise Exception("info.plist missing.")
Exception: info.plist missing.
amw-5:~ amw$

 

Would so love to have this working but need to meet a deadline later today and will travel for a week as of tomorrow – so no hurry from my part. Thanks for your care. And: snazzy new icons.

Edited by kithairon

Share this post


Link to post

That is really weird. The .plist file is there, but alp isn't finding it. We're going to need some clearer bug reporting. Put this code in the `test_space.py` file and run it then send me the results:

 

import os

infoPath = os.path.abspath("./info.plist")
print infoPath
print os.path.exists(infoPath)

Share this post


Link to post

Here it is:

Last login: Mon Jan 13 09:06:04 on ttys000
amw-5:~ amw$ python /Users/amw/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py
/Users/amw/info.plist
False
amw-5:~ amw$

Share this post


Link to post

Ok. I'm not sure why, but absolute path isn't looking in the pwd, but instead your HOME PATH (equivalent to ~/). But, I've altered the alp code to avoid using that method. I've uploaded an updated version of ZotQuery to Packal: http://packal.org/workflow/zotquery. Please update and try again. Just like you have done: alter settings.json, run z:cache, then try a query. 

Share this post


Link to post

Downloaded the latest version and followed the procedure. No success. Here the console's output after running test_space.py:

Last login: Mon Jan 13 09:19:43 on ttys000
amw-5:~ amw$ python /Users/amw/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py
Traceback (most recent call last):
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py", line 3, in <module>
    from dependencies.pyzotero import zotero
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/dependencies/pyzotero/zotero.py", line 42, in <module>
    import requests
ImportError: No module named requests
amw-5:~ amw$

Share this post


Link to post

Where is the error in trying to use the workflow itself? Will it still not cache? Or is the query not working? What does the notification say when you run z:cache? 

 

I'll have to look into the requests module. But for now, I want to see how of the workflow is still broken for you, and what does actually work.

Share this post


Link to post

Let's see if you actually have the requests module. Open Finder, and select Go -> Go to Folder..., then past in this path:

/Library/Python/2.7/site-packages/requests/

Does it exist? If not, try just going to /Library/Python. What all is there? What is the last version of Python there?

Share this post


Link to post

It says "Setup failed! Cannot locate and clone Zotero database"

 

The Path " /Library/Python/2.7/site-packages/requests/" does not exist. When I navigate to /Library/Python the last version it contains is 2.7 – which in turn contains the folder "site-packages"and a single file called "readme". Nothing else is there.

Share this post


Link to post

Well, that would be the problem. For whatever reason, you don't have a stable install of Python on your Mac. That's weird. But it should be fairly simple to solve. Go here: http://www.python.org/getit/releases/2.7.6/

 

Then click the link for "Mac OS X 64-bit/32-bit x86-64/i386 Installer (2.7.6) for Mac OS X 10.6 and later". This will begin a download of a .dmg file. When the file downloads, open it it. The dmg will be mounted and there will be four files: Build.txt, License.txt, ReadMe.txt, and Python.mpkg. You will need to RIGHT-CLICK the Python.mpkg file and click "Open" (instead of double clicking), then simply follow the instructions in the installer. This should put Python 2.7.6 on your Mac. When if finishes installing, check in the site-packages folder again and see what's there. 

Share this post


Link to post

Did as suggested. Installed Python 2.7.6. in the manner described, installed Active TCL as suggested in the instructions to Python. Installer reports success. But: the Python folder (/Library/Python/2.7/site-packages/requests/) stays as empty as before – Z:cache correspondingly reports "setup failed." Don't understand this.

 

The system console app reports:

2014.01.13 21:26:40,618 Installer[369]: Package /Volumes/Python 2.7.6/Python.mpkg/Contents/Packages/PythonFramework-2.7.pkg uses a deprecated pre-10.2 format (or uses a newer format but is invalid). I'm out of my depth here.

 

If I run the test_space.py I still get this:

Last login: Mon Jan 13 21:30:57 on console
amw-5:~ amw$ python /Users/amw/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py
Traceback (most recent call last):
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py", line 3, in <module>
    from dependencies.pyzotero import zotero
  File "/Users/amw/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/dependencies/pyzotero/zotero.py", line 42, in <module>
    import requests
ImportError: No module named requests
amw-5:~ amw$

 

Share this post


Link to post

Ok. Python is installed. That's good. The next step is to install the requests module. Go here and follow the instructions to install: https://pypi.python.org/pypi/requests. 

 

Also, the test_space.py script was changed in the recent update (sorry). Can you paste this code in and report the output:

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import alp
from _zotquery import get_zotero_db
import os
# Create a copy of the user's Zotero database 
zotero_path = get_zotero_db()
clone_database = os.path.join(alp.cache(), "zotquery.sqlite")
print zotero_path
print '- - -'
print clone_database
 
I'm really sorry this isn't working. I'm not sure what's up yet.

Share this post


Link to post

Thanks for the help; I downloaded requests but got stumped with the pip install when trying to run it in terminal ("command not found"). Requests-2.2.0 is unzipped and currently in Downloads folder.

Share this post


Link to post

Doesn't quite work for me either. I don't develop in python much, so I was missing quite a few dependencies.

 

In order to install many of the dependencies I did this:

sudo easy_install pip
sudo easy_install requests
sudo easy_install feedparser
sudo easy_install -U setuptools
sudo pip install pyyaml

Easy install is already on Mavericks (I can't speak to earlier versions) but not pip. Also, I needed to upgrade setuptools because there was a much older version. I'm sure that after using easy_install for setuptools and pip, you could use pip for the rest.

 

But, after that, I get this (I replaced the user and the key):

Traceback (most recent call last):
  File "test_space.py", line 20, in <module>
    ref = zot.item(item_key, content='ris')
  File "/Users/Sven/Dropbox/app-syncing/alfred2/Alfred.alfredpreferences/workflows/user.workflow.C1F39965-1324-4463-BA87-DA5CB4AB94F3/dependencies/pyzotero/zotero.py", line 134, in wrapped_f
    retrieved = self._retrieve_data(func(self, *args))
  File "/Users/Sven/Dropbox/app-syncing/alfred2/Alfred.alfredpreferences/workflows/user.workflow.C1F39965-1324-4463-BA87-DA5CB4AB94F3/dependencies/pyzotero/zotero.py", line 243, in _retrieve_data
    error_handler(self.request)
  File "/Users/Sven/Dropbox/app-syncing/alfred2/Alfred.alfredpreferences/workflows/user.workflow.C1F39965-1324-4463-BA87-DA5CB4AB94F3/dependencies/pyzotero/zotero.py", line 1228, in error_handler
    raise error_codes.get(req.status_code)(err_msg(req))
dependencies.pyzotero.zotero_errors.ResourceNotFound:
Code: 404
URL: https://api.zotero.org/users/{USER}/items/7VT63AQG?content=ris&key={KEY}
Method: GET
Response: Item does not exist

Another note: for upgrading purposes, it would be better to move the data storage somewhere else. In the best practices post, David Ferguson recommends this:

Volatile:~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/[bundle id]
Non-Volatile:~/Library/Application Support/Alfred 2/Workflow Data/[bundle id]

One good reason why is that whenever you update the workflow, some files will be wiped out. I know that's how it does work with the unreleased packal updater, and I'm pretty sure that's how it works with Alfred itself. So, the settings, especially, should go in the NV storage as well as the library cache. The logs should go into the V storage, etc.... This helps separate data from code so that different versions of the workflow can use the same data.

 

Share this post


Link to post

pip is actually a module in itself that makes it easier to install Python packages. But it isn't necessary. Open you Terminal and enter these commands:

 

cd Downloads/

[hit the return key]

cd Requests-2.2.0

[hit the return key]

python setup.py install

[hit the return key]

 

That should install it. 

 

Also, shoot me the output of the test_space.py script with the code in the comment above. 

Share this post


Link to post

Thanks for the help; I downloaded requests but got stumped with the pip install when trying to run it in terminal ("command not found"). Requests-2.2.0 is unzipped and currently in Downloads folder.

 

Kithairon, just use the commands in the terminal that I posted above. Don't copy/paste all of them at first. Just copy/paste the first one; then you will get a password prompt. After that, you can copy/paste the others (sudo gives you a cooldown of about 5 minutes before you need to re-enter your pword).

Share this post


Link to post

Shawn, 

 

Thanks for the tip on storage spaces. Will look into it and update. 

 

As to the error, that is an error with the Zotero API. My guess is that when I exported the Workflow, the test_space.py script hadn't been cleaned (my mistake), so it has on of my item_keys in it, which doesn't exist under your user profile. I use that script as a spot to throw in various code and debug. Does the workflow as a whole not work? Or is the error only in the test_space.py script?

Share this post


Link to post

Installed Python – thanks for the embarassing degree of detail in your instruction – unfortunately this is exactly what's needed here...

Here the output of the test_space.py:

Last login: Mon Jan 13 23:04:17 on ttys000
amw-5:~ amw$ python /Users/amw/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.D7572A1D-A5FB-4859-968C-A102A04EBAFF/test_space.py
None
- - -
/Users/amw/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/com.hackademic.zotquery/zotquery.sqlite
amw-5:~ amw$
 

Edited by kithairon

Share this post


Link to post

Ok. the issue is, the script cannot your Zotero database. Do you have Zotero in Firefox or Standalone? If Standalone, go to ~/Library/Application Support/Zotero and dig into the folders, you should find one called Profiles, then one with a random string, then one in that called zotero, is there a zotero.sqlite file there? 

 

If Firefox, go to ~/Library/Application Support/Firefox and dig around there for the zotero.sqlite file. I tried to write the function to handle various setups, but I was sort of guessing in the dark. When/if you find your zotero.sqlite file, let me know where it is. 

 

Be sure to let me know what version of Zotero you have.

Share this post


Link to post

To find out where the file should be (from Zotero documentation): "Use the “Show Data Directory” button in the Advanced pane of your Zotero preferences to reveal the current data directory."

 

What is this path? What is in it? 

Share this post


Link to post

Also, you could put this code into the test_space.py script and run. It will take a while (30-60 seconds), but it will find your zotero.sqlite file path:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
home = os.environ["HOME"]
for root, dirs, files in os.walk(home):
	for file in files:
		if file.endswith('zotero.sqlite'):
			db_path = os.path.join(root, file)
print db_path

Either way (use Zotero preferences or this code), I need to know the path to that file.

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
×