Implement CSV writer and balance getter
This commit is contained in:
parent
2d5d9c1407
commit
22416136f6
56
balance.py
Executable file
56
balance.py
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/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())
|
11
reader.py
11
reader.py
|
@ -1,11 +0,0 @@
|
||||||
#!/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())
|
|
1
static.py
Normal file
1
static.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
fieldlist = ["number", "validity", "cvc", "ccn", "purchased_on", "purchased_at"]
|
28
writer.py
Executable file
28
writer.py
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/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())
|
Loading…
Reference in a new issue