Commit 22416136 authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Implement CSV writer and balance getter

parent 2d5d9c14
#!/usr/bin/env python3
import csv
import static
import requests
import threading
import queue
import bs4
import sys
def getFile(filename = 'list.csv', fieldnames = static.fieldlist):
with open(filename, "r") as csf:
return list(csv.DictReader(csf, fieldnames))
def getBalance(card, ccn, q = None, eq = None):
try:
with requests.Session() as session:
session.headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"}
session.get("https://b2bpr.vaservices.eu/plb/PayLifeBalanceInquiry/")
data = {"j_username": card, "j_password": ccn, "Submit": "Submit"}
html = session.post("https://b2bpr.vaservices.eu/plb/PayLifeBalanceInquiry/j_security_check", data=data).text
balance = bs4.BeautifulSoup(html, "html5lib").findAll("td")[14].text
output = float(balance.replace(",", "."))
if q:
q.put((card, output))
return output
except:
if eq:
eq.put(sys.exc_info())
raise
if __name__ == "__main__":
q = queue.Queue()
eq = queue.Queue()
threads = []
for card in getFile():
t = threading.Thread(target=getBalance, args=(card["number"], card["ccn"], q, eq))
t.start()
threads += [t]
for t in threads:
t.join()
if not eq.empty():
exc = eq.get()
raise exc[1].with_traceback(exc[2])
while not q.empty():
print("%s: %.2f" % q.get())
#!/usr/bin/env python3
import csv
def getDetails(filename = 'list.csv'):
with open(filename) as csf:
reader = csv.DictReader(csf)
return [[row[key] for key in reader.fieldnames] for row in reader]
if __name__ == "__main__":
print(getDetails())
fieldlist = ["number", "validity", "cvc", "ccn", "purchased_on", "purchased_at"]
#!/usr/bin/env python3
import csv
import static
def writeFile(row, filename = "list.csv", fieldnames = static.fieldlist):
with open(filename, "a") as csf:
return csv.DictWriter(csf, fieldnames).writerow(row)
def inputQuery():
output = {}
output["number"] = input("Credit Card Number: ")
assert output["number"].isdecimal() and len(output["number"]) == 16, "Credit card number must be a 16-digit decimal number"
output["validity"] = input("Validity Date: ")
output["cvc"] = input("CVC2: ")
output["ccn"] = input("Customer Control Number: ")
assert output["ccn"].isdecimal() and len(output["ccn"]) == 6, "Customer Control Number must be a 6-digit decimal number"
output["purchased_on"] = input("Date of purchase: ")
output["purchased_at"] = input("Place of purchase: ")
return output
if __name__ == "__main__":
writeFile(inputQuery())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment