Skip to content

Instantly share code, notes, and snippets.

@jackbow
Last active May 1, 2019 17:42
Show Gist options
  • Save jackbow/1dcf1c60e35e1ce8adec83e745d42a4a to your computer and use it in GitHub Desktop.
Save jackbow/1dcf1c60e35e1ce8adec83e745d42a4a to your computer and use it in GitHub Desktop.
ebay_notif: This will send you push notifications when a given ebay search has an item within your given params (eg. price, condition, etc) is ending within 1 hr. I ran this for a couple weeks on my raspberrypi to find a posting for a laptop a couple hundred dollars cheaper than average.
# This will send you push notifications
# when a given ebay search has an item within
# your given params (eg. price, condition, etc)
# is ending within 1 hr
# just set this var to your search: (default is a test with freq. items)
page_url = "https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1311.R9.TR10.TRC3.A0.H0.Xmacbook.TRS2&_nkw=macbook+pro+2017&_sacat=0&LH_TitleDesc=0&_sop=1&_osacat=0&_odkw=macbook"
# Search for something on ebay, set filters, then list by Time: ending soonest
from bs4 import BeautifulSoup
import requests
from notify_run import Notify
import time
# https://notify.run -- notifications via webpush
notify = Notify()
print(notify.info())
time.sleep(30)
notify.send('Test notification')
while True:
try:
page_response = requests.get(page_url, timeout=5)#, headers=headers)
if page_response.status_code == 200:
page_content = BeautifulSoup(page_response.content, "html.parser")
remaining_times = page_content.find_all(class_='s-item__time-left')
if remaining_times[0].text[1] == 'd':
time.sleep(int(remaining_times[0].text[0]) * 60 * 60 * 23)
if remaining_times[0].text[1] == 'h':
delay = (int(remaining_times[0].text[0]) - 1) * 60 * 60
if delay == 0:
time.sleep(30 * 50)
else:
time.sleep(delay)
# if less than 1hr remaining:
if remaining_times[0].text[1] == 'm':
notify.send('Check ebay saved search')
time.sleep(30*60)
else:
print(page_response.status_code)
notify.send('Request status code error')
time.sleep(30*60)
except requests.Timeout as e:
notify.send("Request timeout error")
print(str(e))
time.sleep(30*30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment