Jump to content

ZotQuery: an Alfred workflow for Zotero


Recommended Posts

the workflow is configured, the cache however send me a result: traceback (most recent call last): File "action_update-caches.py", line 47, i…   the line 47: "shutil.copyfile(zotero_path, clone_database)". That makes me thing that the problem could be at the cache/library I don't know...

 

As I said, I'm completely nearby Alfred and so on, BUT I just started because of your workflow… 

 

I hope this log is that you expected for. I've read your previous posts but I don't know where the problem is so I'm afraid to change things that are working well:

Image 1

Image 2

Image 3

Image 4

Image 5

Image 6

Image 7

Image 8

 

If I made mistake please let me know how to show the action and filter logs

Thanks a lot

Link to comment

Those are screenshots of the code, not log files.

 

You should post the contents of the files action.log and filter.log, not one of the scripts. Please post text, not images of text.

 

If the files are large, you can post the content at Pastebin and just post links to your pastes in here.

Link to comment

Don't be ashamed. The inner guts of a workflow (especially one as complicated as ZotQuery) can be quite the maze. I will post some screenshots later, but I have a guess as to the source of the problem. 

 

When you configured ZotQuery, did any dialog boxes pop up that prompted you to select either:

* your Zotero .sqlite database

* the folder where your linked attachments reside

* Zotero's internal storage folder?

 

If this is a bit confusing, please tell me exactly what happened when you first configured the workflow.

Link to comment

Ok. I'm going to take a stab at what the bug is. I've uploaded v. 5.8 to Packal. Go download and upgrade. Now, this is very important, I will need you to do one thing before you try to run `z:config` again. 

 

Open Finder and up in the Menu Bar go to "Go". In the drop-down menu go all the down to the bottom, where you will find "Go to Folder...". This will bring up a small dialog box. I want you to paste (cmd+v) this file path into that dialog box:

>~/Library/Application Support/Alfred 2/Workflow Data/com.hackademic.zotquery/

 

After you paste this path in, press Return (i.e. Enter) and Finder will take you to that folder. Inside of that folder you will find a few files. I need you to find a file call **paths.json** and delete it. Put it in the Trash. Once this file is removed, you can then (and only then) run `z:config`. 

 

Please let me know everything that happens when you run `z:config` and then let me know the final result as well. Hopefully, this will resolve the issue. 

 

Please let me know,

stephen

Link to comment

I did as you said and was going pretty fine, but I probably choose the wrong path to the zotero sqlite databe, because an error was reported:

System events got an error: the file do not include an icon

 

and also there wasn't demanded my Zotero User ID

Edited by rafaelcampos
Link to comment

Can you give the full error? It will be in the log files. These files are in the workflow folder. To find this folder, open Alfred, go to the ZotQuery workflow, double click on the the zot script filter and click the bottom "Open Wokflow Folder". There will be an action.log and filter.log file in that folder. Past what is in both files.

Also, the full error wherever you got it, should include which script failed and at what line

Link to comment

Hey Stephen, It's working!

 

I found the zotero sqlite: /Users/Local/Library/Application Support/Zotero/Profiles/91d59nt0.default/zotero

 

rebooted the mac & did again as you said to me, and now it's working man!!!!  :D

 

I'll run everything to be sure that all is quiet running, but I let you know in any case…

 

Thank you I do appreciate your help

Link to comment

Perfect! I'm sorry for the initial bug. Thanks for helping me find it. I hope ZotQuery helps you out a lot. And let me know if everything continues to run smoothly.

Also, for my notes, could you let me know your Zotero setup. Do you use Zotero Standalone or Zotero Firefox? Or both?

Link to comment

For other workflow writers, I'll share the bug.

 

As a part of the config process ZotQuery tries to find the 3 paths mentioned above. Often, these will be found in the settings file, but if they aren't the workflow pops up a `choose folder` or `choose file` dialog. Originally, I was just using those, and so the result was an AppleScript alias, which was then saved to the paths.json file. So later when the update cache script runs, it goes and gets that path from the json file. It expects a POSIX path, but was getting an alias.

 

