Esempio n. 1
0
def main(options, args):
    """ main driver for playlist annotation generator """

    user_path = "~"
    if args:
        user_path = args[0]

    if options.verbose:
        print "user path", user_path

    # discover the catalog and save it if the option is set
    if options.discover:
        if options.verbose:
            print "Searching home directory for music files"
        catalog = music_catalog.get_catalog(verbose=options.verbose,
                                            path=user_path)
        catalog.discover()
        catalog.save()
        return 0

    # save the default config if requested
    if options.config:
        if options.verbose:
            print "Saving default configuration"
        conf = config.get_config(user_path)
        conf.save()
        return 0

    # load information for user from config file
    conf = config.get_config(user_path)
    data_path = conf.getKey(config.DATA_PATH)
    music_index = conf.getKey(config.MUSIC_INDEX)
    template = conf.getKey(config.TEMPLATE)
    player_location = conf.getKey(config.PLAYER_LOCATION)
    music_path = conf.getKey(config.MUSIC_PATH)
    (weather_provider,
     weather_rss) = conf.getKey(config.WEATHER_PROVIDER).split(",", 1)
    (news_provider, news_rss) = conf.getKey(config.NEWS_PROVIDER).split(",", 1)
    (calendar_provider,
     calendar_path) = conf.getKey(config.CALENDAR_PROVIDER).split(",", 1)
    web_root = conf.getKey(config.WEB_ROOT)
    web_server = conf.getKey(config.WEB_SERVER)
    web_sync = conf.getKey(config.WEB_SYNC)

    my_radio = MyRadio(user_path, data_path, music_index, music_path,
                       weather_provider, weather_rss, news_provider, news_rss,
                       calendar_provider, calendar_path, options.verbose,
                       options.debug, options.filter, web_root, web_server,
                       web_sync, "julie")

    my_radio.produceShow(player_location, template, sync=options.sync)
    # save updated stats for this show
    get_profile(user_path).save()
    return 0
Esempio n. 2
0
 def exerptFeed( feedurl, content ):
     key = normalize(feedurl + datetime.date.today().isoformat())
     lines_used = get_profile(self.user_path).getKey(key)
     if lines_used == None:
         lines_used = 0
     else:
         lines_used = int(lines_used)
         
     newcontent = "\n".join(content.split("\n")[lines_used:lines_used+10])
     if not newcontent.strip():
         lines_used = 0
         newcontent = "\n".join(content.split("\n")[lines_used:lines_used+10])
         
     get_profile(self.user_path).setKey(key,str(lines_used+10))
     return newcontent
Esempio n. 3
0
 def uniqueChoice(context, intro_type):
     options = context[intro_type]
     key = context["contextid"] + "_" + intro_type
     previous = get_profile(self.user_path).getKey(key)
     if previous:
         used = eval(previous)
         if len(used) == len(options):
             used = set([])
     else:
         used = set([])
     choice = random.randint(0, len(options) - 1)
     while choice in used:
         choice = random.randint(0, len(options) - 1)
     used.add(choice)
     get_profile(self.user_path).setKey(key, str(used))
     return options[choice]
Esempio n. 4
0
 def uniqueChoice( context, intro_type ):
     options = context[intro_type]
     key = context["contextid"]+"_"+intro_type
     previous = get_profile(self.user_path).getKey(key)
     if previous:
         used = eval(previous)
         if len(used) == len(options):
             used = set([])
     else:
         used = set([])
     choice = random.randint(0,len(options)-1)
     while choice in used:
         choice = random.randint(0,len(options)-1)
     used.add(choice)
     get_profile(self.user_path).setKey(key,str(used))
     return options[choice]
Esempio n. 5
0
    def get_album_text(self, album_name, artist_name, debug=False):

        if not album_name:
            return []

        key = normalize("album_%s_%s_used_lines" %
                        (normalize(album_name), normalize(artist_name)))
        used_lines = get_profile(self.user_path).getKey(key)
        if used_lines == None:
            used_lines = 0
        else:
            used_lines = int(used_lines)

        paras = album.fetch_paragraphs(album_name, artist_name)
        if not paras:
            return []

        if debug:
            print "======== start album paras %s %s =========" % (artist_name,
                                                                  album_name)
            print paras
            print "======== start album paras %s %s =========" % (artist_name,
                                                                  album_name)

        sent = []
        for (s, p) in paras:
            for l in re.split("[\.\?\!]", p):
                l = l.strip()
                if l:
                    sent.append(l)

        wc = 0
        idx = 0
        for k in sent[used_lines:]:
            wc = wc + len(k.split())
            if wc >= 60:
                break
            idx = idx + 1

        get_profile(self.user_path).setKey(key, str(used_lines + idx))
        if debug:
            print "+++++++++++++ start selected album lines %s %s ++++++++++++" % (
                artist_name, album_name)
            print sent[used_lines:used_lines + idx]
            print "+++++++++++++ end selected album lines %s %s ++++++++++++" % (
                artist_name, album_name)
        return sent[used_lines:used_lines + idx]
Esempio n. 6
0
        def exerptFeed(feedurl, content):
            key = normalize(feedurl + datetime.date.today().isoformat())
            lines_used = get_profile(self.user_path).getKey(key)
            if lines_used == None:
                lines_used = 0
            else:
                lines_used = int(lines_used)

            newcontent = "\n".join(
                content.split("\n")[lines_used:lines_used + 10])
            if not newcontent.strip():
                lines_used = 0
                newcontent = "\n".join(
                    content.split("\n")[lines_used:lines_used + 10])

            get_profile(self.user_path).setKey(key, str(lines_used + 10))
            return newcontent
