Skip to content

Instantly share code, notes, and snippets.

/truman.py Secret

Created September 15, 2015 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/20ea5c7077ae905ca079 to your computer and use it in GitHub Desktop.
Save anonymous/20ea5c7077ae905ca079 to your computer and use it in GitHub Desktop.
scrapes truman boots site for new releases
#!/usr/bin/env python
import requests
import os
import time
import sys
import signal
from urlparse import urljoin
import re
from bs4 import BeautifulSoup
# from IPython import embed
ROOT_URL = 'http://www.trumanboot.com/'
THE_URL = 'http://www.trumanboot.com/?post_type=product'
def anything_new(links):
all_urls = ''.join(links)
return hash(all_urls) != -817609967207271490
def is_available():
r = requests.get(THE_URL)
soup = BeautifulSoup(r.content, 'html.parser')
anchors = soup.select('li > div > h3 > a:nth-of-type(1)')
links = map(lambda lnk: urljoin(ROOT_URL, lnk.get('href')), anchors)
return not anything_new(links)
def send_email():
os.system('echo "New Truman boots in stock" | mail -s "Alert" 5551234567@tmomail.net')
os.system('echo "New Truman in stock" | mail -s "Alert" example@example.com')
def main():
while True:
if is_available():
send_email()
return 0
else:
time.sleep(600)
def daemonize():
# remove process from session
if os.fork() > 0:
sys.exit(0)
os.setsid()
os.umask(0)
if os.fork() > 0:
sys.exit(0)
# redirect stdin, stdout, and stderr to /dev/null
fd = os.open('/dev/null', os.O_RDWR)
os.dup2(fd, 0)
os.dup2(fd, 1)
os.dup2(fd, 2)
# ignore SIGHUP
signal.signal(signal.SIGHUP, signal.SIG_IGN)
with open('truman.pid', 'w') as f:
f.write(str(os.getpid()) + "\n")
if __name__ == '__main__':
daemonize()
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment