Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- from Tkinter import BooleanVar
- from Tkinter import *
- from Tkinter import Toplevel
- from Tapiv2 import tuentiAPI
- '''from Gui import Gui'''
- import time
- import urllib2
- class Gui():
- def __init__(self,main):
- '''
- iButtons -> Botones que requieren inicio sesion
- phButtons -> Botones que requieren leer fotos
- '''
- self.buttons={'iButtons' : [], 'phButtons' : []}
- gf = LabelFrame(main, text = 'General', relief = RIDGE, labelanchor = 'nw', width = 300, height = 60)
- gf.grid(row = 0, column = 1)
- gf.grid_propagate(0)
- self.guiGeneral(gf,main)
- pf = LabelFrame(main, text = "Perfil", relief = GROOVE, labelanchor = 'nw',width = 300, height = 80)
- pf.grid(row = 2, column = 1)
- pf.grid_propagate(0)
- self.guiProfile(pf,main)
- phf = LabelFrame(main, text = 'Fotos', relief = RIDGE, labelanchor = 'nw', width = 300, height = 200)
- phf.grid(row = 1, column = 2)
- phf.grid_propagate(0)
- self.guiPhotos(phf,main)
- ''''''
- phf_status = LabelFrame(phf, relief = RIDGE, labelanchor = 'nw', width = 295 , height = 55)
- phf_status.grid(row = 3, column = 0)
- phf_status.grid_propagate(0)
- self.guiPhotosStatus(phf_status,main)
- mf = LabelFrame(main, text = "Mensajes", relief = GROOVE, labelanchor = 'nw',width = 480, height = 180)
- mf.grid(row = 1, column = 1)
- mf.grid_propagate(0)
- self.guiMessages(mf,main)
- gid = LabelFrame(main, text = "Id", relief = GROOVE, labelanchor = 'nw',width = 340, height = 100)
- gid.grid(row = 0, column = 2)
- gid.grid_propagate(0)
- self.guiGetId(gid,main)
- '''
- Button(mf, text= "Mostrar mensajes",width=20,state = DISABLED,command = self.showMessages,justify=LEFT),
- Button(mf, text= "Mandar mensaje",state = DISABLED,command = self.sendMessage,justify=LEFT),
- Button(pf, text= "Ver comentarios perfil",state = DISABLED,command = self.showSelfComments),
- Button(pf, text= "Ver comentarios del perfil de",state = DISABLED,command = self.showComments))
- main.options['message'] = Text(mf, foreground="black", background="white", highlightcolor="black", highlightbackground="purple", wrap=NONE, height = 7, width = 40)
- self.iButtons[0].grid(row = 1, column = 0,sticky=W)
- self.iButtons[1].grid(row = 3, column = 0,sticky=W)
- self.iButtons[2].grid(row = 1, column = 1, columnspan = 2)
- self.iButtons[3].grid(row = 2, column = 1, columnspan = 2)
- main.options['message'] = Text(mf, foreground="black", background="white", highlightcolor="black", highlightbackground="purple", wrap=NONE, height = 7, width = 40)
- main.options['message'].grid(row = 2, column = 0,padx=0)
- main.options['message'].insert(END,"Escribe un mensaje...")
- Label(pf,text = 'id:').grid(row = 2, column = 4)
- Entry(pf,textvariable = self.options['idProfile']).grid(row = 2, column = 5)
- Label(mf,text = 'id:').grid(row = 3, column = 1)
- Entry(mf,textvariable = self.options['idPM'],justify=LEFT).grid(row = 3, column = 2)
- self.options['idPM'].set('63455577')
- '''
- def guiGeneral(self,grid,main):
- ind = len(self.buttons['iButtons'])
- Label(grid, text = 'Email:').grid(row = 0, column = 1)
- Entry(grid, textvariable = main.options['email']).grid(row = 0, column = 2, columnspan = 2)
- Label(grid, text = 'Password:').grid(row = 1, column = 1)
- Entry(grid,show="*", textvariable = main.options['password']).grid(row = 1, column = 2, columnspan = 2)
- self.cButton = Button(grid, text= "Conectar",command=main.connect,width=15)
- self.cButton.grid(row = 1, column = 5, columnspan = 2)
- def guiProfile(self,grid,main):
- ind = len(self.buttons['iButtons'])
- self.buttons['iButtons'].append(
- Button(grid, text= "Ver comentarios perfil",state = DISABLED,command = main.showSelfComments))
- self.buttons['iButtons'].append(
- Button(grid, text= "Ver comentarios del perfil de",state = DISABLED,command = main.showComments))
- self.buttons['iButtons'][ind].grid(row = 0, column = 1)
- self.buttons['iButtons'][ind+1].grid(row = 1, column = 1)
- Label(grid,text = 'id:').grid(row = 1, column = 2)
- Entry(grid,textvariable = main.options['idProfile']).grid(row = 1, column = 3)
- def guiPhotos(self,grid,main):
- self.buttons['phButtons'].append(
- Button(grid, text= "Ver fotos",state = DISABLED,command = main.viewPhotos,justify=LEFT)
- )
- self.buttons['phButtons'][0].grid(row = 4, column = 0,sticky=W)
- pass
- def guiPhotosStatus(self,grid,main):
- ind = len(self.buttons['iButtons'])
- lb1 = LabelFrame(grid, relief = FLAT, labelanchor = 'nw', width = 300, height = 20)
- lb1.grid(row = 0, column = 0,sticky=W)
- lb1.grid_propagate(0)
- Label(lb1, text = 'Estado:').grid(row = 0, column = 0,sticky=W)
- self.phStatus = Label(lb1, text = 'No hay fotos cargadas',fg='red')
- self.phStatus.grid(row = 0, column = 1,sticky=W)
- lb2 = LabelFrame(grid, relief = FLAT, labelanchor = 'nw', width = 270, height = 30)
- lb2.grid(row = 1, column = 0)
- lb2.grid_propagate(0)
- self.buttons['iButtons'].append(
- Button(lb2, text= "Leer mis fotos",command = main.getPhotos,justify=LEFT,state=DISABLED)
- )
- self.buttons['iButtons'].append(
- Button(lb2, text= "Leer fotos de",command = main.getPhotos,justify=LEFT,state=DISABLED)
- )
- self.buttons['iButtons'][ind].grid(row = 1, column = 0,sticky=W)
- self.buttons['iButtons'][ind+1].grid(row = 1, column = 1,sticky=W,padx=3)
- Label(lb2, text = 'Id:').grid(row = 1, column = 2,sticky=W,padx=0)
- Entry(lb2, textvariable = main.options['idPhoto']).grid(row = 1, column = 3, columnspan = 2,sticky=W)
- def guiMessages(self,grid,main):
- ind = len(self.buttons['iButtons'])
- self.buttons['iButtons'].append(
- Button(grid, text= "Mostrar mensajes",width=20,state = DISABLED,command = main.showMessages,justify=LEFT)
- )
- self.buttons['iButtons'].append(
- Button(grid, text= "Mandar mensaje",state = DISABLED,command = main.sendMessage,justify=LEFT)
- )
- self.buttons['iButtons'][ind].grid(row = 1, column = 0,sticky=W)
- self.buttons['iButtons'][ind+1].grid(row = 3, column = 0,sticky=W)
- main.options['message'] = Text(grid, foreground="black", background="white", highlightcolor="black", highlightbackground="purple", wrap=NONE, height = 7, width = 40)
- main.options['message'].grid(row = 2, column = 0,padx=0)
- main.options['message'].insert(END,"Escribe un mensaje...")
- Label(grid,text = 'id:').grid(row = 3, column = 1)
- Entry(grid,textvariable = main.options['idPM'],justify=LEFT).grid(row = 3, column = 2)
- def guiGetId(self,grid,main):
- ind = len(self.buttons['iButtons'])
- lb1 = LabelFrame(grid, relief = FLAT, labelanchor = 'nw', width = 160, height = 40)
- lb1.grid(row = 1, column = 0,sticky=W)
- lb1.grid_propagate(0)
- Label(lb1, text = 'Nombre:').grid(row = 1, column = 1,padx=0,sticky=W)
- Entry(lb1, textvariable = main.options['nameSearch']).grid(row = 1, column = 2, columnspan = 2,sticky=W)
- Label(lb1, text = 'Apellidos:').grid(row = 2, column = 1,sticky=W,padx=0)
- Entry(lb1, textvariable = main.options['surnameSearch']).grid(row = 2, column = 2, columnspan = 2,sticky=W)
- self.buttons['iButtons'].append(
- Button(grid, text = "Obtener id",state = DISABLED,command = main.getId)
- )
- self.buttons['iButtons'][ind].grid(row = 3, column = 1,sticky=NW)
- lb2 = LabelFrame(grid, relief = FLAT, labelanchor = 'nw', width = 240, height = 40)
- lb2.grid(row = 3, column = 0,sticky=W)
- lb2.grid_propagate(0)
- self.searchStatus = Label(lb2, text = '',fg='red')
- self.searchStatus.grid(row = 2, column = 1,sticky=W)
- Label(lb2, text = 'Estado:').grid(row = 2, column = 0,sticky=W)
- Label(lb2, text = 'Id obtenida:').grid(row = 1, column = 0,sticky=W,padx=0)
- Entry(lb2, textvariable = main.idFound,width = 28).grid(row = 1, column = 1, columnspan = 2,sticky=W)
- class Main(Tk):
- def __init__(self):
- Tk.__init__(self)
- self.title(string = "PyTuenti")
- '''.resizable(width=FALSE, height=FALSE)
- '''
- self.options = {
- 'email' : StringVar(),
- 'password' : StringVar(),
- 'idProfile' : IntVar(),
- 'message' : StringVar(),
- 'idPM' : IntVar(),
- 'idPhoto' : IntVar(),
- 'nameSearch' : StringVar(),
- 'surnameSearch' : StringVar()
- }
- self.friendsData = None
- self.idFound= StringVar();
- self.photos = None
- self.connected = False
- self.phGot = False
- self.options['email'].set('agrs700@hotmail.com')
- self.options['password'].set('axelrulez92')
- self.gui=Gui(self)
- def connect(self):
- if(not self.connected):
- self.api = tuentiAPI(self.options['email'].get(),self.options['password'].get())
- self.friendsData = (self.api.request("getFriendsData",{}))['friends']
- self.gui.cButton['text']="Desconectar"
- self.connected=TRUE
- for button in self.gui.buttons['iButtons']:
- button['state'] = ACTIVE
- else:
- self.connected=FALSE
- self.gui.cButton['text']="Conectar"
- for button in self.gui.buttons['iButtons']:
- button['state'] = DISABLED
- del self.api
- def showMessages(self):
- messages = self.api.request("getInbox",{'user_id' : "1024"})
- for i in messages['threads']:
- print i['counter_part']['name'] +' '+ i['counter_part']['surname']
- print i['preview']
- def showSelfComments(self):
- comments = self.api.request("getProfileWall",{})
- for comment in comments['posts']:
- print comment['author']['name']+" " +comment['author']['surname']
- print comment['body'][0]['plain']
- def showComments(self):
- comments = self.api.request("getProfileWall",{'user_id' : self.options['idProfile'].get()})
- for comment in comments['posts']:
- print comment['author']['name']+" " +comment['author']['surname']
- print comment['body'][0]['plain']
- def sendMessage(self):
- print self.api.request("sendMessage",{'recipient' : self.options['idPM'].get(), 'body' : self.options['message'].get(0.0,END)})
- def getId(self):
- ids = []
- i = 0
- print self.options['nameSearch'].get()
- for friendData in self.friendsData:
- if(self.options['nameSearch'].get().lower().startswith(friendData['name'].lower())):
- if(self.options['surnameSearch'].get()==""):
- ids.append(friendData['id'])
- i = i+1
- elif(self.options['surnameSearch'].get().lower() == friendData['surname'].lower()):
- ids.append(friendData['id'])
- i = i+1
- if(i==0):
- self.gui.searchStatus['text'] = "Ningun usuario encontrado"
- self.gui.searchStatus['foreground'] = 'red'
- elif(i>1):
- self.gui.searchStatus['text'] = "Encontrados mas de un usuario"
- self.gui.searchStatus['foreground'] = 'lime green'
- else:
- self.gui.searchStatus['text'] = "Usuario encontrado"
- self.gui.searchStatus['foreground'] = 'lime green'
- idsStr = str(ids).strip('[]')
- self.idFound.set(idsStr)
- def getPhotos(self):
- print self.gui.phStatus
- user = self.api.request("getUsersData",{'ids' : [self.options['idPhoto'].get()]})
- print self.options['idPhoto'].get()
- if 'error' in user:
- print "Error: Usuario no valido"
- self.photos = None
- for button in self.gui.buttons['phButtons']:
- button['state'] = DISABLED
- else:
- if user['users'][0]['can_see'] == False:
- print "Error: No puedes ver las fotos del usuario introducido\nComprueba que esta en tu lista de amigos o si puedes ver su perfil"
- self.photos = None
- for button in self.gui.buttons['phButtons']:
- button['state'] = DISABLED
- else:
- albums = self.api.request("getUserAlbums",{'user_id' : self.options['idPhoto'].get()})
- album_list = [[a, albums[a]['size'], albums[a]['size']/25 if albums[a]['size']%25 == 0 else albums[a]['size']/25+1] for a in albums]
- self.photos = []
- for album in album_list:
- print 'Nombre del Album: %s\nNumero de Elementos: %d\nNumero de paginas: %d' % tuple(album)
- print album
- for p in range(album[2]):
- print 'Obteniendo pagina: %d' % p
- for e in self.api.request("getAlbumPhotos",{'user_id' : self.options['idPhoto'].get(),'album_id' : album[0], 'page' : p,})['album']:
- self.photos.append(e)
- self.gui.phStatus['foreground'] = 'lime green'
- self.gui.phStatus['text'] = 'Cargadas fotos de ' + user['users'][0]['name'] + " " + user['users'][0]['surname']
- for button in self.gui.buttons['phButtons']:
- button['state'] = ACTIVE
- def viewPhotos(self):
- for e in self.photos:
- print e['photo_url_600']
- if __name__ == '__main__':
- try:
- mw = Main()
- mw.mainloop()
- except Exception, ex:
- print(ex)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement