#-------------------------------------------------------------------------------

# Name: PebbleChecker

# Purpose: Periodically check the Pebble Time Kickstarter page to see if

# there's a free spot on the 159$ pledge!

#

# Author: Marco Pontello - http://mark0.net

#

# Created: 02/03/2015

# Copyright: (c) 2015 Marco Pontello

# License: The MIT License (MIT) - http://opensource.org/licenses/MIT

#-------------------------------------------------------------------------------

#!/usr/bin/env python

import urllib

import time

import os

import random

import webbrowser

KSURL = "http://www.kickstarter.com/projects/597507018/pebble-time-awesome-smartwatch-no-compromises"

JUMPURL = "https://www.kickstarter.com/projects/597507018/pebble-time-awesome-smartwatch-no-compromises/pledge/edit?ref=manage_pledge"

DEBUG = False

def log ( text ) :

"""Simple logging."""

f = open ( "pebblechecker.log" , "a" )

text = time . strftime ( "%d/%m/%Y %H:%M:%S" , time . gmtime ( ) ) + " " + text + "

"

f. write ( text )

f. close ( )

def download_page ( url ) :

"""Retrive a webpage."""

try :

u = urllib . urlopen ( url )

page = u. read ( )

u. close

except :

log ( "* error: unable to download " + url )

return ""

return page

def beeep ( ) :

while True :

print " \a "

time . sleep ( 1 )

def main ( ) :

while True :

if DEBUG == True :

log ( " Read page." )

print "Reading page from disk..."

f = open ( "kspage.html" , "rb" )

page = f. read ( )

f. close

else :

log ( " Download page." )

print "Downloading page..."

page = download_page ( KSURL )

# search

page = page [ page. index ( "Pledge $159 or more" ) : ]

page = page [ :page. index ( "Ships anywhere in the world" ) ]

if page. find ( "All gone!" ) < 0 :

log ( "! Available!!!!!!!!!!!!" )

webbrowser . open ( JUMPURL )

beeep ( )

else :

log ( " nothing left!" )

# pause & restart

secs = random . randint ( 10 , 30 )

print "Waiting %i seconds..." % ( secs )

time . sleep ( secs )

if __name__ == "__main__" :