Δημοσιεύτηκε: 15 Ιαν 2014, 21:03
από malos
Εδώ είναι ο κώδικας με spoiler που δεν δουλεύει με κλικ. Μόνο στο κείμενο έχω κάνει αλλαγές, δηλαδή το έκανα στα ελληνικά. Άλλαξα επίσης κάποια γραμμή και την έκανα
ενώ ήταν έτσι
- Κώδικας: Επιλογή όλων
try: hf = codecs.open(fur % val,"r", encoding='utf-8')
ενώ ήταν έτσι
- Κώδικας: Επιλογή όλων
try: hf = open(fur % val,"r")
Spoiler: show
- Κώδικας: Επιλογή όλων
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# qtCosmos v0.6, based on pycosmos
# kaddressbook contacts' loader based on pysmssend
# by dkarnout. Last version: 10/07/09
from os import path, environ
from sys import argv, exit
from urllib import urlencode
from httplib import HTTPConnection
from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QDialog, QLabel, QComboBox, QPlainTextEdit, QPushButton, QIcon
from PyQt4.QtGui import QListWidget, QLineEdit, QInputDialog, QMessageBox, QApplication
#import os
import codecs
def isvd(dsn):
try:
testdst = str(int(dsn))
except: return "!"
dsn = str(dsn).strip()
if dsn[:2] == "69": dsn = "0030" + dsn
if dsn[:1] == "+": dsn = "00" + dsn[1:]
if not dsn[:2] == "00" or not len(dsn) == 14: return "!"
return dsn
def httpc(url,cookie="",body=None,he='set-cookie',glen=3000):
if cookie:
headers={
"accept-language": "el", "accept-encoding": "gzip, deflate", "cache-control": "no-cache", "cookie": cookie,
"user-agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 3.51; SV1; .NET CLR 2.0.50727)",
"content-type": "application/x-www-form-urlencoded", "connection": "Keep-Alive", "host": "mail.mycosmos.gr",
"accept": "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
}
else: headers={}
if bool(body): headers['content-length'] = str(len(body))
try:
h=HTTPConnection("mail.mycosmos.gr",80)
except: return "!"
h.request(["GET","POST"][bool(body)],"/mycosmos/%s.aspx" % url,body,headers)
resp=h.getresponse()
if not bool(body):
try:
p.gvs=resp.read(glen).split('VIEWSTATE')[1]
p.gvs=p.gvs.split('"')[2]
except: p.gvs="!"
h.close()
if glen==3000: return resp.getheader(he)
def letsend():
i=0; dst = nlist.currentText().split(";")
while i < len(dst):
d2 = nlist.findText(str(dst[i]).strip())
if d2 > -1:
dst[i] = p.pl[d2]
else:
dsv = isvd(dst[i])
if dsv == "!":
noti(dst[i]+u" είναι κουφός αριθμός!")
del dst[i]; i=i-1
else: dst[i]=dsv
i=i+1
if len(dst)==0: return 1
i = len(tsms.toPlainText()); msgl = []
for j in range(i/140 + bool(i % 140)):
msgl.append(tsms.toPlainText()[j*140:(j+1)*140])
noti(u"Φορτώνονται το cookies από το mycosmos")
try:
test = p.asid
test = p.vs1
except:
h=httpc("login")
if h=="!": noti(u"Το μύνημα δεν στάλθηκε. Σφάλμα σύνδεσης δικτύου"); return 1
p.asid=h.split()[0].split(';')[0]
p.vs1=p.gvs
for k in range(len(dst)):
for j in range(len(msgl)):
nc = 0; tpr = "%s/%s " % (str(j+1),str(len(msgl)))
if len(msgl) == 1: tpr = "SMS "
while True:
if p.ck == "": getck()
if not p.vs2 == "!":
h=httpc("SMS_Send",p.ck,urlencode({"__VIEWSTATE": p.vs2, "txtMobile": dst[k], "txtMessage": unicode(msgl[j]).encode('utf-8'), "btnSend": "Αποστολή"}),'location')
try:
if h.split('Success=')[1].split('&')[0] == "True":
noti(tpr + u"εστάλη επιτυχώς!"); os.system('notify-send "Το SMS στάλθηκε επιτυχώς" '); os.system('espeak -v el -p 35 -s 100 -k 1 "Το πήρε! το μύνημα" '); nc = 0; break
else:
nc = nc + 1; noti(tpr + u"δεν εστάλη. Πέρασες το όριο")
except:
nc = nc + 1; noti(tpr + u"δεν εστάλη. Άγνωστος λόγος")
else:
nc = nc + 1; noti(u"Λάθος. Μάλλον μαϊμού λογαριασμός")
p.ck = ""
if nc <= len(p.al) and len(p.al) > 1:
a1 = p.al.pop(0); p.al.append(a1)
try:
lacc.takeItem(0); lacc.addItem(a1)
except: pass
a1 = p.cl.pop(0); p.cl.append(a1)
if (len(p.al)==1 and nc==2) or (nc==len(p.al) and len(p.al)>1): return 1
def getck():
noti("Getting cookie for %s account..." % p.al[0])
h1=httpc("login",p.asid,urlencode({"__VIEWSTATE": p.vs1, "tbUsername": p.al[0], "tbPassword": p.cl[0], "btLogin": "Σύνδεση", "rbSecurityPub": "rbSecurityPub"}))
if h1=="!": p.vs2="!"; return 1
p.ck = p.asid+"; "+h1.split()[0]+" "+h1.split()[2].split(';')[0]
noti("Getting mycosmos SMS viewstate...")
if httpc("SMS_Send",p.ck,glen=6000)=="!": p.vs2="!"; return 1
p.vs2=p.gvs
class pprop():
def __init__(self):
self.al, self.cl, self.pl = [], [], []
self.ck, self.vs2, self.gvs = "", "", ""
class QtCosmos(QDialog):
def __init__(self):
global nlist, tsms, bsend, bconf, slab, label, mpar
QDialog.__init__(self,None)
self.setWindowTitle(u'Στείλε το SMS σου')
self.setWindowIcon(QIcon("%s48.png" % path.abspath(argv[0]).split(".py")[0]))
label = QLabel(u'Αριθμός του φίλου:', self); nlist = QComboBox(self)
nlist.setEditable(True); nlist.setInsertPolicy(0)
nlist.setWhatsThis(" Type here the name (if in phonebook) or the number of the reciever. You may set a list of recievers with '<b>;</b>' among them.")
label1 = QLabel(u'Γράψε εδώ το κείμενο:', self); mpar = QLabel('', self)
tsms = QPlainTextEdit(self); tsms.setTabChangesFocus(True)
tsms.setWhatsThis(" Type here your message. Messages longer than <b>140</b> characters will be split.\n <b>10</b> messages per account per day are allowed.")
bsend = QPushButton(u'Στείλε', self); bsend.setDefault(True)
bconf = QPushButton(u'Λογαριασμοί', self)
slab = QLabel('', self)
self.setMinimumSize(255+bconf.sizeHint().width(),149)
label.move(5, 5+nlist.height()/2-label.sizeHint().height()/2); label1.move(5, label.sizeHint().height()+16)
mpar.move(label1.width()+12, label1.y()); tsms.move(5, mpar.y()+mpar.sizeHint().height()+1)
self.connect(bsend, SIGNAL('clicked()'), letsend)
self.connect(bconf, SIGNAL('clicked()'), conf)
self.connect(tsms, SIGNAL('textChanged()'), mpw)
def resizeEvent(self,a):
p.toSave=True
i=label.sizeHint().width()
nlist.setGeometry(i+10, 5, a.size().width()-(i+15), nlist.height())
tsms.setGeometry(5, tsms.y(), self.width()-bconf.sizeHint().width()-15, self.height()-tsms.y()-label.sizeHint().height()-3)
bsend.setGeometry(self.width()-bconf.sizeHint().width()-5,tsms.y()+bsend.sizeHint().height()+5,bconf.sizeHint().width(),bconf.sizeHint().height())
bconf.move(bsend.x(), tsms.y())
slab.setGeometry(1, tsms.height()+tsms.y()+1, a.size().width(), label.sizeHint().height())
def closeEvent(self,a):
if not p.toSave: return 0
try:
af = open(path.expanduser('~') + "/.qtcosmosrc","w")
noti(u"Οι ρυθμίσεις αποθηκεύονται")
af.write("[Geometry]\n")
af.write("%s,%s,%s,%s\n" % (self.x(),self.y(),self.width(),self.height()))
if len(p.al) > 0:
af.write("[Accounts]\n")
for i in range(len(p.al)):
af.write(p.al[i] + "," + p.cl[i] + "\n")
af.close()
noti(u"Έγινε.")
except IOError:
noti("I/O Error. Cannot save accounts and settings.")
class QtConf(QDialog):
def __init__(self):
global lacc, laa, lap, bau, bad, baa, bar
QDialog.__init__(self,qc)
self.move(qc.x()+220, qc.y()+99); self.setMinimumSize(295, 150); self.setWindowTitle(u'Λογαριασμοί του qtcosmos')
label2 = QLabel(u'Λογαριασμοί:', self); lacc = QListWidget(self)
laa = QLineEdit(self); laa.setMaxLength(10); lap = QLineEdit(self); lap.setEchoMode(2)
bau = QPushButton(u'Πάνω', self); bad = QPushButton(u'Κάτω', self)
baa = QPushButton(u'Πρόσθεσε', self); bar = QPushButton(u'Διαγραφή', self)
print lap.EchoMode()
label2.move(5, 5)
self.connect(lacc, SIGNAL('itemSelectionChanged()'), asel)
self.connect(laa, SIGNAL('editingFinished()'), claa)
self.connect(lap, SIGNAL('editingFinished()'), clap)
self.connect(bau, SIGNAL('clicked()'), cbau)
self.connect(bad, SIGNAL('clicked()'), cbad)
self.connect(baa, SIGNAL('clicked()'), cbaa)
self.connect(bar, SIGNAL('clicked()'), cbar)
def resizeEvent(self,a):
laa.setGeometry(self.width()/2+2, label.height()+5, self.width()/2-10, laa.sizeHint().height())
lap.setGeometry(laa.x(), laa.y()+laa.height()+5, laa.width(), laa.height())
baa.setGeometry(laa.x()+55, lap.y()+lap.height()+5, 80, baa.sizeHint().height())
bar.setGeometry(baa.x(), baa.y()+baa.height()+4, baa.width(), baa.height())
bad.setGeometry(laa.x(), bar.y(), 50, baa.height())
bau.setGeometry(bad.x(), baa.y(), bad.width(), baa.height())
lacc.setGeometry(10, label.height()+5, self.width()/2-15, self.height()-label.height()-12)
def inpD(ask,echomode = 0):
ask, ok = QInputDialog.getText(q2, 'qtCosmos', ask, echomode)
return ask
def cbaa():
cr = lacc.currentRow()+1
while True:
kacc = inpD(u"Γράψε το κινητό σου")
if len(kacc) == 0: return 1
try:
tst = str(int(kacc))
except: tst = "~INT"
if not (kacc[:2] == "69" or len(kacc) == 10) or tst == "~INT":
QMessageBox.warning(q2,'qtCosmos', u"Ο λογαριασμός είναι λάθος")
else: break
kpas = inpD(u"Δώσε κωδικό:",2)
if len(kpas) == 0: return 1
p.al.insert(cr,kacc); p.cl.insert(cr,kpas); lacc.insertItem(cr,kacc)
lacc.setCurrentRow(cr); p.toSave = True
def cbau():
cr = lacc.currentRow()
if cr < 1: return 1
aa=p.al.pop(cr); p.al.insert(cr-1,aa)
cc = p.cl.pop(cr); p.cl.insert(cr-1,cc)
lacc.takeItem(cr); lacc.insertItem(cr-1,aa)
lacc.setCurrentRow(cr-1); p.toSave = True
def cbad():
cr = lacc.currentRow()
if cr == -1 or cr == len(p.al)-1: return 1
aa=p.al.pop(cr); p.al.insert(cr+1,aa)
cc = p.cl.pop(cr); p.cl.insert(cr+1,cc)
lacc.takeItem(cr); lacc.insertItem(cr+1,aa)
lacc.setCurrentRow(cr+1); p.toSave = True
def cbar():
cr = lacc.currentRow()
if len(p.al) == 0: return 1
p.al.pop(cr); p.cl.pop(cr); lacc.takeItem(cr); p.toSave = True
def claa():
if lacc.count()==0: laa.setText(""); return 0
cr = lacc.currentRow(); tt = laa.text()
if tt == p.al[cr]: return 0
try:
tst = str(int(tt))
except: tst = "~INT"
if not (tt[:2] == "69" or len(tt) == 10) or tst == "~INT":
laa.setText(p.al[cr])
QMessageBox.warning(q2,'qtCosmos', u"Είναι μαϊμού ο λογαριασμός")
return 1
p.al.insert(cr,tt); p.al.pop(cr+1); lacc.insertItem(cr,tt); lacc.takeItem(cr+1)
p.toSave = True
def clap():
if lacc.count()==0: lap.setText(""); return 0
cr = lacc.currentRow(); tt = lap.text()
if tt == p.cl[cr]: return 0
p.cl.insert(cr,tt); p.cl.pop(cr+1); p.toSave = True
def asel():
cr = lacc.currentRow()
if len(p.al) == 1: cr=0
if cr == -1:
laa.setText(""); lap.setText("")
else:
laa.setText(p.al[cr]); lap.setText(p.cl[cr])
def noti(txt):
slab.setText(txt)
print txt
return 0
def mpw():
t = tsms.toPlainText()
i = len(t)+t.count("[")+t.count("]")+t.count("{")+t.count("}")+t.count("|")+t.count("~")+t.count("^")+t.count("\\")+t.count("€")
i = i/140 + bool(i % 140)
if i == 1:
t1 = ")"
else: t1 = "s)"
mpar.setText("(%s message" % str(i) + t1)
def conf():
global q2
q2=QtConf()
if lacc.count() == 0: lacc.addItems(p.al)
try: lacc.setCurrentRow(0)
except: pass
q2.show()
def getcontacts():
fur=environ["HOME"] + "/.kde%s/share/apps/kabc/std.vcf"
if path.exists(fur % "4"):
val="4"
elif path.exists(fur % ""):
val=""
else:
return 1
try: hf = codecs.open(fur % val,"r", encoding='utf-8')
except IOError: return 1
text = hf.readlines()
hf.close()
for i in text:
if i[0:3] == "FN:":
nam=i[3:]
if i[0:14] == "TEL;TYPE=CELL:":
phon=isvd(i[14:].strip())
if phon == "!":
pass
else:
nlist.addItem(nam.strip())
p.pl.append(phon)
nlist.setEditText("")
if __name__ == "__main__":
app = QApplication(argv)
global qc, p
p = pprop(); qc = QtCosmos()
try:
afile = open("%s/.qtcosmosrc" % path.expanduser('~'),"r")
while afile:
buf = afile.readline()
if len(buf) == 0: break
if buf[:4] == "[Geo":
ltyp="geo"
elif buf[:4] == "[Acc":
ltyp="acc"
else:
buf = buf.split(",", [1,4][bool(ltyp=="geo")])
if ltyp == "geo":
qc.setGeometry(int(buf[0]),int(buf[1]),int(buf[2]),int(buf[3]))
elif ltyp == "acc":
p.al.append(buf[0])
p.cl.append(buf[1][:len(buf[1])-1])
afile.close()
if getcontacts() == 1:
noti(u"Δεν βρέθηκε το βιβλίο διευθύνσεων.")
else:
noti(u"'Ετοιμο")
except IOError:
noti(u"[!] Δεν βρέθηκε λογαρισμός και ρυθμίσεις. ΤΖΙΦΟΣ!.")
qc.show()
exit(app.exec_())