Created
September 1, 2010 00:06
-
-
Save chmouel/560005 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff -uw -L /rsyncc:chmouel@acer:/home/chmouel/.xbmc/addons/script.tv.show.next.aired/resources/lib/scraper.py.order-by -L /rsyncc:chmouel@acer:/home/chmouel/.xbmc/addons/script.tv.show.next.aired/resources/lib/scraper.py /tmp/tramp.10818XFG.order-by /tmp/tramp.10818kPM.py | |
--- script.tv.show.next.aired/resources/lib/scraper.py~ | |
+++ script.tv.show.next.aired/resources/lib/scraper.py | |
@@ -9,10 +9,12 @@ | |
import xbmc | |
import xbmcgui | |
import time | |
+import datetime | |
SOURCEPATH = os.getcwd() | |
DATA_PATH = xbmc.translatePath( "special://profile/addon_data/script.tv.show.next.aired/") | |
+CACHE_HOURS=24 | |
RESOURCES_PATH = os.path.join( SOURCEPATH , "resources" ) | |
CACHE_PATH = os.path.join( DATA_PATH , "cache" ) | |
IMAGES_PATH = os.path.join( DATA_PATH , "images" ) | |
@@ -33,13 +35,23 @@ | |
us = ["January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday"] | |
+def expired(cache_file, cache_hours=24): | |
+ timestamp_cache_file=os.stat(cache_file).st_mtime | |
+ paste_date=datetime.datetime.now() - datetime.timedelta(hours=24) | |
+ timestamp_paste_date=time.mktime(paste_date.timetuple()) | |
+ return timestamp_paste_date > timestamp_cache_file | |
def get_html_source( url , save=False): | |
""" fetch the html source """ | |
+ cache_file=os.path.join( CACHE_PATH , save ) | |
class AppURLopener(urllib.FancyURLopener): | |
version = __useragent__ | |
urllib._urlopener = AppURLopener() | |
succeed = 0 | |
+ | |
+ if os.path.exists(cache_file) and not expired(cache_file, cache_hours=CACHE_HOURS): | |
+ return file( cache_file, "r").read() | |
+ | |
while succeed <= 5: | |
try: | |
if os.path.isfile( url ): sock = open( url, "r" ) | |
@@ -48,7 +60,7 @@ | |
sock = urllib.urlopen( url ) | |
htmlsource = sock.read() | |
- if save: file( os.path.join( CACHE_PATH , save ) , "w" ).write( htmlsource ) | |
+ if save: file( cache_file , "w" ).write( htmlsource ) | |
sock.close() | |
succeed = 5 | |
return htmlsource | |
@@ -83,7 +95,7 @@ | |
def listing(): | |
# sql statement for tv shows | |
- sql_data = "select tvshow.c00 , path.strPath from tvshow , path , tvshowlinkpath where path.idPath = tvshowlinkpath.idPath AND tvshow.idShow = tvshowlinkpath.idShow" | |
+ sql_data = "select tvshow.c00 , path.strPath from tvshow , path , tvshowlinkpath where path.idPath = tvshowlinkpath.idPath AND tvshow.idShow = tvshowlinkpath.idShow order by tvshow.c00" | |
xml_data = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % urllib.quote_plus( sql_data ), ) | |
match = re.findall( "<field>(.*?)</field><field>(.*?)</field>", xml_data, re.DOTALL ) | |
@@ -108,7 +120,8 @@ | |
# get info for show with exact name | |
print "### searching for %s" % search_name | |
print "###search url: http://services.tvrage.com/tools/quickinfo.php?show=%s" % urllib.quote_plus( search_name ) #DEBUG | |
- result_info = get_html_source( "http://services.tvrage.com/tools/quickinfo.php?show=%s" % urllib.quote_plus( search_name)) | |
+ save_name="%s.info" % search_name | |
+ result_info = get_html_source( "http://services.tvrage.com/tools/quickinfo.php?show=%s" % urllib.quote_plus( search_name), save=save_name) | |
print "### parse informations" | |
#print dict( re.findall( "(?m)(.*)@(.*)", result_info.strip( "<pre>\n" ) ) ) | |
#print "-"*100 | |
Diff finished. Wed Sep 1 01:06:05 2010 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment