コード例 #1
0
ファイル: main.py プロジェクト: JoseOneTime/couchtuner
def init_shows_xml():
    """ Initialize shows.xml """
    shows_root = E('root')
    for key in sorted(SHOWS.keys()):
        try:
            show_pg = ShowPage(SHOWS[key]['url'])
            show = show_pg.to_xml()
            shows_root.append(show)
        except Timeout:
            pass
    shows_root.getroottree().write('shows.xml')
    s3 = boto.connect_s3()
    s3_bucket = s3.get_bucket('xtcouchtuner')
    s3_key = s3_bucket.get_key('shows.xml')
    s3_key.set_contents_from_filename('shows.xml')
    s3.close()
コード例 #2
0
ファイル: main.py プロジェクト: JoseOneTime/couchtuner
def go(showname=None, season=None):
    if showname:
        shows = [showname]
    else:
        shows = sorted(SHOWS.keys())
    chrome = start_chromedriver()
    s3 = boto.connect_s3()
    s3_bucket = s3.get_bucket('xtcouchtuner')
    try:
        for showname in shows:
            try:
                print 'Parsing %s...' % showname.title()
                p = ShowPage(SHOWS[showname.lower()]['url'])
                if season:
                    seasons = [season]
                else:
                    seasons = p.get_seasons()
                for s in seasons:
                    print 'Writing season %i...' % s,
                    p.write_season_file(s, chrome)
                    print 'Season %i local done...' % s,
                    s3_key = s3_bucket.get_key(p.get_s3_key_name(s))
                    if not s3_key:
                        s3_key = s3_bucket.new_key(p.get_s3_key_name(s))
                    s3_key.set_contents_from_filename(p.get_local_xml_file(s))
                    print 'S3 done'
                print
            except Timeout:
                pass
    except KeyboardInterrupt:
        print 'Well, I guess you\'ve got better things to do...'
    except:
        print_exc()
    finally:
        try:
            chrome.quit()
        except URLError:
            pass
        s3.close()