Esempio n. 7
0
 def get_artist_text( self, artist_name, debug = False ):
 
     if not artist_name:
         return []
 
     key = normalize("artist_%s_used_lines"%(normalize(artist_name)))
     used_lines = get_profile(self.user_path).getKey(key)
     if used_lines == None:
         used_lines = 0
     else:
         used_lines = int(used_lines)
 
     paras = artist.fetch_paragraphs( artist_name )
     if debug:
         print "======== start artist paras %s ========="%(artist_name)
         print paras
         print "======== start artist paras %s ========="%(artist_name)
 
     if not paras:
         return []
 
     sent = []
     for (s,p) in paras:
         for l in re.split("[\.\?\!]",p):
             l = l.strip()
             if l:
                 sent.append(l)
 
     wc = 0
     idx = 0
     for k in sent[used_lines:]:
         wc = wc + len(k.split())
         if wc >= 60:
             break
         idx = idx + 1
 
 
     get_profile(self.user_path).setKey(key,str(used_lines+idx))
 
     if debug:
         print "+++++++++++++ start selected artist lines %s ++++++++++++"%(artist_name)
         print sent[used_lines:used_lines+idx]
         print "+++++++++++++ end selected artist lines %s ++++++++++++"%(artist_name)
     return sent[used_lines:used_lines+idx]
Esempio n. 8
0
async def run(ctx, key: str) -> None:
    if ctx.channel.id not in config.get_channels():
        await ctx.channel.send('Not authorised to run in this channel!')
        return

    profile = config.get_profile(key)

    if profile is None:
        await ctx.channel.send(f'Unknown profile `{key}`')
        return

    profile.run()
    await ctx.channel.send(f'Running profile `{key}`')
Esempio n. 9
0
async def check(ctx, key: str) -> None:
    if ctx.channel.id not in config.get_channels():
        await ctx.channel.send('Not authorised to run in this channel!')
        return

    profile = config.get_profile(key)

    if profile is None:
        await ctx.channel.send(f'Unknown profile `{key}`')
        return

    if profile.running():
        await ctx.channel.send(f'`{key}` is running')
    else:
        await ctx.channel.send(f'`{key}` has stopped')
Esempio n. 10
0
async def kill(ctx, key: str) -> None:
    if ctx.channel.id not in config.get_channels():
        await ctx.channel.send('Not authorised to run in this channel!')
        return

    profile = config.get_profile(key)

    if profile is None:
        await ctx.channel.send(f'Unknown profile `{key}`')
        return

    if not profile.running():
        await ctx.channel.send(f'Profile `{key}` is already not running')
        return

    profile.kill()
    await ctx.channel.send(f'Killed `{key}`!')
Esempio n. 11
0
async def console(ctx, key: str, *args) -> None:
    if ctx.channel.id not in config.get_channels():
        await ctx.channel.send('Not authorised to run in this channel!')
        return

    profile = config.get_profile(key)

    if profile is None:
        await ctx.channel.send(f'Unknown profile `{key}`')
        return

    if not profile.running():
        await ctx.channel.send(f'Profile `{key}` is not running, start it with `?run`')
        return

    if not profile.console_allowed():
        await ctx.channel.send(f'Profile `{key}` does not allow console access')
        return

    profile.console(' '.join(args))
    await ctx.channel.send('Sent console input!')
Esempio n. 12
0
def main( options, args ):
    """ main driver for playlist annotation generator """
        
    user_path = "~"
    if args:
        user_path = args[0]

    if options.verbose:
        print "user path", user_path
        
    # discover the catalog and save it if the option is set
    if options.discover:
        if options.verbose:
            print "Searching home directory for music files"
        catalog = music_catalog.get_catalog(verbose=options.verbose,path=user_path)
        catalog.discover()
        catalog.save()
        return 0
        
    # save the default config if requested
    if options.config:
        if options.verbose:
            print "Saving default configuration"
        conf = config.get_config(user_path)
        conf.save()
        return 0
                                                 
    # load information for user from config file
    conf = config.get_config(user_path)
    data_path = conf.getKey(config.DATA_PATH)
    music_index = conf.getKey(config.MUSIC_INDEX)
    template = conf.getKey(config.TEMPLATE)
    player_location = conf.getKey(config.PLAYER_LOCATION)
    music_path = conf.getKey(config.MUSIC_PATH)           
    (weather_provider, weather_rss) = conf.getKey(config.WEATHER_PROVIDER).split(",",1)
    (news_provider, news_rss) = conf.getKey(config.NEWS_PROVIDER).split(",",1)
    (calendar_provider, calendar_path) = conf.getKey(config.CALENDAR_PROVIDER).split(",",1)
    web_root = conf.getKey(config.WEB_ROOT)
    web_server = conf.getKey(config.WEB_SERVER)
    web_sync = conf.getKey(config.WEB_SYNC)
    
    my_radio = MyRadio( user_path,
                        data_path,
                        music_index, 
                        music_path,
                        weather_provider,
                        weather_rss,
                        news_provider,
                        news_rss,
                        calendar_provider,
                        calendar_path,
                        options.verbose,
                        options.debug,
                        options.filter,
                        web_root,
                        web_server,
                        web_sync,
                        "julie" )
    
    
    my_radio.produceShow(player_location, template, sync= options.sync)
    # save updated stats for this show
    get_profile(user_path).save()
    return 0