def get_all_posts(group_id):
    all_posts = []
    group_id = get_group_id_by_url(group_id)
    if int(group_id) > 0:
        group_id = str(-int(group_id))
    posts_data_raw = call_api("wall.get", [("owner_id", group_id), ("count", 1)])
    count = 100
    offset = -count
    while offset + count < posts_data_raw[0]:
        offset += count
        posts_data_raw = call_api("wall.get", [("owner_id", group_id), ("count", count),
                                               ("offset", offset)])
        all_posts += posts_data_raw[1:]
    return all_posts
Exemple #2
0
def MusicList(token, uid):
    try:
        if checkConnection():
            return call_api('audio.get', [('uid', uid)], token)
        return ListFromDir(chachedir)
    except:
        return None
Exemple #3
0
def MusicList(token, uid):
    try:
        if checkConnection():
            return call_api('audio.get', [('uid', uid)], token)
        return ListFromDir(chachedir)
    except:
        return None
Exemple #4
0
 def GetMusicListFromUID(self, uid):
     token = self.user_params['token']
     try:
         if checkConnection():
             return call_api('audio.get', [('uid', uid)], token)
         return ListFromDir(self.chache_dir)
     except:
         return None
def get_postponed_posts_times_with_text(group_id):
    logging.debug("start getting postponed posts with text")
    group_id = get_group_id_by_url(group_id)
    postponed_posts_times_with_text = dict()
    if int(group_id) > 0:
        group_id = str(-int(group_id))
    posts_data_raw = call_api("wall.get", [("owner_id", group_id), ("filter", "postponed"), ("count", 1)], token)
    count = 100
    offset = -count
    while offset + count < posts_data_raw[0]:
        offset += count
        posts_data_raw = call_api("wall.get", [("owner_id", group_id), ("filter", "postponed"), ("count", count),
                                               ("offset", offset)], token)
        for post_data in posts_data_raw[1:]:
            postponed_posts_times_with_text[post_data["date"]] = post_data["text"]
    logging.debug("finish getting postponed posts with text")
    return postponed_posts_times_with_text
def get_user_id(username):
    username = username.split('/')[-1]
    try:
        result = call_api("users.get", [("user_ids", username)])
    except APIErrorException:
        raise InvalidUserIDError
    real_user_id = result[0]["uid"]
    return real_user_id
Exemple #7
0
 def GetMusicListFromUID(self, uid):
     token = self.user_params['token']
     try:
         if checkConnection():
             return call_api('audio.get', [('uid', uid)], token)
         return ListFromDir(self.chache_dir)
     except:
         return None
def get_all_posts(group_id):
    # date = {"year": 2015, "month": 12, day: 3 }
    logging.debug("start getting all posts")
    all_posts = []
    group_id = get_group_id_by_url(group_id)
    if int(group_id) > 0:
        group_id = str(-int(group_id))
    posts_data_raw = call_api("wall.get", [("owner_id", group_id), ("count", 1)], token)
    count = 100
    offset = -count
    while offset + count < 500: #posts_data_raw[0]:
        offset += count
        # print "offset = {}".format(offset)
        posts_data_raw = call_api("wall.get", [("owner_id", group_id), ("count", count),
                                               ("offset", offset)], token)
        all_posts += posts_data_raw[1:]
        date_last_post = system_api.date_from_epoch(posts_data_raw[-1]["date"])
    return all_posts
def get_name_by_id(user_id):
    user_id = str(abs(int(user_id)))
    response = call_api("users.get", [("user_ids", user_id)])
    try:
        result = response[0]["first_name"]+ " " + response[0]["last_name"]
    except IndexError:
        print user_id
        raise
    return result
def get_name_by_id(user_id):
    # if not str(user_id).isdigit():
    #     print "I'm here"
    #     return user_id
    user_id = str(abs(int(user_id)))
    response = call_api("users.get", [("user_ids", user_id)], token)
    try:
        result =  response[0]["first_name"]+ " " + response[0]["last_name"]
    except IndexError:
        print user_id
        raise
    return result
Exemple #11
0
def get_photos_urls(user_id, album_id, token):
    photos_list = call_api("photos.get", [("uid", user_id), ("aid", album_id)], token)
    result = []
    for photo in photos_list:
        #Choose photo with largest resolution
        if "src_xxbig" in photo:
            url = photo["src_xxbig"]
        elif "src_xbig" in photo:
            url = photo["src_xbig"]
        else:
            url = photo["src_big"]
        result.append(url)
    return result
def get_group_id_by_url(url2group):
    """
    >>> get_group_id_by_url("http://vk.com/team")
    22822305
    >>> get_group_id_by_url(22822305)
    22822305
    >>> get_group_id_by_url("22822305")
    22822305
    >>> get_group_id_by_url("vk.com/team")
    22822305
    """
    logging.debug("start get_group_id_by_url")
    if str(url2group).isdigit():
        return int(url2group)
    url2group = url2group.split('/')[-1]
    try:
        group_info = call_api("groups.getById", [("group_id", url2group)], token)
    except AccessTokenExpiredException:
        os.remove(config.vk_token_filename)
        group_info = call_api("groups.getById", [("group_id", url2group)], token)
    group_id = group_info[0]["gid"]
    return group_id
def upload_picture_to_group_from_hdd(group_id, picture_path, force=False):
    # picture_description = "blah"
    statinfo = os.stat(picture_path)
    # if not force and statinfo.st_size < config.small_picture_limit:
    #     return False
    group_id = get_group_id_by_url(group_id)
    if int(group_id) < 0:
        group_id = str(-int(group_id))
    answer = call_api("photos.getWallUploadServer", [("group_id", group_id)])

    album_id = answer["aid"]
    upload_url = answer["upload_url"]
    files = {'file': open(picture_path, 'rb')}
    r = requests.post(upload_url, files=files)

    photo_id = r.json()["photo"]
    photo_hash = r.json()["hash"]
    photo_server = r.json()["server"]
    result_uploading_photo = call_api("photos.saveWallPhoto", [("group_id", group_id),
                                                               ("photo", photo_id),
                                                               ("server", photo_server),
                                                               ("hash", photo_hash)])

    return result_uploading_photo[0]["id"]
def get_group_id_by_url(url2group):
    """
    >>> get_group_id_by_url("http://vk.com/team")
    22822305
    >>> get_group_id_by_url(22822305)
    22822305
    >>> get_group_id_by_url("22822305")
    22822305
    >>> get_group_id_by_url("vk.com/team")
    22822305
    """
    logging.debug("start get_group_id_by_url")
    if str(url2group).isdigit():
        return int(url2group)
    url2group = url2group.split('/')[-1]
    group_info = call_api("groups.getById", [("group_id", url2group)])

    group_id = group_info[0]["gid"]
    return group_id
Exemple #15
0
def FriendsList(token, uid):
    return call_api('friends.get', [('uid', uid), ('fields', 'first_name,last_name')], token)
Exemple #16
0
def get_albums(user_id, token):
    return call_api("photos.getAlbums", [("uid", user_id)], token)
Exemple #17
0
def MusicList(token, uid):
    return call_api('audio.get', [('uid', uid)], token)
Exemple #18
0
def MutualFriendsList(token, source_uid, target_uid):
    #print source_uid, target_uid
    return call_api('friends.getMutual', [('target_uid', target_uid), ('source_uid', source_uid)], token)