class Airmore_SMS_handler(object): def __init__(self, phone_IP, send_number): self.__send_number = format_phone_number(send_number) self.__session = AirmoreSession(IPv4Address(phone_IP)) self.__correct_direction = lambda x: x.type == MessageType.RECEIVED assert self.__session.is_server_running assert self.__session.request_authorization() self.__service = MessagingService(self.__session) self.__initialization_time = datetime.datetime.now() self.__chat_id = None self.__chat_id = self.__get_chat_id() self.__buffer = b'' self.__already_read = set() # Add new messages to already read... self.get_new_messages() def send(self, message): assert isinstance(message, str) self.__service.send_message(self.__send_number, message) def get_new_messages(self): chat_id = self.__get_chat_id() new_messages = [] if chat_id != None: messages = self.__service.fetch_chat_history(message_or_id=chat_id, limit=50) for message in messages: if self.__correct_direction(message) and not (message.id, message.content) in self.__already_read: new_messages.append(message.content) self.__already_read = set((message.id, message.content) for message in messages) return new_messages def __get_chat_id(self): if self.__chat_id != None: return self.__chat_id for message in self.__service.fetch_message_history(): if format_phone_number(message.phone) == self.__send_number: self.__chat_id = message.id return self.__chat_id @staticmethod def create_test_connection(): handler1 = Airmore_SMS_handler('192.168.1.22', '8016605023') handler2 = Airmore_SMS_handler('192.168.1.23', '8016436371') return handler1, handler2
def waitForPasscodeLabel(self, method): global PIN_CODE session = AirmoreSession(IPv4Address(str(config.core['airmore_server']))) # also you can put your port as int, airmore's port default is 2333 session.is_server_running # True session.request_authorization() # True if accepted, False if denied service = MessagingService(session) messages = service.fetch_message_history() pattern = "HSBC: Verification code is (\D{4}-)(\d{6})" for msg in messages: group = re.findall(pattern, msg.content) if len(group) > 0 and len(group[0]) > 0: if group[0][0] == str(self.driver.find_element(By.ID, "passcodelabel").text): PIN_CODE = str(group[0][1]) return True return False
def waitForPasscodeLabel(self, method): global PIN_CODE session = AirmoreSession(IPv4Address(str(config.core['airmore_server']))) # also you can put your port as int, airmore's port default is 2333 session.is_server_running # True session.request_authorization() # True if accepted, False if denied service = MessagingService(session) messages = service.fetch_message_history() pattern = "For your online transaction, please use this MasterCard SecureCode One-Time Password: (\w{4})-(\d{6})" for msg in messages: group = re.findall(pattern, msg.content) if len(group) > 0 and len(group[0]) > 0: if group[0][0] == str(self.driver.find_element(By.CSS_SELECTOR , "#pwdpage > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(9) > td:nth-child(2) > span:nth-child(2)").text): PIN_CODE = str(group[0][1]) return True return False
class OTP: def __init__(self, ip): self.ip = IPv4Address(ip) self.session = AirmoreSession(self.ip) self.messageService = MessagingService(self.session) self.otpStart = 'Your OTP to register/access CoWIN is' def getOTP(self, retries=5, delay=5): for _ in range(retries): messages = self.messageService.fetch_message_history() rangenum = 3 for i in range(rangenum): messageTime = messages[i].datetime messageTime += datetime.timedelta(minutes=3) if messageTime > datetime.datetime.now(): if messages[i].content.startswith(self.otpStart): return re.findall(r'[0-9]{6}', messages[i].content) else: rangenum -= 1 if delay: time.sleep(delay) return None
#page2 phone verification functionality driver.find_element_by_xpath(inputPhoneNo_xpath).send_keys(phoneNumber) driver.find_element_by_xpath(phoneNext_xpath).click() sleep(25) print("here") #getting text from phone using pyairmore ip = IPv4Address( "192.168.0.27" ) # whatever server's address is(press the three dots at top right corner of airmore apk to get this) session = AirmoreSession(ip) # port is default to 2333 txt_service = MessagingService(session) messages = txt_service.fetch_message_history() OTP_message = messages[0].content # "latest Message" OTP_code = findnum(r'\d+', OTP_message) driver.find_element_by_xpath(otpInput_xpath).send_keys(OTP_code) driver.find_element_by_xpath(OTPverify_xpath).click() sleep(15) #page3 Bio info functionality driver.find_element_by_xpath(birthDate_xpath).send_keys(1) dropMonth = Select(driver.find_element_by_xpath(birthMonthDrop_xpath)) dropMonth.select_by_value('2') driver.find_element_by_xpath(birthYear_xpath).send_keys(i.dob) dropGender = Select(driver.find_element_by_xpath(genderDrop_xpath)) dropGender.select_by_value('3') #Rather not say for gender
import openpyxl from openpyxl import Workbook from openpyxl import load_workbook def printm(str1): for i in str1: print(i ,end="") bekle(0.03) print(end="\n") ip = IPv4Address("192.168.1.4") session = AirmoreSession(ip) was_accepted = session.request_authorization() service = MessagingService(session) messages = service.fetch_message_history() cikart_phone = [] cikart_content = [] for i in range(0,len(messages)): if(messages[i].was_read == False): cikart_phone.append(str(messages[i].phone)) cikart_content.append(str(messages[i].content)) filepath = "C:/Users/mfurk/Desktop/SMS GÖNDERME/deneme.xlsx" xl = pd.ExcelFile(filepath) df = xl.parse("Merhaba", header=None) df.columns = ['A','B'] for i in cikart_phone: if(i[0] != "+"):
class Wedding(): def __init__(self): self.loc = (FILENAME) self.ip = IPv4Address(IP_ADDRESS) self.session = AirmoreSession(self.ip) self.was_accepted = self.session.request_authorization() if (self.was_accepted): print("Connection Established") else: print("Connection Error! please verify ip address") exit() self.service = MessagingService(self.session) #Open Excel self.rb = xlrd.open_workbook(self.loc) self.sheet = self.rb.sheet_by_index(0) self.wb = copy(self.rb) self.w_sheet = self.wb.get_sheet(0) self.createGuestListDict() self.sendInvitationList() self.checkRecieve() self.createArrivedGuestsDict() self.sendThankYou() def getConfirmedGuests(self): column_sum = 0 for row in range(self.sheet.nrows): try: column_sum += self.sheet.cell_value(row, 4) except: pass return int(column_sum) def createArrivedGuestsDict(self): arrived_guests = 0 self.guest_dict = {} for i in range(1, self.sheet.nrows): try: if ((self.sheet.cell_value(i, 12)>0) and (len(self.sheet.cell_value(i, 2))==10)): #Person did not response and phone number is defined in list phone_number = self.sheet.cell_value(i, 2) phone_number = COUNTRY_AREA_CODE + phone_number[1:len(phone_number)] self.guest_dict[phone_number] = i arrived_guests += self.sheet.cell_value(i, 10) except: pass print("Total Arrived Guests - ", arrived_guests) def createGuestListDict(self): not_resp = 0 self.guest_dict = {} for i in range(0, self.sheet.nrows): if ((self.sheet.cell_value(i, 9)=="לא הגיב") and (len(self.sheet.cell_value(i, 2))==10)): #Person did not response and phone number is defined in list phone_number = self.sheet.cell_value(i, 2) phone_number = COUNTRY_AREA_CODE + phone_number[1:len(phone_number)] self.guest_dict[phone_number] = i not_resp += 1 print("Total Rows - ", self.sheet.nrows, "Did not responed - ", not_resp, " confirmed guests - ", self.getConfirmedGuests()) def checkRecieve(self): while True: messages = self.service.fetch_message_history() for i in range(0,20): #Check only last 20 messages #Update person with the retuned number of SMS try: print(messages[i].phone) print("Recieved Message from - ", messages[i].phone, " number of confirmed guests - ", int(messages[i].content)) if ((messages[i].phone in self.guest_dict) and (self.sheet.cell_value(self.guest_dict[messages[i].phone], 9)=="לא הגיב")): print("Guest Confirmed!! Recieved Message from - ", messages[i].phone, " number of confirmed guests - ", int(messages[i].content)) self.w_sheet.write(self.guest_dict[messages[i].phone], 10, messages[i].content) self.w_sheet.write(self.guest_dict[messages[i].phone], 9, "מגיע") if (int(messages[i].content)>0): print("Send Transportation") print(messages[i].phone, TRANSPORTATION) if DEBUG else self.service.send_message(messages[i].phone, TRANSPORTATION) self.wb.save('Wedding.xlsx') except: pass time.sleep(0.2) def sendThankYou(self): print("Do you want to send THANK YOU SMS? \n") choice = input().lower() if (choice=="yes"): print ("Sending SMS") #Send SMS for i in self.guest_dict: print("Send SMS to - ", i) name = self.sheet.cell_value(self.guest_dict[i], 0) msg_to_send = name + ",\n" + THANK_YOU print(msg_to_send) if DEBUG else self.service.send_message(i, msg_to_send) time.sleep(2) def sendInvitationList(self): print("Do you want to send INVITATION SMS? \n") choice = input().lower() if (choice=="yes"): print ("Sending SMS") for i in self.guest_dict: print("Send SMS to - ", i) print(INVITE_REMINDER) if DEBUG else self.service.send_message(i, INVITE) time.sleep(1) def sendInvitationReminderAllList(self): print("Do you want to send INVITATION REMINDER SMS? \n") choice = input().lower() if (choice=="yes"): print ("Sending SMS") for i in self.guest_dict: print("Send SMS to - ", i) print(INVITE_REMINDER) if DEBUG else self.service.send_message(i, INVITE_REMINDER) time.sleep(1)