Last active
January 7, 2016 12:12
-
-
Save mhanoglu/6564ac2a8f504fa73d42 to your computer and use it in GitHub Desktop.
Kişi adını içeren özel mesaj oluşturma ve gönderme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
''' Project Name : SpecialMessages : 15:05 21.11.2011 | |
Author : by MeHMeT a.k.a MaRZoCHi (Mehmet Hanoğlu) | |
Copyright : www.mehmethanoglu.com.tr | |
License : GNU License | |
Update : 25.02.2012(0.4),06.01.2012(0.3),31.12.2011(0.2),01.01.2012 | |
''' | |
__doc__ = 'SpecialMessages : 15:05 21.11.2011' | |
__author__ = 'by MeHMeT a.k.a MaRZoCHi' | |
__name__ = 'smessages' | |
__version__ = '0.4' | |
__devmod__ = True | |
class SpecialMessages(object): | |
__module__ = __name__ | |
def __init__(self, ) : | |
if __devmod__ : | |
self.__count = 0 | |
self.operators = {"053":"Turkcell","054":"Vodafone","050":"Avea","055":"Avea"} | |
self.ALL_OPERATORS = self.operators.values() | |
self.names = {} | |
self._import() | |
def contents(self, vars) : | |
self.msg_dir = vars['msgdir'] | |
fopen = open(vars['cntfile'],'r') | |
self.cnt = fopen.read() | |
fopen.close() | |
del vars,fopen | |
def dump_op(self, op_dict) : | |
self.operators = op_dict | |
self.ALL_OPERATORS = self.operators.values() | |
del op_dict | |
def sets(self, limit=0, log=True, type=0, flash=0, sort=0, gsm=[], sender = "") : | |
self.limit = limit | |
self.log = log | |
self.type = type | |
self.gsm = gsm | |
self.flash = flash | |
self.sort = sort | |
self.sender = sender | |
if self.flash : | |
import flashy | |
self.message = flashy.send | |
del flashy | |
else : | |
import messaging | |
self.message = messaging.sms_send | |
del messaging | |
self._create_list() | |
if self.IMPORT : | |
self.READY = True | |
else : | |
self.READY = False | |
def start(self, args=[None,None]) : | |
if args[0] is not None : | |
sended = list() | |
if self.log : | |
file = open("e:\\others\\~message.log","a") | |
file.write(self.time("%y.%m.%d")+'\n'+'='*10+'\n') | |
file.close() | |
if self.READY : | |
self.msg_dir = self.msg_dir.encode("u8") | |
listd = self.listdir(self.msg_dir) | |
cntlist = self.names.keys() | |
if self.sort : cntlist.sort() | |
for i in range(len(cntlist)) : | |
if self.limit != 0 and i == self.limit : break | |
mfile = self.msg_dir+listd[self.random(0,len(listd))] | |
fop = open(mfile,'r') | |
shablon = fop.read().replace("\xff\xfe",'') ; fop.close() | |
if cntlist[i] : | |
if shablon.find("{to0}") != -1 : mtype = 0 | |
elif shablon.find("{to1}") != -1 : mtype = 1 | |
elif shablon.find("{to2}") != -1 : mtype = 2 | |
to = self._detect_name(cntlist[i].decode('u8'),mtype) | |
try : | |
mes = (shablon.replace("{from}",self.sender)).replace("{to"+str(mtype).encode('u8')+"}",to) | |
except : | |
mes = None | |
num = self.names[cntlist[i]] | |
if args[0] is not None : | |
sended.append(unicode(cntlist[i],"utf8","ignore")) | |
args[0](sended, len(cntlist)) | |
if not mes is None : | |
if __devmod__ : | |
self._devlog(cntlist[i] , num , mes) | |
else : | |
self._send(mes.decode('u8') , num) | |
if args[1] is not None : | |
del sended | |
args[1](len(cntlist)) | |
def _create_list(self,) : | |
for x in self.cnt.split('\n') : | |
if x is not '' : | |
[name,num] = x.split(':') | |
if num.find(',') != -1 : | |
num = num.split(',')[0] | |
if self.operators.has_key(num[0:3]) and (self.operators[num[0:3]] in self.gsm) : | |
self.names[name] = num | |
def _send(self, msg, num) : | |
try : | |
self.message(unicode(num,"u8"), self._latincon(msg)) | |
print '[+]',num | |
if self.log : self._log(num,True) | |
self.sleep(1.9000001) | |
except Exception, er: | |
print '[-]',num,er | |
if self.log : self._log(num,False) | |
def _log(self, num, state) : | |
file = open("e:\\others\\~message.log","a") | |
if state : | |
file.write(self.time("%H.%M.%S")+"-SENT::"+num+'\n') | |
else : | |
file.write(self.time("%H.%M.%S")+"-NOTSENT::"+num+'\n') | |
file.close() | |
def _devlog(self, name, num, mes) : | |
if __devmod__ : | |
self.__count += 1 | |
print "[%d] %s" %(self.__count, name.decode("u8")) | |
file = open("e:\\others\\__devmod__.log","a") | |
file.write(self.time("%H.%M.%S")+'\n'+name+' : '+str(num)+'\n'+mes+'\n') | |
file.close() | |
def _get_length(self,) : | |
return len(self.names.keys()) | |
def _detect_name(self, name, mtype): | |
last = (name.split(" ")[-1])[-2:].encode('u8','replace') | |
suffix = 0 | |
if last.find('a') != -1 : | |
if mtype == 1 : suffix = "ın" | |
elif mtype == 2 : suffix = "a" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'a' : | |
if mtype == 1 : suffix = "nın" | |
elif mtype == 2 : suffix = "ya" | |
elif mtype == 0 : suffix = "" | |
elif last.find('e') != -1 : | |
if mtype == 1 : suffix = "in" | |
elif mtype == 2 : suffix = "e" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'e' : | |
if mtype == 1 : suffix = "nin" | |
elif mtype == 2 : suffix = "ye" | |
elif mtype == 0 : suffix = "" | |
elif last.find('o') != -1 : | |
if mtype == 1 : suffix = "un" | |
elif mtype == 2 : suffix = "a" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'o' : | |
if mtype == 1 : suffix = "nun" | |
elif mtype == 2 : suffix = "ya" | |
elif mtype == 0 : suffix = "" | |
elif last.find('ö') != -1 : | |
if mtype == 1 : suffix = "in" | |
elif mtype == 2 : suffix = "e" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'ö' : | |
if mtype == 1 : suffix = "nin" | |
elif mtype == 2 : suffix = "ye" | |
elif mtype == 0 : suffix = "" | |
elif last.find('u') != -1 : | |
if mtype == 1 : suffix = "un" | |
elif mtype == 2 : suffix = "a" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'u' : | |
if mtype == 1 : suffix = "nun" | |
elif mtype == 2 : suffix = "ya" | |
elif mtype == 0 : suffix = "" | |
elif last.find('ü') != -1 : | |
if mtype == 1 : suffix = "ün" | |
elif mtype == 2 : suffix = "e" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'ü' : | |
if mtype == 1 : suffix = "nün" | |
elif mtype == 2 : suffix = "ye" | |
elif mtype == 0 : suffix = "" | |
elif last.find('ı') != -1 : | |
if mtype == 1 : suffix = "ın" | |
elif mtype == 2 : suffix = "a" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'ı' : | |
if mtype == 1 : suffix = "nın" | |
elif mtype == 2 : suffix = "ya" | |
elif mtype == 0 : suffix = "" | |
elif last.find('i') != -1 : | |
if mtype == 1 : suffix = "in" | |
elif mtype == 2 : suffix = "e" | |
elif mtype == 0 : suffix = "" | |
if last[-1] == 'i' : | |
if mtype == 1 : suffix = "nin" | |
elif mtype == 2 : suffix = "ye" | |
elif mtype == 0 : suffix = "" | |
else : pass | |
if suffix != 0 : | |
if mtype == 0 : | |
return (name.encode('u8')) | |
else : | |
return (name.encode('u8')+"'"+suffix) | |
else : print "Unknown coding format for",name | |
def _latincon(self, text,) : | |
liste = ["ı","i","ş","s","ç","c","ğ","g","ü","u","ö","o", | |
"İ","i","Ş","S","Ç","C","Ğ","G","Ü","U","Ö","O"] | |
for x in xrange(0,len(liste),2): | |
text = text.replace(liste[x].decode("u8"),liste[x+1]) | |
return text | |
def create_list(self, path) : | |
from contacts import ContactsDb | |
cdb = ContactsDb() | |
liste = {} | |
self.count_cnt = 0 | |
for x in cdb.find('') : | |
mb = x.find('mobile_number') | |
if mb : | |
liste[x.title] = [mb[t].value for t in range(len(mb))] | |
cntcts = {} | |
for w in range(len(liste.keys())): | |
name = liste.keys()[w] | |
cntcts[name] = ",".join(liste[name]) | |
cntlist = cntcts.keys() | |
cntlist.sort() | |
a = open(path, 'w') | |
for i in range(len(cntlist)): | |
xname = cntlist[i] | |
xnum = cntcts[cntlist[i]] | |
if xnum : | |
a.write(xname.encode('u8','ignore')) | |
a.write(':') | |
a.write(xnum) | |
a.write('\n') | |
self.count_cnt += 1 | |
a.close() | |
def _import(self, ) : | |
try : | |
from os import listdir | |
from random import randrange | |
from time import strftime, sleep | |
from sys import setrecursionlimit | |
setrecursionlimit(10000000) | |
self.listdir = listdir | |
self.sleep = sleep | |
self.random = randrange | |
self.time = strftime | |
self.IMPORT = True | |
except : | |
self.IMPORT = false | |
##### Kullanım | |
import smessages | |
sms = smessages.SpecialMessages() | |
sms.create_list("c:\\contact.txt") | |
sms.dump_op({ | |
"053":"Turkcell", | |
"054":"Vodafone", | |
"050":"Avea", | |
"055":"Avea" | |
}) | |
sms.contents({ | |
"cntfile" : "c:\\contact.txt", | |
"msgdir" : "e:\\mess\\", | |
}) | |
sms.sets( | |
limit=0 , | |
log=True , | |
flash=False , | |
sort=True , | |
gsm=sms.ALL_OPERATORS , | |
gsm=["Vodafone","Avea","Turkcell"] | |
sender="Mehmet Hanoglu" , | |
) | |
print sms._get_length() | |
sms.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment