def getStep(gid=GID, offset="0", step='10'): '''Служит для получения промежуточного списка документов. Запрашивает \'step\' штук.''' if gid[0]!='-': gid='-'+gid result=[] response= api.call("photos.getAll", {'owner_id': gid, 'count':step, 'offset':offset})[1:] for x in response: result.append([ x[u'text'], x[u'owner_id'], x[u'pid'] ]) return result
def getById(oid, did, gid=GID): '''Возвращает информацию о документе.''' if gid[0]=='-': gid=gid[1:] response=api.call("docs.get",{'oid':'-'+gid}) docs=[] for x in xrange(int(response[0])): if response[x+1][u'owner_id']==oid and response[x+1][u'did']==did: return response[x+1] return []
def upload(filename, aid=album1_500, gid=GID, caption="Загружено с помощью Nerd Library Manager."): '''Загружает фото в альбом группы''' print 'Загружается', basename(filename) if gid[0]=='-': gid=gid[1:] response=api.call("photos.getUploadServer", {'aid':aid,'gid':gid} ) f = open (filename) full_url=response['upload_url'] aid=response['upload_url'] #----------------------|Загрузка файла|--------------------- r = requests.post(url=full_url, data ={'title':'test_file'}, files={'file1':f} ) # print r.content photo=json.loads(r.content) #field file photo['caption']=caption response=api.call("photos.save", photo )[0] print response return [gid, response[u'pid']]
def upload_video(filename, name="", gid=NerdID, privacy_view=0, privacy_comment=0, description="", export_info=[]): '''Загружает видео в альбом группы, а также экспортирует необходимую информацию в export_info''' if name=="": name, ext=os.path.splitext(os.path.basename(filename)) response=api.call("video.save", {'name':name, 'gid':gid, 'privacy_view':privacy_view, 'privacy_comment':privacy_comment, 'description=':description}) export_info.append(str(response['vid'])) export_info.append(str(gid)) # Загрузка файла f = open (filename) return requests.post(url=response['upload_url'], data ={'title':'test_file'}, files={'video_file':f} )
def get(gid=GID): '''Возвращает вложенный список''' if gid[0]=='-': gid=gid[1:] response=api.call("docs.get",{'oid':'-'+gid}) docs=[] try: for x in xrange(int(response[0])): docs.append([response[x+1][u'title'] , response[x+1][u'owner_id'], response[x+1][u'did']]) except: print "Сервер выдал ошибку", response return docs
def upload(filename, gid=GID): '''Загружает документ в личные документы пользователя''' print "Загружаю ", filename if filename.find(tmp_path)==-1: filename=tmp_path+filename if gid[0]=='-': gid=gid[1:] response=api.call("docs.getUploadServer", {'gid':gid}) f = open (filename) full_url=response['upload_url'] #----------------------|Загрузка файла|--------------------- r = requests.post(url=full_url, data ={'title':'test_file'}, files={'file':f} ) # print r.content try: fFile=json.loads(r.content) #field file # print fFile['file'] rs=api.call("docs.save", {'file': fFile['file']}) print "Вроде файл загрузился :)" return 'http://vk.com/doc'+str(rs[0][u'owner_id'])+'_'+str(rs[0][u'did']) except: print "Сервер выдал ошибку:", r.content
def getAmount(gid=GID): '''Возвращает количество фотографий в группе в целом или в альбоме.''' if gid[0]=='-': gid=gid[1:] return int(api.call("photos.getAll", {'owner_id':'-'+gid, 'count': '1'})[0])
def Get(key='0', glob='1'): return api.call("storage.get", {'key':key, 'global':glob})
def Set(key='0', value='None',glob='1'): #glob=global key=str(key) return api.call("storage.set", {'key':key, 'global':glob, 'value':value})
def getAmount(gid=GID): '''Возврщащает количество документов''' if gid[0]=='-': gid=gid[1:] return int(api.call("docs.get", {'oid':'-'+gid})[0])
def rename(vid, oid, name="Default", desc="Загружено с помощью Nerd Library Manager."): #print "video",oid,vid return api.call("video.edit",{'vid':vid,'oid':oid,'name':name,'desc':desc})
def get(): return api.call("pages.getTitles", {'gid': GID})
def save(title='untitled', gid=GID, text="This is page"): pid=api.call("pages.save", {'gid': gid, 'Text': text, 'title':title}) api.call("pages.save", {'gid': gid, 'Text': text, 'pid':pid}) api.call("pages.saveAccess", {'pid':pid, 'gid': gid, 'view':'2' , 'edit': '0'}) return 'http://vk.com/page-'+gid+'_'+str(pid)