예제 #1
0
def download_users(age_from, age_to, city_id, downloaded_users_file):
    months = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30,
              7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
    downloaded_users_list = get_lists_from_file(downloaded_users_file)
    users_info_list = get_lists_from_file(users_info_file)
    for age in range(age_from, age_to+1):
        for month in months.keys():
            for day in range(1, months[month]+1):
                print('''processed: day = {}, month = {}, age = {}'''.format(day, month, age))
                while True:
                    users = Vk.get_uids(age, month, day, city_id)
                    if users:
                        break
                    Vk.get_token()
                need_to_write_users = list()
                for user in users:
                    if not check_in_file(user.uid, downloaded_users_list):
                        dir_of_photos = os.path.join(vk_dir, age.__str__())
                        get_profile_photos(user.uid, dir_of_photos, downloaded_users_file)
                    if check_in_file(user.uid, users_info_list):
                        print('We have this user in info too! ' + user.name + ' ' + user.last_name)
                    else:
                        print('added info ' + user.name + ' ' + user.last_name)
                        need_to_write_users.append(user)
                write_users_to_file(need_to_write_users, users_info_file)
예제 #2
0
def downloaded_friends(user_ids, dir_, deep=2):
    downloaded_users_file_friends = os.path.join(dir_, 'downloaded_users.txt')
    users_info_file_friends = os.path.join(dir_, 'user_info.txt')
    downloaded_users_list = get_lists_from_file(downloaded_users_file_friends)
    users_info_list = get_lists_from_file(users_info_file_friends)
    count = 0
    next_iter_uids = set()
    for uid in user_ids:
        count += 1
        if not check_in_file(uid, downloaded_users_list):
            get_profile_photos(uid, dir_, downloaded_users_file_friends)
        user = get_user_info_from_list(uid, users_info_list)
        if user is not None:
            print('We have this user in info too! ' + user.name + ' ' + user.last_name + ' (id ' +
                  user.uid.__str__() + '), ' + count.__str__() + '\\' + len(user_ids).__str__())
            user_friends_file = os.path.join(dir_, uid)
            user_friends_file = os.path.join(user_friends_file, 'friends.txt')
            users = get_users_from_file(user_friends_file)
        else:
            user = Vk.get_user_info(uid)
            if user is not None:
                print('added info ' + user.name + ' ' + user.last_name + ' (id ' + user.uid.__str__() + '), '
                      + count.__str__() + '\\' + len(user_ids).__str__())
                write_users_to_file([user], users_info_file_friends)
                for i in range(3):
                    users = Vk.get_friends(uid)
                    if users:
                        break
                    Vk.get_token()
                path_to_write = os.path.join(dir_, uid)
                path_to_write = os.path.join(path_to_write, 'friends.txt')
                write_users_in_file(path_to_write, users, open_mode='w')
        if deep > 0:
            next_iter_uids = next_iter_uids | set([user.uid for user in users])

    if next_iter_uids:
        downloaded_friends(next_iter_uids, dir_, deep-1)