Created
August 22, 2011 14:46
-
-
Save fission6/1162537 to your computer and use it in GitHub Desktop.
HP Touchpad tracker
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
import urllib2 | |
from lxml import html | |
from time import sleep | |
from datetime import datetime | |
from subprocess import Popen | |
PRODUCT_URL = "http://www.shopping.hp.com/store/product/product_detail/FB355UA%2523ABA?jumpid=se_r1002_fp_usen_hho" | |
def check(): | |
""" | |
Check product url and look for 'Out of Stock' in the specified xpath. | |
If not found, then the product maybe in stock, so BEEP. | |
""" | |
time_check = datetime.now() | |
page = urllib2.urlopen(PRODUCT_URL).read() | |
tree = html.fromstring(page) | |
available = tree.xpath("//div//span[@class='error']/b")[0] | |
is_available = not available.text.lower() == 'out of stock' | |
if is_available: | |
print time_check, "Touchpad maybe available" | |
#Show a zenity popup | |
Popen("zenity --info --text 'HP Touchpad maybe available'", shell=True) | |
else: | |
print time_check, "Touch pad is not available" | |
def main(): | |
while True: | |
check() | |
sleep(120) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment