예제 #1
0
def main(name, dry_run):
    """go through and check wishlist against previous entries"""

    echo.out(
        "{}. Starting on wishlist {}",
        datetime.datetime.utcnow(),
        name,
    )

    # Let's flush out any problems connecting to the DB before getting into the loop
    WatchlistItem.interface.connect()

    name = name[0]
    email = Email(name)
    item_count = 1
    try:
        for item_count, we in enumerate(Wishlist(name), item_count):
            try:
                echo.out("{}. (p{}) {}", item_count, we.page, we.title)

                item = Item(
                    uuid=we.uuid,
                    body=we.jsonable(),
                    price=we.price,
                    element=we,
                )
                add_item(email, item, dry_run)

            except Exception as e:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                email.errors.append((e, (exc_type, exc_value, exc_traceback)))

                echo.err("{}. Failed!", item_count)
                echo.exception(e)

                # bail if we've had a lot of errors or the first N items
                # have all resulted in an error
                total_errors = len(email.errors)
                if total_errors > 25 or (total_errors > 10
                                         and total_errors == item_count):
                    break

        echo.out(
            "{}. Done with wishlist, {} total items, {} changes",
            datetime.datetime.utcnow(),
            item_count,
            len(email),
        )

    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        email.errors.append((e, (exc_type, exc_value, exc_traceback)))
        echo.exception(e)

    if not dry_run:
        email.send(item_count=item_count)
예제 #2
0
def main_dump(name, start_page, stop_page, **kwargs):
    """This is really here just to test that I can parse a wishlist completely and
    to demonstrate (by looking at the code) how to iterate through a list"""
    name = name[0]
    #pout.v(name, start_page, stop_page, kwargs)
    #pout.x()

    pages = set()
    current_url = ""
    w = Wishlist()
    for i, item in enumerate(w.get(name, start_page, stop_page), 1):
        new_current_url = w.current_url
        if new_current_url != current_url:
            current_url = new_current_url
            echo.h3(current_url)

        try:
            item_json = item.jsonable()
            echo.out("{}. {} is ${:.2f}", i, item_json["title"],
                     item_json["price"])
            echo.indent(item_json["url"])

        except RobotError:
            raise

        except ParseError as e:
            echo.err("{}. Failed!", i)
            echo.err(e.body)
            echo.exception(e)

        except KeyboardInterrupt:
            break

        except Exception as e:
            echo.err("{}. Failed!", i)
            echo.exception(e)

        finally:
            pages.add(w.current_page)

    echo.out("Done with wishlist, {} total pages parsed (from {} to {})",
             len(pages), start_page, stop_page)
예제 #3
0
def main_dump(name, **kwargs):
    """This is really here just to test that I can parse a wishlist completely and
    to demonstrate (by looking at the code) how to iterate through a list"""
    name = name[0]
    #pout.v(name, start_page, stop_page, kwargs)
    #pout.x()

    w = Wishlist(name)
    i = 1
    for i, item in enumerate(w, 1):
        try:
            item_json = item.jsonable()
            echo.out("{}. {} is ${:.2f}", i, item_json["title"],
                     item_json["price"])

        except RobotError:
            raise

        except ParseError as e:
            echo.err("{}. Failed!", i)
            echo.err(e.body)
            echo.exception(e)

    echo.out("Done with wishlist, {} total items", i)