Example #1
0
def save_all_favs_for_user(username,
                           out_dir,
                           save_in_html=True,
                           with_comments=False,
                           save_by_name=False,
                           limit=None,
                           project='h'):
    filetype = 'pdf'
    if save_in_html:
        filetype = 'html'
    if project == 'g':
        hu = GeektimesUser(username, need_favorites=True)
    else:
        hu = HabraUser(username, need_favorites=True)
    favs_id = hu.favorites()
    deleted = list()
    if limit is not None:
        limit_cnt = int(limit)
    else:
        limit_cnt = -1
    for topic_name in favs_id:
        if limit_cnt == 0:
            break
        elif limit_cnt > 0:
            limit_cnt -= 1
        topic_id = favs_id[topic_name]
        print('Downloading "{}"...'.format(topic_name))
        if save_by_name:
            t_name = topic_name.replace('/', '_').replace('\\', '_').replace(
                '!', '.').replace(':', '.').replace(';', '.')
            if len(t_name) > 250:
                t_name = t_name[:250]
            filename = '{dir}/{name}.{filetype}'.format(dir=out_dir,
                                                        name=t_name,
                                                        filetype=filetype)
        else:
            filename = '{dir}/{id}.{filetype}'.format(dir=out_dir,
                                                      id=topic_id,
                                                      filetype=filetype)
        print('Saving it in "{}"'.format(filename))
        try:
            if save_in_html:
                save_html(topic_id,
                          filename,
                          with_comments=with_comments,
                          project=project)
            else:
                save_pdf(topic_id,
                         filename,
                         with_comments=with_comments,
                         project=project)
        except PostDeleted:
            print('Post {} is deleted!'.format(topic_id))
            deleted.append(topic_id)
    if len(deleted):
        print('All deleted posts: \n{}'.format('\n'.join(deleted)))
    pass
Example #2
0
def save_all_favs_for_user(
    username, out_dir, save_in_html=True, with_comments=False, save_by_name=False, limit=None, project="h"
):
    filetype = "pdf"
    if save_in_html:
        filetype = "html"
        # raise NotImplemented
    # hu = HabraUser(username, need_favorites=True)
    if project == "g":
        hu = GeektimesUser(username)
    elif project == "m":
        hu = MegamozgUser(username)
    else:
        hu = HabraUser(username)
    # hu = GeektimesUser(username) if project == 'g' else MegamozgUser(username) if project == 'm' else HabraUser(username)
    favs_id = hu.favorites()
    # print (favs_id)
    deleted = list()
    if limit is not None:
        limit_cnt = int(limit)
    else:
        limit_cnt = -1
    for topic_name in favs_id:
        if limit_cnt == 0:
            break
        elif limit_cnt > 0:
            limit_cnt -= 1
        topic_id = favs_id[topic_name]
        print('Downloading "{}"...'.format(topic_name))
        # topic = HabraTopic(topic_id)
        if save_by_name:
            t_name = (
                topic_name.replace("/", "_").replace("\\", "_").replace("!", ".").replace(":", ".").replace(";", ".")
            )
            if len(t_name) > 250:
                t_name = t_name[:250]
            filename = "{dir}/{name}.{filetype}".format(dir=out_dir, name=t_name, filetype=filetype)
        else:
            filename = "{dir}/{id}.{filetype}".format(dir=out_dir, id=topic_id, filetype=filetype)
        print('Saving it in "{}"'.format(filename))
        try:
            if save_in_html:
                html = save_html(topic_id, filename, with_comments=with_comments, project=project)
            else:
                save_pdf(topic_id, filename, with_comments=with_comments, project=project)
        except PostDeleted:
            print("Post {} is deleted!".format(topic_id))
            deleted.append(topic_id)
    if len(deleted):
        print("All deleted posts: \n{}".format("\n".join(deleted)))
    pass
