Давно когда то писал, код не стоит принимать всерьез, но работал в свое время.
#!/usr/bin/python
# -*- coding: utf-8
#mobilnaya versiya sayta
from grab import Grab
from Tkinter import *
import Image, ImageTk
import urllib
def loadConfig():
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.ini')
login = config.get('connect', 'login')
pas = config.get('connect', 'pas')
return {'login':login,'pas':pas}
config = loadConfig()
log = config['login']
pas = config['pas']
g = Grab()
g.setup(post={"fr.posted": "set", "fr.needCaptcha": "", 'fr.login':log, 'fr.password':pas,"button_login": "Войти"})
g.go("http://m.odnoklassniki.ru/dk?bk=GuestMain&st.cmd=main&_prevCmd=main&tkn=8520")
g.go('http://m.odnoklassniki.ru/dk?st.cmd=userDlgs&tkn=9002&_prevCmd=userMain')# zdes link dialogov
btn = {}
def gen(x):#генерирует кнопки с участниками
s = out
btn[x] = Button(r , text = s,height=1, command = lambda: two(x)).pack()
def res():
global r
global out
r = Tk()
r["bg"] = "green"
c = 0
g.go('http://m.odnoklassniki.ru/dk?st.cmd=userDlgs&tkn=9002&_prevCmd=userMain')
while True:
try:
c += 1
s = '['+str(c)+']'
out = g.xpath_text('//*[@id="dialogs"]/li'+ s) # prosmotr ychastnikov dialogov
Button(root, text='',command=gen(c))#генерируем кнопки с участниками
r.destroy()
except:
r.destroy()
break
def one(event=None):
global r
global out
r = Tk()
r["bg"] = "green"
c = 0
g.go('http://m.odnoklassniki.ru/dk?st.cmd=userDlgs&tkn=9002&_prevCmd=userMain')
while True:
try:
c += 1
s = '['+str(c)+']'
out = g.xpath_text('//*[@id="dialogs"]/li'+ s) # prosmotr ychastnikov dialogov
Button(root, text='',command=gen(c))#генерируем кнопки с участниками
except: break
def two(x):
g.go('http://m.odnoklassniki.ru/dk?st.cmd=userDlgs&tkn=9002&_prevCmd=userMain')
d = x
s = '['+str(d)+']'
#print g.xpath_text('//*[@id="dialogs"]/li'+ s)#vibiraem nomer uchastnika dialoga
lnk = g.xpath('//*[@id="dialogs"]/li'+s+'/div/a').get('href') # uznaem link ego sms chata so mnoi
g.go('http://m.odnoklassniki.ru/'+ lnk)# perehodim
tex.delete(1.0,END)
ot = g.xpath_text('//*[@id="message-list"]')
oute = ot.split(u'Удалить')
for i in oute:
tex.insert(END,i+' ')
tex.see(END)
ent.delete(0,END)
r.destroy()
def output(event=None):
global stat
try:
msg = ent.get()
g.set_input('fr.msg', msg)
g.submit()
stat = status()
given = stat[0]
family = stat[1]
outw = zip(given, family)
lines=[]
tex.delete(1.0,END)
for row in outw:
lines.append(' '.join(map(str, [i.encode('utf-8') for i in row])))
for i in lines:
#tex.delete(1.0,END)
tex.insert(END,i+' ')#.decode('utf-8')+' ')
tex.see(END)
ent.delete(0,END)
free()
except Exception as e:
#print e
res()
pass
def free():
try:
stat2 = status()
out2 = stat2[0][-1] + ' ' + stat2[1][-1] + "\r\n"
if stat[1][-1] == stat2[1][-1]:
pass
else:
tex.insert(END,out2)
tex.see(END)
output()
root.after(7000, free)
except Exception as e:
#print 'output'
pass
def status():
try:
sp = []
spt = []
v = 0
try:
#g.xpath('//*[@id="messages-pager-bottom"]/ul/li[2]/a').get('href')
#ln = g.xpath('//*[@id="messages-pager-bottom"]/ul/li[2]/a').get('href') #obnovlyaem stranicu
g.go('http://m.odnoklassniki.ru/'+ g.xpath('//*[@id="messages-pager-bottom"]/ul/li[2]/a').get('href')) #obnovlyaem stranicu
except:
#ln = g.xpath('//*[@id="messages-pager-bottom"]/ul/li/a').get('href') #obnovlyaem stranicu
g.go('http://m.odnoklassniki.ru/'+ g.xpath('//*[@id="messages-pager-bottom"]/ul/li/a').get('href')) #obnovlyaem stranicu
finally: pass
try:
while True: #uznaem kolichestvo sms
v += 1
b = '['+str(v)+']'
d = g.xpath_text('//*[@id="message-list"]/li' + b)
except:
v = v #kolichestvo sms
for i in xrange(1,v):
b = '['+str(i)+']'
try:
d = g.xpath('//*[@id="message-list"]/li' + b).get('title')
dt = g.xpath('//*[@id="message-list"]/li'+b+'/div/div[2]').get('aria-label')
except: pass
sp.append(d)# spisok sms
spt.append(dt)# spisok time
try:
img = 'http://m.odnoklassniki.ru/'+ g.xpath('//*[@id="content"]/div/div[2]/div/div/div[1]/div/div/img').get('src')
fimg = img.split('/')[-1]
if fimg == 'olblu.gif':
btn40.configure(state=NORMAL,background='blue' )
elif fimg == 'olorg.gif':
btn40.configure(state=NORMAL,background='orange' )
except Exception as e:
btn40.configure(state=NORMAL,background='white' )
pass
return spt, sp
except Exception as e:
print 'status', e
pass
def clear(event):#функция очистки текстового поля
tex.delete(1.0,END)
def clear_ent(event):#функция очистки поля ввода
ent.delete(0,END)
def sm1(event):#функции вставки смайлов в окно ввода
ent.insert(END, ' '+':-)')
def sm2(event):
ent.insert(END, ' '+':-D')
def sm3(event):
ent.insert(END, ' '+';-)')
def sm4(event):
ent.insert(END, ' '+'(K)')
def sm5(event):
ent.insert(END, ' '+'(F)')
def sm6(event):
ent.insert(END, ' '+":'(")# ent.insert(0, ":'(")добавление в конец/начало строки
def toggle(): #функция скрывает/восстанавливает рамку виджет frame на которой кнопки смайлов
if window.visible:
btnToggle["text"] = "Show Smiles"
window.place_forget()
else:
window.place(window.pi)
btnToggle["text"] = "Hide Smiles"
window.visible = not window.visible
root = Tk()
root.title(log)
root["bg"] = "green"
root.geometry('560x150')
##########################################################относится
window = Frame(root,width=300,height=50) #к рамке
window.visible = True #на которой
window.place(x=60, y=110) #кнопки
window.pi = window.place_info() #со
#смайлами
btnToggle = Button(text="Hide Smiles", command=toggle) #
btnToggle.place(x=250, y=120) #
##########################################################
ent = Entry(root,width=80)
but = Button(root,text=u"Ввод")
but2 = Button(root,text=u"Диалоги")
#but3 = Button(root,text="Выбор диалога")
but4 = Button(root,text=u"Стереть")
#but5 = Button(root,text="Стереть ввод")
tex = Text(root,width=53,height=4,font='14',wrap=WORD)
scr = Scrollbar(root,command=tex.yview)
tex.configure(yscrollcommand=scr.set)
tex.grid(row=0,column=0)
scr.place(x=480, y=25)
ent.place(x=0, y=90)
but.place(x=450, y=120)
but2.place(x=500, y=120)
#but3.grid(row=4,column=2)
but4.place(x=500, y=35)
#but5.grid(row=3,column=2)
###################################### здесь кнопки со смайлами
ph1 = ImageTk.PhotoImage(Image.open('image\\04b.gif'))
btn = Button(window, image=ph1)
ph2 = ImageTk.PhotoImage(Image.open('image\\11a.gif'))
btn2 = Button(window, image=ph2)
ph3 = ImageTk.PhotoImage(Image.open('image\\09a.gif'))
btn3 = Button(window, image=ph3)
ph4 = ImageTk.PhotoImage(Image.open('image\\24a.gif'))
btn4 = Button(window, image=ph4)
ph5 = ImageTk.PhotoImage(Image.open('image\\23a.gif'))
btn5 = Button(window, image=ph5)
ph6 = ImageTk.PhotoImage(Image.open('image\\13a.gif'))
btn6 = Button(window, image=ph6)
btn.place(x = 0, y = 6)
btn.bind("<Button-1>",sm1)
btn2.place(x = 30, y = 6)
btn2.bind("<Button-1>",sm2)
btn3.place(x = 60, y = 6)
btn3.bind("<Button-1>",sm3)
btn4.place(x = 90, y = 6)
btn4.bind("<Button-1>",sm4)
btn5.place(x = 120, y = 6)
btn5.bind("<Button-1>",sm5)
btn6.place(x = 150, y = 6)
btn6.bind("<Button-1>",sm6)
###############################################################
#root.after(100, one)
ent.bind("<Return>",output)
but.bind("<Button-1>",output)
but2.bind("<Button-1>",one)
#but3.bind("<Button-1>",two)
but4.bind("<Button-1>",clear)
#but5.bind("<Button-1>",clear_ent)
btn40 = Button(root)# кнопка индикатор
btn40.configure(state=NORMAL,background='white' )
btn40.place(x=480, y=0)
root.mainloop()