Esempio n. 1
0
def DeadFish(c):
    subgroup_data = next(sg for sg in d.available_subgroups if sg['subgroup'] == 'DeadFish')
    if not subgroup_data:
        print("None Found")
    #user_id = '64513'
    user_id = subgroup_data['nyaa_id']
    title_regex = subgroup_data['regex']['title']
    quality_regex = subgroup_data['regex']['quality']
    #title_regex = r'(?<=\[HorribleSubs\] ).*(?= \- \d{2,3} \[)'
    #quality_regex = r'(?<=\[)\d*p(?=\])'
    param = {}
    anime_list = []
    i = 1
    input_title = input('Anime name: ').replace(' ', '+')
    
    # Used to query all pages from RSS feed.
    while True:
        results = feedparser.parse(utils.get_rss_feed(input_title, user_id, i))
        i = i + 1
        if not results['entries']:
            break
        for hit in results['entries']:
            try:
                parsed_title = re.search(title_regex, hit['title']).group(0)
                parsed_quality = re.search(quality_regex, hit['title']).group(0)
                
            except Exception as e:
                parsed_title = ''
                parsed_quality = ''
                pass
            
            title_found = False
            #optimize this
            if parsed_title:
                if anime_list:
                    for t in anime_list:
                        if t[0] == parsed_title and parsed_quality:
                            t[1].append(parsed_quality) if parsed_quality not in t[1] else None 
                            title_found = True
                if not title_found and parsed_quality:
                    anime_list.append((parsed_title, [parsed_quality]))
    if anime_list:
        print('Found titles: ')
        utils.selection(list([i[0] for i in anime_list]))
        #asks for input for title choice
        anime_selection = anime_list[utils.selector('Select the title: ', len(anime_list))]
        param['title'] = anime_selection[0]

        #asks for input for quality choice
        print('Available qualities: ')
        utils.selection(anime_selection[1])
        param['quality'] = anime_selection[1][utils.selector('Quality: ', len(anime_selection[1]))]
        
        try:
            c.execute("INSERT INTO DeadFish VALUES('%s', '%s');" %(param['title'].replace("'","''"), param['quality']))
        except Exception as e:
            print(e)

    else:
        print("No title found under %s" %input_title)
Esempio n. 2
0
def main():
    #get stuff stuff from configs

    DB_NAME, DB_USER = cfg.database_name, cfg.database_user
    try:
        connection = psycopg2.connect("dbname=%s user=%s" %(DB_NAME, DB_USER))
    except Exception as e:
        print(e)
    utils.init_tables()
    cursor = connection.cursor()
    #cursor.execute("SELECT * FROM subgroups;")
    available_groups = list(i['subgroup'] for i in d.available_subgroups)
    if not available_groups:
        print("No Subgroups configured")
        return False
    print("Subgroups available: ")
    utils.selection(available_groups)
    eval('subgroups.%s(cursor)' %available_groups[utils.selector('Select Subgroup: ', len(available_groups))])
    #subgroups.HorribleSubs(cursor)
    connection.commit()
    connection.close()