Example #3
0
def create_url_list(username, filename, project='h'):
    '''
    Generates url list for favorites
    :param username:
    :param filename:
    :param project: one of 'h', 'g', 'm'
    :return:
    '''
    hu = GeektimesUser(username) if project == 'g' else MegamozgUser(username) if project == 'm' else HabraUser(username)
    T =  GeektimesTopic if project == 'g' else MegamozgTopic if project == 'm' else HabraTopic
    urls = list()
    favs_id = hu.favorites()
    for topic_name in favs_id:
        urls.append(T(favs_id[topic_name]).getTopicUrl())
    urls.sort()
    with open(filename, 'wt') as f:
        f.write('\n'.join(urls))
Example #4
0
def create_url_list(username, filename, project='h'):
    '''
    Generates url list for favorites
    :param username:
    :param filename:
    :param project: one of 'h', 'g', 'm'
    :return:
    '''
    hu = GeektimesUser(username) if project == 'g' else MegamozgUser(
        username) if project == 'm' else HabraUser(username)
    T = GeektimesTopic if project == 'g' else MegamozgTopic if project == 'm' else HabraTopic
    urls = list()
    favs_id = hu.favorites()
    for topic_name in favs_id:
        urls.append(T(favs_id[topic_name]).getTopicUrl())
    urls.sort()
    with open(filename, 'wt') as f:
        f.write('\n'.join(urls))
Example #5
0
def save_all_favs_for_user(username, out_dir, save_in_html=True, with_comments=False, save_by_name=False, limit=None,
                           project='h'):
    filetype = 'pdf'
    if save_in_html:
        filetype = 'html'
    if project == 'g':
        hu = GeektimesUser(username, need_favorites=True)
    else:
        hu = HabraUser(username, need_favorites=True)
    favs_id = hu.favorites()
    deleted = list()
    if limit is not None:
        limit_cnt = int(limit)
    else:
        limit_cnt = -1
    for topic_name in favs_id:
        if limit_cnt == 0:
            break
        elif limit_cnt > 0:
            limit_cnt -= 1
        topic_id = favs_id[topic_name]
        print('Downloading "{}"...'.format(topic_name))
        if save_by_name:
            t_name = topic_name.replace('/', '_').replace('\\', '_').replace('!', '.').replace(':', '.').replace(';',
                                                                                                                 '.')
            if len(t_name) > 250:
                t_name = t_name[:250]
            filename = '{dir}/{name}.{filetype}'.format(dir=out_dir, name=t_name, filetype=filetype)
        else:
            filename = '{dir}/{id}.{filetype}'.format(dir=out_dir, id=topic_id, filetype=filetype)
        print('Saving it in "{}"'.format(filename))
        try:
            if save_in_html:
                save_html(topic_id, filename, with_comments=with_comments, project=project)
            else:
                save_pdf(topic_id, filename, with_comments=with_comments, project=project)
        except PostDeleted:
            print('Post {} is deleted!'.format(topic_id))
            deleted.append(topic_id)
    if len(deleted):
        print('All deleted posts: \n{}'.format('\n'.join(deleted)))
    pass
Example #6
0
def create_url_list(username, filename, project='h'):
    '''
    Generates url list for favorites
    :param username:
    :param filename:
    :param project: one of 'h', 'g'
    :return:
    '''
    hu = GeektimesUser(username) if project == 'g' else HabraUser(username)
    T = GeektimesTopic if project == 'g' else HabraTopic
    urls = list()
    favs_id = hu.favorites()
    for topic_name in favs_id:
        try:
            urls.append(T(favs_id[topic_name]).getTopicUrl())
        except PostDeleted:
            print('Post {} is deleted!'.format(favs_id[topic_name]))
    urls.sort()
    with open(filename, 'wt') as f:
        f.write('\n'.join(urls))
Example #7
0
def create_url_list(username, filename, project='h'):
    '''
    Generates url list for favorites
    :param username:
    :param filename:
    :param project: one of 'h', 'g'
    :return:
    '''
    hu = GeektimesUser(username) if project == 'g' else HabraUser(username)
    T = GeektimesTopic if project == 'g' else HabraTopic
    urls = list()
    favs_id = hu.favorites()
    for topic_name in favs_id:
        try:
            urls.append(T(favs_id[topic_name]).getTopicUrl())
        except PostDeleted:
            print('Post {} is deleted!'.format(favs_id[topic_name]))
    urls.sort()
    with open(filename, 'wt') as f:
        f.write('\n'.join(urls))