Created
February 27, 2016 02:13
-
-
Save jonowar/6596b404041942ad98d1 to your computer and use it in GitHub Desktop.
Quickie little script to watch a webpage for changes (when Beach House tix go on sale)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""pagetracker.py: Looks at a webpage and creates an OSX notification if a pattern is not found on the page. | |
Requirements: | |
pip install requests | |
pip install beautifulsoup4 | |
pip install pync | |
Try running it like this: | |
while :; do | |
clear | |
date | |
./pagetracker.py | |
sleep 5 | |
done | |
""" | |
__author__ = "Jono Warren, https://github.com/jonowar" | |
import re | |
import requests | |
from bs4 import BeautifulSoup | |
from pync import Notifier | |
def track(url, pattern, notification): | |
""" | |
Open a url and search the text for a pattern. | |
If it's not found, notify us! | |
""" | |
req = requests.get(url) | |
soup = BeautifulSoup(req.text, "html.parser") | |
if not re.search(pattern, soup.get_text()): | |
print '"{pattern}" not found on {url}!!!'.format( | |
pattern=pattern, | |
url=url, | |
) | |
Notifier.notify(notification, open=url) | |
else: | |
print '"{pattern}" still found on {url}'.format( | |
pattern=pattern, | |
url=url, | |
) | |
if __name__ == "__main__": | |
track(url="http://www.beachhousebaltimore.com/installation/", | |
pattern="San Francisco.*TBA", | |
notification="BEACH HOUSE TICKETS ON SALE!!!" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment