sniffingpickles / Auto-Amazon-Giveaways

Automated Amazon Giveaways using Python3 & Pyppeteer :gift: :snake:
6 stars 8 forks source link

Suggestion - Avoid opening giveaway pages that have already been entered #11

Open robbiepee opened 6 years ago

robbiepee commented 6 years ago

90% of the time I'm running the program it's just showing the "already entered giveaway in the database" and "all checks have been reached, moving on to the next giveaway" messages, because it's opening the same few giveaways in a loop. I'm not sure how the URL structure works, but I'm fairly sure new giveaways generate their own new URLs, so a simple fix would be not to go to any URL that has already been entered into the database, and if it runs out of new giveaways, sleep until a new one is posted - that might even result in a higher win rate for first-come-first-serve giveaways. Unfortunately I've only just started learning Python, so I don't have a suggestion for how to accomplish that

sniffingpickles commented 6 years ago

That was a better idea, but i'm really new to python and couldn't figure out how to do a check on the enumerated pages, versus just return False if it's already in the database when it checks the page.

robbiepee commented 6 years ago

I probably am not the person to ask, but following logic from other languages it should be possible to, before checking the page, lookup in the database to see if the URL already exists, and if it does, skip it.

How I'd do it would be to have a temporary variable that stores the name of the next page it wants to go to, and before running the page check, have a lookup action check the database for the string contained in that variable. Then, have an if statement of, like, "if found (run whatever code you use to check the page), else (code to generate a new page/skip current page)"

On a somewhat related note, occasionally Amazon just logs out of my account for no reason and it breaks the script so I need to restart that instance of command prompt to restart the script. Any idea how to avoid this?

dziban303 commented 6 years ago

As a workaround, I have it set to open a random giveaway page, so there's less chance of getting a page full of giveaways you've already entered. You can uncomment #RANDOM_PAGE = list(range(1,100)) at the top of giveaway.py, and change line 71 from

await login_page.goto('https://www.amazon.com/ga/giveaways')

to

await login_page.goto('https://www.amazon.com/ga/giveaways?pageId=' + str(numpy.random.choice(RANDOM_PAGE)))

robbiepee commented 6 years ago

This is a temporary fix, correct? Looking through the code there's already a lookup action to see if the URL is already in the database, I think it'd be fairly simple to add an "if len(result) == 1 ↵ (however one would write "skip (def visit_page(url))" in python, or the script it already uses to move on to the next giveaway if the requirements have already been met)" statement. I understand that random pages is a simple workaround, but skipping any giveaways that have already been entered would increase the efficiency a ton, and likely increase winrate too

dziban303 commented 6 years ago

Despite your earlier statements about knowing very little python, I suspect you know more than I do. I'm afraid doing anything other than extremely basic bandaids is beyond me at the moment. 🚫👞🐍