Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import urllib.request
- import sys
- from bs4 import BeautifulSoup
- username = 'BUXFER USERNAME'
- password = 'BUXFER PASSWORD'
- def checkError(response):
- result = json.loads(response)
- response = result['response']
- if response['status'] != "OK":
- print("An error occured: " + response['status'].replace('ERROR: ', ''))
- sys.exit(1)
- return response
- # BUXFER ACCOUNT POLLING #
- base = "https://www.buxfer.com/api";
- url = base + "/login?userid=" + username + "&password=" + password;
- # Confirm API request and obtain token
- req = urllib.request.Request(url=url)
- response = checkError(urllib.request.urlopen(req).read().decode('utf-8'))
- token = response['token']
- # Obtain accounts
- url = base + "/accounts?token=" + token;
- req = urllib.request.Request(url=url)
- response = checkError(urllib.request.urlopen(req).read().decode('utf-8'))
- # PCPARTPICKER TOTAL POLLING #
- url = 'PCPARTPICKER BUILD URL'
- req = urllib.request.Request(url=url)
- req_html = urllib.request.urlopen(req).read().decode('utf-8')
- table = [[cell.text for cell in row("td")] for row in BeautifulSoup(req_html, "html.parser")("tr")]
- money = 0
- for entry in table:
- if len(entry) > 2:
- if entry[0] == "Base Total:":
- money = float(entry[1][1:])
- # Parse balance from first account and write to a text file
- balance = response['accounts'][0]['balance']
- f = open(r'PATH_TO_@RESOURCES', 'w')
- f.write('[Variables]\n\nBalance='+str(balance)+'\nGoal='+str(money))
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement