Beispiel #1
0
 def __init__(self):
     accessDetails = open('/home/hemant/access.txt')
     aD = json.loads(accessDetails.read())
     self.client = FrappeClient(aD['url'],aD['username'],aD['password'])
     self.settingObj = self.client.get_api("varmani.getMTNServiceSettings")
     self.driver = webdriver.PhantomJS()
     self.login()
Beispiel #2
0
	def __init__(self):
		accessDetails = open('/home/hemant/access.txt')
		aD = json.loads(accessDetails.read())
		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		self.client = FrappeClient(aD['url'],aD['username'],aD['password'])
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
		#print 'USSD Processor login', secondsTime

		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		self.settingsObj = self.client.get_api("varmani.getMTNServiceSettings")
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
		#print 'Getting settings', secondsTime

		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		self.myMessageService = myService()
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
Beispiel #3
0
class MessageProcessor(object):
	def __init__(self):
		accessDetails = open('/home/hemant/access.txt')
		aD = json.loads(accessDetails.read())
		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		self.client = FrappeClient(aD['url'],aD['username'],aD['password'])
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
		#print 'USSD Processor login', secondsTime

		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		self.settingsObj = self.client.get_api("varmani.getMTNServiceSettings")
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
		#print 'Getting settings', secondsTime

		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		self.myMessageService = myService()
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
		#print 'init message service', secondsTime

		
	def logMe(self, msg):
		#localtime = datetime.datetime.now().replace(microsecond=0)
		#message = "[" + localtime.strftime("%Y-%m-%d %H:%M:%S") + "] " + msg + "\r\n"
		#sys.stdout.write(message)
		#sys.stdout.flush()
		pass

	def processMessage(self, sessionId, msisdn, rootMsg, requestMsg, msgType, ranNow):
		localtime = time.asctime(time.localtime(time.time()))
		current = datetime.datetime.now().replace(microsecond=0)
		diff = current - ranNow
		seconds = diff.total_seconds()

		lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
		banned = self.client.get_api("varmani.isBanned","msisdn=" + msisdn)
		currentTime = datetime.datetime.now()
		diffTime = currentTime - lastTimeCheck
		secondsTime = diffTime.total_seconds()
		#print 'checking banned', secondsTime
		#print banned
		if (banned != True or banned==None):
			lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
			self.myMessageService.sendUSSD(sessionId,msisdn,str(seconds) + ' - ' + requestMsg,'USER_REQUEST')

			currentTime = datetime.datetime.now()
			diffTime = currentTime - lastTimeCheck
			secondsTime = diffTime.total_seconds()
			#print 'sending message',secondsTime

			lastTimeCheck = datetime.datetime.now().replace(microsecond=0)
			self.recordMessage(sessionId, msisdn, rootMsg, requestMsg, msgType)
			currentTime = datetime.datetime.now()
			diffTime = currentTime - lastTimeCheck
			secondsTime = diffTime.total_seconds()
			#print 'Storing sessiong message', secondsTime
	
	def recordMessage(self, sessionid, msisdn, rootMsg, requestMsg, msgType):
		#self.client = FrappeClient("https://www.varmani.co.za","administrator","gauranga")
		name = self.client.get_value("USSD Session", "name", {"sessionid": sessionid})
		
		if name:
			doc = self.client.get_doc("USSD Session", name["name"])
		else:
			doc = {"doctype":"USSD Session"}
			
		doc["sessionid"] = sessionid
		doc["msisdn"] = msisdn
		doc["root_message"] = rootMsg
		localtime = datetime.datetime.now().replace(microsecond=0)
		doc["date"] = localtime.strftime("%Y-%m-%d %H:%M:%S")
		mdoc = {"doctype":"USSD Message"}
		mdoc["incoming"] = "1"
		mdoc["msisdn"] = msisdn
		mdoc["message"] = requestMsg
		mdoc["message_type"]=msgType
		#print doc.messages
		try:
			doc['messages'].append(mdoc)
		except:
			doc['messages']=[]
			doc['messages'].append(mdoc)

		if name:
			self.client.update(doc)
		else:
			self.client.insert(doc)