The solution involves my [user interaction AS helper functions](http://www.alfredforum.com/topic/3956-applescript-user-interaction-helper-functions/). The helper functions for choose_folder and choose_file return POSIX paths. So for anyone who uses AS interaction dialog to get paths and wants to save them for later reading from other scripts, be sure that you are saving file paths in the proper format. And if you want to take any hassle out of it, go to my [GitHub](https://github.com/smargh/AppleScript_Helpers) and check out those helper functions.

 

Another change for v. 5.8 was to enable re-configuring. Now, anytime you run `z:config` the configuration scripts will run. The export styles script and the Zotero API scripts will read their appropriate files and offer the previous data as default answers. Currently (I'm about to change it for 5.9), the script to find the paths only runs if there is no previous file. It will change to also offer the previous data paths as defaults. This will allow user's more easily (without finding the storage directory and deleting certain files) to change their configuration settings, or as in this case, to fix a configuration mistake. 

Edited by smarg19
Link to comment

You'd have to be more specific regarding the layout of the database.

I assume you'd need to search across multiple data within each database entry.

I've been working on a library for Python workflows. You might want to have a look at the filter function to see how to implement search.

It performs an Alfred-like search, looking at capital letters, initials, substrings and finally anything that contains all the characters of the query.

What you'd need to do is to generate a decent "key" for each database entry by combining relevant fields into a single string.

You might also want to consider rewriting ZotQuery a little bit to use the library: it provides a run method that will catch and log any errors thrown and makes it very easy to retrieve the logs (this seems to be an ongoing difficulty for users of ZotQuery). See the Magic arguments section of the README for details.

Edited by deanishe
Link to comment

I've actually been watching your workflow library. I've been wanting to migrate from alp (which is great, but stagnant). If you say it's ready to rumble, I'll start migrating.

I've actually already written a key function to generate a single string of relevant data, so it shouldn't be too difficult to migrate and utilize the filter function.

Also, having an easy way to open the log files would be great. I'm constantly working to make the workflow as user-friendly as possible. In my mind, that means not having to navigate to any of the key directories (root, storage, cache). So enabling users to get the logs without opening the root directory would be a perfect next step.

In general, your library appears to take the same general approach to certain issues that I would take, so I look forward to working with it. Hopefully I can fully migrate in the next few weeks. Would you say the library is at a 1.0 version now?

Link to comment

I didn't think I'd mentioned the library before, but I see you found it on GitHub :)

I spent this evening writing the unit tests (and discovered serveral bugs so far). Coverage is up to 87%, and I expect I'll get to 100% tomorrow, so any glaring bugs will be gone by then. And it's a lot smaller and a fair bit more Pythonic than alp (a major goal).

I've written a couple of workflows based on it myself, so it's definitely useable.

To be honest, a good number of the features were inspired by the problems I've noticed popping up in this thread (ZotQuery is a heck of an ambitious project, and its users are not the übergeeks that other workflows appeal to), so I'd be very pleased if you, as sort of the epitome of the target audience, would give it a try, and I'd really appreciate your feedback on using it: if it's good enough for ZotQuery, it's good enough for anything, IMO.

ZotQuery as it stands, however, is structured in a rather unusual way for a Python program, and would benefit from significant refactoring to make the most of Python and the workflow library. I'd be very happy if you'd consider that and if I could offer any assistance.

Edited by deanishe
Link to comment

I'm a clever researcher :)

And I'm certain ZotQuery isn't quite right on the Python side. To be honest, this was the project I used to learn Python, so I'm still effectively a noob. I've tried my best to get the functionality I want with an nimble implementation, but my lack of realnPython knowledge and best practices has certainly hampered me.

I'd love to learn the right ways to code in Python tho, and if migrating to your library provide that opportunity, I'm all in, tho I'll undoubtedly need some assistance on just what Python beat practices are

Link to comment

Hi Stephen


I get a situation on Attach new PDFs. I've tried both ways: by Alfred’s file manager and by hotkey. This works well.


Then a ZotQuery box pops up asking me what terms I wanna use for ZotQuery: SEARCH, GOOGLE, DEEP, Answered, Question, July, HARVESTING? 


I chose Google (but I've tried others as well). from here, does not work anymore.


A z:pdf search launch asking if I just wanna attach the PDF to Zotero item, or if a wanna Create a new Zotero Item and attach the chosen PDF. However, no matter which I chose notting works. 


After that, I also tried launch the z:add. At this time, when I do that appears the search parameter "zot z:add" and gives me an error: "ERROR! no results found".


Am I doing something wrong, or should I change some stuff?


Yours


Link to comment

@deanishe,

 

I've started migrating ZotQuery's code to your library. I wanted to let you know that the process has already cleaned a few things up. I realized that I only need on `filter.py` script that accepts two vars (query, search scope), and I have dict->string keys for all the relevant search scopes as well. So while I'm sure there are still tons of non-Pythonic code in the workflow, I'm already shrinking its size just by essentially starting over with all the knowledge I've accumulated since starting this project.

Link to comment

UPDATE: version 6.0

Download at Packal: http://www.packal.org/workflow/zotquery
 
I've migrated to deanishe's workflow library. This has led to some general code clean-up as well. 
 
New:

  • short script filter keywords:
  • z = zot
  • zt = zot:t
  • za = zot:a
  • znc = zot:c
  • znt = zot:tag
  • zn = zot:n
  • zat = z:att
  • ztg = z:tag
  • zc = z:col
  • Note: All previous, long keywords still work. Workflow is backwards compatible

 

Removed:

  • ability to attach pdfs (coming soon)

Upcoming:

  • pdf management stuff
  • debugging stuff
  • writing workflow stuff
Edited by smarg19
Link to comment

Wow! You've tidied it up a whole lot.

FWIW, you can go back to installing requests, feedparser etc. into the dependencies subdirectory if you call Workflow thusly:

 

wf = Workflow(libraries=['./dependencies'])
A safer way would be to use:

 

wf = Workflow(libraries=[os.path.join(os.path.dirname(__file__),
                                      'dependencies')])
Link to comment
Good point. Thanks for the reminder. I've changed the workflow accordingly, but I won't push out an update till I finish at least one more of my desired goals. 

One of my long-term, don't mess with now goals is to see whether I can port pyzotero away from its requests dependency to your web module. But that's for another month :)

Link to comment

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
×
×
  • Create New...