def scrape_wish_list_items(list_id):
    """ Populate wish_list_items with data from wishlist """
    print "Scraping wishlist..."

    wish = Wishlist(list_id)
    item_ids = wish.get_list_items()

    wishlist_items = []

    api = API(locale='us')
    for item_id in item_ids:
        try:
            result = api.item_lookup(item_id, ResponseGroup="Large")
            for item in result.Items.Item:
                itm = {
                    "title": item.ItemAttributes.Title,
                    "price":
                    item.Offers.Offer.OfferListing.Price.FormattedPrice,
                    "amazonid": item.ASIN
                }
                wishlist_items.append(itm)
        except:
            print "!!! Failed getting " + item_id

    print "Completed scraping."
    return wishlist_items
    def create_tables(self):
        c = self.conn.cursor()
        Wishlist.create_table(c)
        Item.create_table(c)

        for wishlist in self.wishlists.itervalues():
            wishlist.insert_into_table(c)

        self.conn.commit()
Example #3
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)
def scrape_wish_list_items(list_id):
    """ Populate wish_list_items with data from wishlist """
    print "Scraping wishlist..."

    wish = Wishlist(list_id)
    item_ids = wish.get_list_items()

    wishlist_items = []

    api = API(locale='us')
    for item_id in item_ids:
        try:
            result = api.item_lookup(item_id, ResponseGroup="Large")
            for item in result.Items.Item:
                itm = { "title": item.ItemAttributes.Title, "price": item.Offers.Offer.OfferListing.Price.FormattedPrice, "amazonid": item.ASIN }
                wishlist_items.append(itm)
        except:
            print "!!! Failed getting " + item_id

    print "Completed scraping."
    return wishlist_items
 def __init__(self, cmdargs, out):
     self.out = out
     self.cmdargs = cmdargs
     # get the amazon credentials
     config = SafeConfigParser()
     config.read(self.cmdargs.path_to_ini)
     self.AWS_ACCESS_KEY_ID = config.get('Credentials', 'AWS_ACCESS_KEY_ID')
     self.AWS_SECRET_ACCESS_KEY = config.get('Credentials', 'AWS_SECRET_ACCESS_KEY')
     self.AMAZON_TRACKING_ID = config.get('Credentials', 'AMAZON_TRACKING_ID')
     self.amazon = AmazonAPI(self.AWS_ACCESS_KEY_ID, self.AWS_SECRET_ACCESS_KEY, self.AMAZON_TRACKING_ID)
     wishlists = [Wishlist.from_url(name, url) for (name, url) in config.items('wishlist-urls')]
     self.wishlists = dict([(wishlist.wishlist_id, wishlist) for wishlist in wishlists])
     self.conn = sqlite3.connect(self.cmdargs.path_to_db)
     self.batch_limit = config.getint('amazon', 'batch-limit')
     self.create_tables()
Example #6
0
def home():
    wishlist = Wishlist()
    items = wishlist.get_list()
    for item in items:
        items = wishlist.total_count()
        types = wishlist.total_type()
    total = wishlist.total_cost()
    if request.method == 'POST':
        name = request.form['name']
        quantity = request.form['quantity']
        price = request.form['price']
        if name and quantity and price:
            wishlist.write_csv(name, quantity, price)
        else:
            flash('Please fill in all forms!')
    else:
        pass
    return render_template('index.html', type_item=types, num_item=items, total=total)
Example #7
0
from wishlist import Wishlist
from trade import Trade
from images import Images

intents = discord.Intents.default()
intents.members = True

load_dotenv()
BOT_TOKEN = os.getenv('BOT_TOKEN')
bot = commands.Bot(command_prefix='*', intents=intents)

bot.add_cog(Roll(bot))
bot.add_cog(Admin(bot))
bot.add_cog(Profile(bot))
bot.add_cog(Information(bot))
bot.add_cog(Wishlist(bot))
bot.add_cog(Trade(bot))
bot.add_cog(Images(bot))

#### Bot commands ####


@bot.command()
async def ping(ctx):
    await ctx.message.delete()
    await ctx.send('Yup, I\'m awake.', delete_after=5)


#### Bot event handlers ####

Example #8
0
from flask import Flask, request
from flask_socketio import SocketIO, send
from wishlist import Wishlist
import json

app = Flask(__name__)
socketio = SocketIO(app)
wishlist = Wishlist()

# Request handler


def send_response(response, sid):
    print 'sending {}'.format(response)
    send(response, json=True, room=sid)


def process_request(request, sid):
    try:
        data = json.loads(request)
        method = data['method']
        args = data['args']

        print 'calling {} with {}'.format(method, args)

        result = getattr(wishlist, method)(*args)
        send_response({'result': result}, sid)
    except Exception as e:
        send_response({'error': {
            'name': type(e).__name__,
            'args': e.args
Example #9
0
def view():
    wishlist = Wishlist()
    items = wishlist.get_list()
    return render_template('view.html', items=items)
Example #10
0
 def setUpClass(self):
     self.wishlist = Wishlist()
Example #11
0
class WishlistTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.wishlist = Wishlist()

    @classmethod
    def tearDownClass(self):
        self.wishlist.items.drop_table()
        self.wishlist.links.drop_table()
        self.wishlist.reservations.drop_table()

    def test_item(self):
        links = [{
            'title': 'Link 1',
            'href': 'website.com'
        }, {
            'title': 'Link 2',
            'href': 'internet.com'
        }]
        id = self.wishlist.add_item('Item 1', 'An item', 'imagedata', links, 1)
        self.assertNotEqual(id, None)

        rows = self.wishlist.get_items()
        result = rows[0]

        self.assertEqual(len(rows), 1)
        self.assertEqual(result['id'], id)
        self.assertEqual(result['name'], 'Item 1')
        self.assertEqual(result['description'], 'An item')
        self.assertEqual(result['image'], 'imagedata')
        self.assertEqual(len(result['links']), 2)
        self.assertEqual(result['max_reservations'], 1)

        def add_reservations():
            self.wishlist.add_reservation(id, 2)

        self.assertRaises(WishlistError, add_reservations)

        self.wishlist.add_reservation(id, 1)
        reserved = self.wishlist.get_reservations(id)

        self.assertEqual(reserved, 1)

        self.wishlist.remove_reservation(id, 1)
        reserved = self.wishlist.get_reservations(id)

        self.assertEqual(reserved, 0)

        self.wishlist.remove_reservation(id, 1)
        reserved = self.wishlist.get_reservations(id)

        self.assertEqual(reserved, 0)