This python script queries iTunes update url to see if iPhone OS 3.0 has been released for the iPhone 3G
import urllib2 | |
import re | |
from time import sleep | |
class PageScraper(object): | |
""" | |
This class scrapes a url for a string, can be used with a loop. | |
""" | |
def __init__(self, url, string=''): | |
self.url = url | |
self.string = string | |
self.page = '' | |
self.request = None | |
def pull(self): | |
""" | |
This method pull's the request and saves it as self.page. | |
""" | |
if self.request == None: | |
self.request = urllib2.Request(self.url) | |
try: | |
self.page = urllib2.urlopen(self.request).read() | |
except urllib2.HTTPError: | |
self.page = '' | |
def search(self): | |
""" | |
Search for a string in self.page. | |
""" | |
return self.string in self.page | |
def loop(self, delay=5.0): | |
""" | |
Loop until the string is found. | |
""" | |
while 1: | |
update.pull() | |
if update.search(): | |
return True | |
sleep(delay) | |
if __name__ == "__main__": | |
update = PageScraper('http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/com.apple.jingle.appserver.client.MZITunesClientCheck/version', 'iPhone1,2_3.0_7A341') | |
if update.loop(delay=10.0): | |
print 'iPhone 3G 3.0 Update found' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment