Comments

2 comments

  • Jon Hall
    import urllib.request, urllib.error, urllib.parse
    import sys
    import re
    import base64
    import simplejson

    # XXX WARNING: only a sample; please do NOT hard-code your username
    # or passwords in this manner in your API clients

    username = "username"
    password = "password"

    #############

    Code  block that i got running for py3.8

     

    def checkError(response):
        result = simplejson.load(response)
        response = result['response']
        if response['status'] != "OK":
            print("An error occured: %s" % response['status'].replace('ERROR: ', ''))
            sys.exit(1)

        return response

    url  = base + "/login?userid=" + username + "&password=" + password

    req = urllib.request.Request(url=url)
    response = checkError(urllib.request.urlopen(req))
    token = response['token']

    url  = base + "/budgets?token=" + token
    req = urllib.request.Request(url=url)
    response = checkError(urllib.request.urlopen(req))
    for budget in response['budgets']:
        print("%12s %8s %10.2f %10.2f" % (budget['name'], budget['periodSize'], budget['limit'], budget['balance']))

    sys.exit(0)

     

     

    0
    Comment actions Permalink
  • Jon Hall

    to bring back everything in budget (so you can see the headings) use 

    "print(response)"
     
    after last "response = checkError(urllib.request.urlopen(req))"
    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk