From a30ddbb6006fd3163b4e9a2362b2aeca0f532842 Mon Sep 17 00:00:00 2001 From: Nakroma Date: Wed, 9 Mar 2016 18:57:33 +0100 Subject: [PATCH 1/2] Now cancels trades if the minimum value isn't reached --- pucauto.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/pucauto.py b/pucauto.py index ccbddb7..688b3d8 100755 --- a/pucauto.py +++ b/pucauto.py @@ -345,11 +345,46 @@ def complete_trades(highest_value_bundle): if send_card(card): success_value += card["value"] success_count += 1 - + print("Successfully sent {} out of {} cards worth {} points!".format( success_count, len(sorted_cards), success_value)) + # See if enough cards have made it trough + if success_value >= CONFIG["min_value"]: + print("The successful shipping value is under your minimum value, removing cards...") + remove_unshipped_trades(member_name) + + +def remove_unshipped_trades(member_name): + """Removes unshipped cards from a specific member. + + Args: + member_name - A string how the member is called + """ + + DRIVER.get("https://pucatrade.com/trades/active") + + try: + DRIVER.find_element_by_css_selector("div.dataTables_filter input").send_keys(member_name + ' Unshipped') + except NoSuchElementException: + return + + # Wait a bit for the DOM to update after filtering + time.sleep(5) + + soup = BeautifulSoup(DRIVER.page_source, "html.parser") + + cancels = [] + for row in soup.find_all("tr", id=lambda x: x and x.startswith("user_card_")): + cancel_id = row.find("td", class_="sorting_1").text + cancel_href = "https://pucatrade.com/trades/cancel/" + cancel_id + cancels.append(cancel_href) + + for cancel in cancels: + # Goto cancel trade link + DRIVER.get(cancel) + def find_trades(): """The special sauce. Read the docstrings for the individual functions to From 77bbf619c5ed789a2fdc86b7a0af8ab5c9e77a5f Mon Sep 17 00:00:00 2001 From: Nakroma Date: Fri, 11 Mar 2016 20:24:20 +0100 Subject: [PATCH 2/2] Fixed wrong operator --- pucauto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pucauto.py b/pucauto.py index 134ab6b..c429926 100755 --- a/pucauto.py +++ b/pucauto.py @@ -349,7 +349,7 @@ def complete_trades(highest_value_bundle): success_count, len(sorted_cards), success_value)) # See if enough cards have made it trough - if success_value >= CONFIG["min_value"]: + if success_value < CONFIG["min_value"]: print("The successful shipping value is under your minimum value, removing cards...") remove_unshipped_trades(member_name)