mozilla / active-data-recipes

A repository of various activedata queries and recipes
Mozilla Public License 2.0
9 stars 24 forks source link

Ability to open a query in ActiveData's query tool #17

Closed ahal closed 6 years ago

ahal commented 6 years ago

Sometimes it's nice to run a query in ActiveData's actual query tool (http://activedata.allizom.org/tools/query.html). It's possible to POST a query to that endpoint and receive a URL back. Maybe we could create an adr-query --debug <query> which instead of running the query, get's the URL from the web interface and opens it in the user's browser.

I'm not sold on the name --debug, open to other ideas.

sashafierce commented 6 years ago

Hello @ahal! I am an Outreachy aspirant and I feel I like this project the most thus far hence I would like to start towards solving something, I have installed the adr module and tried to use it( although I'm getting errors with some commands, not sure if its expected behavior). I think I understand this issue, please let me know if this is good bug to start with. Thanks :smile:

ahal commented 6 years ago

Hi @sashafierce , thanks for your interest! Yes you are more than welcome to try this out :). And yes, it's expected that some of the recipes won't work. ActiveData is undergoing a bit of migration so things aren't as stable as we'd like. But as long as you see data from some of the recipes that's good enough for our purposes (the adr inspect one is nice and simple to test out).

This is a little more complicated than some of the other ones, but depending on your experience level it shouldn't be too hard. In a nutshell, you'll need to add an extra parameter to the POST request we send to ActiveData (save=True). Then in the JSON response, you'll find a meta.saved_as key. You can append this to the query tool's URL and then open it in a browser with the webbrowser standard library. You'll need to add some sort of cli flag to hook this up.

Feel free to reach out if you have any questions

sashafierce commented 6 years ago

Thanks @ahal I am looking into this, if someone else wants to try they are welcome to!

TrangNguyenBC commented 6 years ago

Hi @ahal and @sashafierce. I followed above suggestion and found that the POST request is {"from":"meta.tables","meta":{"save":true}}. Can I try this one? Thanks.

klahnakoski commented 6 years ago

@TrangEmily you must include the query you want opened. In your example the query is {"from":"meta.tables"}, which is a special metadata query, and make me wonder why you chose that table.

klahnakoski commented 6 years ago

@TrangEmily the sequence will look something like

  1. The command line options will dictate a particular recipe/query to send to ActiveData
  2. Your code will intercept that send and attach {"meta":{"save":true}} to the query
  3. Your code will intercept the response and record the {"meta":{"saved_as":UID}}
  4. Your code returns the response to the recipe/query, and let it do its work.
  5. Your code will also open http://activedata.allizom.org/query#query_id=UID in the browser