Skip to content

Instantly share code, notes, and snippets.

@fission6
Created August 22, 2011 14:46
Show Gist options
  • Save fission6/1162537 to your computer and use it in GitHub Desktop.
Save fission6/1162537 to your computer and use it in GitHub Desktop.
HP Touchpad tracker
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