Beispiel #4
0
class RicaService(object):
    def __init__(self):
        accessDetails = open('/home/hemant/access.txt')
        aD = json.loads(accessDetails.read())
        self.client = FrappeClient(aD['url'],aD['username'],aD['password'])
        self.settingObj = self.client.get_api("varmani.getMTNServiceSettings")
        self.driver = webdriver.PhantomJS()
        self.login()

        #self.driver = webdriver.Firefox()

    def __enter__(self):
        return self

    def __exit__(self, *args, **kwargs):
        self.logout()

    def login(self):
        self.driver.set_window_size(1120, 550)
        self.driver.get(self.settingObj['rica_login_url'])
        self.driver.find_element_by_id('txtId').send_keys(self.settingObj['rica_username'])
        self.driver.find_element_by_id("txtPassword").send_keys(self.settingObj['rica_password'])
        self.driver.find_element_by_id("btnLogin").click()
        #"""
        if self.driver.current_url == self.settingObj['rica_register_url']:
            return True
        else:
            return False

    def logout(self):
        self.driver.quit()

    def register(self, doc):
        result = {}
        self.driver.get(self.settingObj['rica_register_url'])
        if doc['is_consumer'] == True:
            self.driver.find_element_by_id('lstCustType').send_keys("C")
        else:
            self.driver.find_element_by_id('lstCustType').send_keys("J")

        self.driver.find_element_by_id('txtFName').send_keys(doc['first_names'])
        self.driver.find_element_by_id('txtSurname').send_keys(doc['last_names'])
        if doc['is_citizen'] == True:
            self.driver.find_element_by_id('optSA').send_keys("I")
        else:
            self.driver.find_element_by_id('optSA').send_keys("P")
        self.driver.find_element_by_id('txtID').send_keys(doc['identification_number'])
        self.driver.find_element_by_id('lstResRegion').send_keys(doc['region'])
        time.sleep(1)
        self.driver.find_element_by_id('txtResCityTown').send_keys(doc['city'])
        time.sleep(1)
        self.driver.find_element_by_id('txtResCityTown').send_keys(doc['city'])
        self.driver.find_element_by_id('txtResSuburb').send_keys(doc['surburb'])
        self.driver.find_element_by_id('txtResAddr1').send_keys(doc['address1'])
        self.driver.find_element_by_id('txtResAddr2').send_keys(doc['address2'])
        self.driver.find_element_by_id('txtResAddr3').send_keys(doc['address3'])
        self.driver.find_element_by_id('txtResCode').send_keys(doc['code'])

        #self.driver.find_element_by_id('txtMSISDN').send_keys("7203245157089")
        #time.sleep(1)

        self.driver.find_element_by_id('txtSIM').send_keys(doc['serial_number'])
        time.sleep(1)
        self.driver.find_element_by_id("btnAddSIM").click()

        #self.driver.find_element_by_id('txtSIMKit').send_keys("")
        time.sleep(2)
        self.driver.find_element_by_id("lnkSubmit").click()
        time.sleep(2)
        try:
            alert = self.driver.switch_to_alert()
            result.message = alert.text
            alert.accept()
        except:
            print "no alert to accept"
            soup = BeautifulSoup(self.driver.page_source, "lxml")
            #print soup._all_strings
            trs = soup.find('tr')
            for tr in trs:
                #print tr
                try:
                    self.result.message = tr.get_text()
                except:
                    pass


        if "successfully RICA'd" in result.message:
            result.processed= True
        else:
            result.processed = False

        return result

    def deregister(self, doc):
        result = {}
        self.driver.get(self.settingObj['rica_deregister_url'])

        self.driver.find_element_by_id('optSearchType_1').click()
        time.sleep(1)

        self.driver.find_element_by_id('txtSIM').send_keys(doc['serial_number'])
        if doc['is_citerzen'] == True:
            self.driver.find_element_by_id('optIDType_0').click()
            self.driver.find_element_by_id('txtID').send_keys(doc['identification_number'])
        else:
            self.driver.find_element_by_id('optIDType_').click()
            self.driver.find_element_by_id('lstCounty').send_keys(doc['country'])
            self.driver.find_element_by_id('txtPassport').send_keys(doc['identification_number'])
        time.sleep(1)
        self.driver.find_element_by_id("lnkSubmit").click()
        time.sleep(2)
        try:
            alert = self.driver.switch_to_alert()
            result.message = alert.text
            alert.accept()
        except:
            print "no alert to accept"
            soup = BeautifulSoup(self.driver.page_source, "lxml")
            #print soup._all_strings
            trs = soup.find('tr')
            for tr in trs:
                #print tr
                try:
                    self.result.message = tr.get_text()
                except:
                    pass


        if "successfuly deregistered" in result.message:
            result.processed= True
        else:
            result.processed = False

        return result
Beispiel #5
0
import json, time
from varmani.scripts.emailService import EmailService
from varmani.scripts.frappeclient import FrappeClient
import socket, select, string, sys
from varmani.scripts.messageService import MessageSerice

accessDetails = open('/home/hemant/access.txt')
aD = json.loads(accessDetails.read())

client = FrappeClient(aD['url'], aD['username'], aD['password'])
post = client.get_api("varmani.get_pi")
for pi in post:
    print(pi["name"])
    client.get_api("varmani.repost_pi","name="+pi["name"])