-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAmexOffers_print.py
More file actions
executable file
·73 lines (55 loc) · 1.93 KB
/
AmexOffers_print.py
File metadata and controls
executable file
·73 lines (55 loc) · 1.93 KB
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
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from util import Serialization, clear_screen
from driver.model import Amex
import itertools
import sys
def visible_offers():
offers = Serialization.load(Amex.Offer.FILE)
if "-v" in sys.argv:
return offers
ignored = Serialization.load(Amex.Offer.IGNOREDFILE)
visible = [x for x in offers if x not in ignored]
return visible
def main():
if "-v" in sys.argv:
verboseprint()
return
defaultprint()
def verboseprint():
offers = Serialization.load(Amex.Offer.FILE)
printlist = sorted([repr(x) for x in offers], key=str)
Serialization.print_list(printlist)
def defaultprint():
lookup_table = Serialization.load(Amex.CardOffer.FILE)
cards = Serialization.load(Amex.Card.FILE)
offers = sorted(visible_offers(), key=lambda x: x.discovered_date)
groups = itertools.groupby(offers, key=lambda x: x.discovered_date)
index = 0
for date, elmts in groups:
index += 1
prefix = f"{index} "
print("\n"*15)
print("-----------------------")
print(f" Discovered: {date}")
print(f"{prefix}")
for x in sorted(elmts, key=lambda x: x.site.lower()):
print_offer(prefix, x, lookup_table, cards)
def print_offer(prefix, offer, lookup_table, cards):
exp = (offer.expires_string or "").lower()
if exp.startswith("expires "):
exp = exp[8:]
print(f"{prefix}\n{prefix} {offer.site}\n{prefix} {offer.description}\n{prefix} Expires {exp}")
card_uniquekeys_with_offer = [
x.card for x in lookup_table if x.offer == offer]
cards_with_offer = [c for c in cards if c in card_uniquekeys_with_offer]
def format_card(c): return f"{prefix} {c}"
card_strings = [format_card(c) for c in cards_with_offer]
print(f"\n".join(card_strings))
#
# Main
#
if __name__ == "__main__":
clear_screen("AmexOffers.py")
main()
print("\nDone\n")