55import json
66import time
77import six
8- import pprint
98from selenium import webdriver
109from selenium .common .exceptions import NoSuchElementException
1110from datetime import datetime
2322LAST_ADD_ON_CHECK = START_TIME
2423
2524
25+ def log (s ):
26+ """Prints s with the date/time like Jul 16 09:15:48 PM CDT Hello world"""
27+ print ("{} {}" .format (time .strftime ("%b %d %I:%M:%S %p %Z" ), s ))
28+
29+
2630def print_pucauto ():
2731 """Print logo and version number."""
2832
@@ -34,7 +38,7 @@ def print_pucauto():
3438 | ___|| || _|| || | | | | |_| |
3539 | | | || |_ | _ || | | | | |
3640 |___| |_______||_______||__| |__||_______| |___| |_______|
37- pucauto.com v0.4.6
41+ pucauto.com v0.4.7
3842 github.com/tomreece/pucauto
3943 @pucautobot on Twitter
4044
@@ -118,7 +122,7 @@ def send_card(card, add_on=False):
118122 """
119123
120124 if CONFIG .get ("debug" ):
121- print (u" DEBUG: Skipping send of '{}'" .format (card ["name" ]))
125+ log (u" DEBUG: Skipping send of '{}'" .format (card ["name" ]))
122126 return False
123127
124128 # Go to the /trades/sendcard/******* page first to secure the trade
@@ -131,7 +135,7 @@ def send_card(card, add_on=False):
131135 reason = DRIVER .find_element_by_tag_name ("h3" ).text
132136 # Indented for readability because this is part of a bundle and there
133137 # are header/footer messages
134- print (u" Failed to send {}. Reason: {}" .format (card ["name" ], reason ))
138+ log (u" Failed to send {}. Reason: {}" .format (card ["name" ], reason ))
135139 return False
136140
137141 # See if the the PucaShield insurance checkbox is checked or not
@@ -147,11 +151,11 @@ def send_card(card, add_on=False):
147151 DRIVER .get (confirm_url )
148152
149153 if add_on :
150- print (u"Added on {} to an unshipped trade for {} PucaPoints!" .format (card ["name" ], card ["value" ]))
154+ log (u"Added on {} to an unshipped trade for {} PucaPoints!" .format (card ["name" ], card ["value" ]))
151155 else :
152156 # Indented for readability because this is part of a bundle and there
153157 # are header/footer messages
154- print (u" Sent {} for {} PucaPoints!" .format (card ["name" ], card ["value" ]))
158+ log (u" Sent {} for {} PucaPoints!" .format (card ["name" ], card ["value" ]))
155159
156160 return True
157161
@@ -344,7 +348,7 @@ def complete_trades(highest_value_bundle):
344348 member_name = highest_value_bundle [1 ]["name" ]
345349 member_points = highest_value_bundle [1 ]["points" ]
346350 bundle_value = highest_value_bundle [1 ]["value" ]
347- print (u"Found {} card(s) worth {} points to trade to {} who has {} points..." .format (
351+ log (u"Found {} card(s) worth {} points to trade to {} who has {} points..." .format (
348352 len (sorted_cards ), bundle_value , member_name , member_points ))
349353
350354 success_count = 0
@@ -354,7 +358,7 @@ def complete_trades(highest_value_bundle):
354358 success_value += card ["value" ]
355359 success_count += 1
356360
357- print ("Successfully sent {} out of {} cards worth {} points!" .format (
361+ log ("Successfully sent {} out of {} cards worth {} points!" .format (
358362 success_count , len (sorted_cards ), success_value ))
359363
360364
@@ -366,6 +370,7 @@ def find_trades():
366370 global LAST_ADD_ON_CHECK
367371
368372 if CONFIG .get ("find_add_ons" ) and should_check_add_ons ():
373+ log ("Finding add-ons..." )
369374 find_and_send_add_ons ()
370375 LAST_ADD_ON_CHECK = datetime .now ()
371376 goto_trades ()
@@ -383,7 +388,7 @@ def find_trades():
383388 """Start Pucauto."""
384389
385390 print_pucauto ()
386- print ("Logging in..." )
391+ log ("Logging in..." )
387392 log_in ()
388393 goto_trades ()
389394 wait_for_load ()
@@ -394,14 +399,14 @@ def find_trades():
394399 # matching really is on, but I don't have a clever solution for it yet, so
395400 # this is a band-aid safety measure.
396401 time .sleep (5 )
397- print ("Turning on auto matching..." )
402+ log ("Turning on auto matching..." )
398403 turn_on_auto_matching ()
399404 time .sleep (5 )
400405
401406 wait_for_load ()
402407 sort_by_member_points ()
403408 wait_for_load ()
404- print ("Finding trades..." )
409+ log ("Finding trades..." )
405410 while check_runtime ():
406411 find_trades ()
407412 DRIVER .close ()
0 commit comments