-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapital_one_reimburse.py
67 lines (58 loc) · 1.89 KB
/
capital_one_reimburse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from selenium.common import TimeoutException
from yaml import safe_load
from src.driver.webdriver import ChromeDriver
from src.pages.login import LoginPage
from src.pages.purchases import PurchasesPage
from src.utility.utility import random_sleep
with open("parameters.yaml", "r") as f:
parameters = safe_load(f)
driver = ChromeDriver()
login_page = LoginPage(driver, parameters)
login_page.open()
login_page.log_in()
purchase_page = PurchasesPage(driver, parameters)
purchase_page.open()
reimbursed = []
while True:
purchase_page = PurchasesPage(driver, parameters)
purchase_page.open()
try:
card = purchase_page.get_first_purchase_card()
except TimeoutException:
break # No more redeemable purchases
purchase_page.action_chain.click(card).perform() # Must interact to load card text
date = purchase_page.get_purchase_date(card)
merchant = purchase_page.get_purchase_merchant(card)
cost = purchase_page.get_purchase_cost(card)
miles_available, miles_redeemed, remaining_miles, confirmation = (
purchase_page.reimburse(card)
)
print(
f"Reimbursed transaction: {date} {merchant} {cost}\n"
f" Miles available: {miles_available}\n"
f" Miles redeemed: {miles_redeemed}\n"
f" Miles remaining: {remaining_miles}\n"
f" Confirmation: {confirmation}"
)
reimbursed.append(
(
date,
merchant,
cost,
miles_available,
miles_redeemed,
remaining_miles,
confirmation,
)
)
random_sleep(0, 1)
with open("report.csv", "w+") as f:
f.writelines(
[
"date,merchant,cost,miles_available,miles_redeemed,remaining_miles,confirmation\n"
]
+ [
f'"{i[0]}","{i[1]}","{i[2]}","{i[3]}","{i[4]}","{i[5]}","{i[6]}"\n'
for i in reimbursed
]
)