def get_groups(ui): backsave = get_uibs(ui) if (not backsave is False) and backsave['date'] + 18000 > time.time(): groups = backsave['groups'] print u'took groups from backsave' else: groups = vk.method('groups.get', {'user_id': ui, 'count': 1000, 'extended': 1}) add_uibs(ui, groups) return groups
def load_user_posts(vk, ui): try: posts = vk.method('wall.get', { 'owner_id': ui, 'count': '20', 'filter': 'owner' })['items'] except vk_api.ApiError: posts = [] return posts
def load_users(vk, group_id, count, offset, sort='id_asc'): # sort = id_desc users = [] for n in range((count / 1000) + 1): user_ids = vk.method( 'groups.getMembers', { 'count': str(count - n * 1000), 'group_id': group_id, 'offset': offset + n * 1000, 'sort': sort })['items'] if len(user_ids) == 0: return users user_ids = [str(ui) for ui in user_ids] users_str = ','.join(user_ids) users += vk.method('users.get', { 'user_ids': users_str, 'fields': 'connections,status,sex,city' }) return users
def api(): li, final = load_wall_photos()[:10], [] s = ",".join([str(n['signer_id']) for n in li]) users = vkuser.method("users.get", {'user_ids': s}) #return jsonify({"resp": users, "resp2": li}) for n in li: n['name'] = "" for u in users: if n['signer_id'] == u['id']: n['name'] = u['first_name'] + u" " + u['last_name'] if not n['link'] in [f['link'] for f in final]: final.append(n) answer = jsonify({"resp": final}) answer.headers['Access-Control-Allow-Origin'] = '*' return answer
def get_uvideo_lemmas(ui): backsave = get_uibs(ui) if (not backsave is False) and backsave['date'] + 1800 > time.time(): text = backsave['videos'] print u'took videos from backsave' else: videos = vk.method('video.get', { 'owner_id': ui, 'count': 200 })['items'] text = u'' for video in videos: text += video['title'] + u' ' + video['description'] + u' ' add_uibs(ui, text) return get_imps(text)
def get_comments(): #exampling return [{u'date': 1511092576, u'text': u'all\nXL', u'id': 9, u'from_id': 163663706},\ # {u'date': 1511208089, u'text': u'all', u'id': 10, u'from_id': 337409123}] n, le, li = 0, 100, [] while le == 100: resp = vk.method( 'board.getComments', { 'count': 100, 'topic_id': topic_id, 'group_id': group_id, 'offset': 1 + n * 100 }) li += resp['items'] n += 1 le = len(resp['items']) return li
def load_last_photos(): limit = 40000 li = [] photos = vk.method( 'photos.get', { 'count': 10, 'owner_id': toptovar, 'album_id': album, 'offset': 0, 'rev': 1 })['items'] for photo in photos: if time.time() - photo['date'] > limit: return li else: li.append(photo) return li
def load_wall_photos(): wall = vkuser.method("wall.get", {"owner_id": toptovar, "count": 100,\ "filter": "owner", "offset": 1})['items'] wall_photos = [] for n in wall: descs = get_post_descs(n['text'], len(n.get("attachments", []))) if len(descs) == 1: n["attachments"] = n.get("attachments", [])[:1] for step, p in enumerate(n.get("attachments", [])): if p['type'] == 'photo': obj = p['photo'] obj['text'] += u" " + descs[step] #obj['signer_id'] = n.get('signer_id', '') obj['link'] = 'wall{}_{}'.format(str(n['owner_id']), str(n['id'])) wall_photos.append(obj) return wall_photos
def get_daily_usernots(ui): photos = vkuser.method( 'photos.get', { 'count': 100, 'owner_id': toptovar, 'album_id': album, 'offset': 0, 'rev': 1 })['items'] good = [] for p in photos: if ui in get_waiters_many(p): good.append(p) posts = good[:5] ats = ",".join([get_at(n) for n in posts]) text = "" for post in posts: text += u'vk.com/photo{}_{} {}\n\n'.format(str(post['owner_id']), str(post['id']), get_price(post['text'])) return text, ats
def load_photos(text, count=6, splitter=" "): items, n = [], 0 tli = text.rsplit(splitter, 1) for p in load_wall_photos(): print p['link'] if key_in_text(tli[0], p['text']) and \ good_size(tli[1], p['text'], False) and \ len(items) < count: items.append(p) while len(items) < count and n < count: photos = vkuser.method('photos.getAll', {'count': 200, 'owner_id': toptovar, \ 'offset': n*200, 'rev': 1})['items'] for p in photos: if p['album_id'] != 242356583 and p['album_id'] != 221657593: if key_in_text(tli[0], p['text']) and \ good_size(tli[1], p['text'], False): p['link'] = 'photo{}_{}'.format(str(p['owner_id']), str(p['id'])) items.append(p) n += 1 return items
def load_group_id(vk, link): screen_name = link.rsplit('/')[-1] return vk.method("groups.getById", {"group_ids": screen_name})[0]['id']