Jump to content

Tomasz Banas

Member
  • Posts

    12
  • Joined

  • Last visited

Posts posted by Tomasz Banas

  1. Deanishe, you're right. I'm not sure what to do, where to add my API key, etc. I created "script filter" but still don't know what I'm doing wrong. Do you mind uploading the final forkflow? as of the installation Alfred says "If you intend to distribute your workflow to other users, you should include Alfred-Workflow (and other non-standard Python libraries your workflow requires) within your workflow as described above. Do not ask users to install anything into their system Python. That way lies broken software." So, I guess I should not to force someone to install anything. 

     

    I appreciate your help.

  2. On 6/28/2017 at 4:18 PM, deanishe said:

    Using my Python library for workflows, you'd use a Script Filter and the code would look something like the below. You haven't provided enough information to actually test it, though (such as the actual API you're using), so this is an untested guess.

    
    import sys
    
    from workflow import Workflow3, web
    
    log = None
    
    
    def main(wf):
        query = wf.args[0]
    
        url = 'https://api.website.com/?domain={}&apikey={}&output=json'.format(query, apikey)
        r = web.get(url)
        r.raise_for_status()
        data = r.json()
    
        wf.add_item('DNS test of ' + query)
        wf.add_item('Expected response: ' + data['expectedresponse'])
        for i, d in enumerate(data['response']['server']):
            title = '{} {} - {} - {}'.format(
                i + 1, d['location'], d['resultvalue'], d['resultstatus'])
            wf.add_item(title)
    
        wf.send_feedback()
    
    if __name__ == '__main__':
        wf = Workflow3()
        log = wf.logger
        sys.exit(wf.run(main))

     

     

    Here's the workflow - http://d.inco.re/mYKH6

  3. I'm new to creating Workflows. I'm trying to create a workflow that will pull the data via API to JSON and show results directly in Alfred without the need to visit the website to look at the response.

     

    API REQUEST

    GET https://api.website.com/?domain=test.com&apikey=yourapikey&output=output_type

     

    So, what I'm trying to do is this:

    type "dns test.com"

     

    then request is:

    GET https://api.website.com/?domain=test.com&apikey=123123123123123&output=json

     

    The response will be:

     

    JSON response will look like this:

    {
        "query": {
            "tool": "name of the tool",
            "domain": "test.com"
        },
        "expectedresponse": "205.204.123.234",
        "response": {
            "server": [
                {
                    "location": "Town, Country",
                    "resultvalue": "205.204.123.123",
                    "resultstatus": "ok"
                },
                {
                    "location": "Another Town, Another Country",
                    "resultvalue": "205.204.123.234",
                    "resultstatus": "ok"
                },
            ]
        }
    }

     

    and I'm trying to show it in the Alfred window:

     

    DNS test of test.com

     

    Expected Response: 205.204.70.111

    1. Town, Country - 205.204.123.123 - NOT OK

    2. Another Town, Another Country - 205.204.123.234 - OK

    etc.

     

    Any help would be appreciated :)

     

×
×
  • Create New...