def launchurl(self): global session, service, oneurl with open("config.ini", "r+") as f: f.seek(0) d = f.readlines() #print(d) for i in d: if "url=" + oneurl + '\n' not in i: f.write(i) f.write("url=" + self.textEntryVar.get() + "\n") f.truncate() try: url = str(self.textEntryVar.get()) ip = IPv4Address(url) # let's create an IP address object # now create a session session = AirmoreSession(ip) # if your port is not 2333 # session = AirmoreSession(ip, 2334) # assuming it is 2334 was_accepted = session.request_authorization() if was_accepted == True: self.nstatus['text'] = "Connected to Phone!" self.nstatus['fg'] = "blue" service = MessagingService(session) except Exception as e: self.nstatus['text'] = "IP Address Error!" self.nstatus['fg'] = "red"
def send_sms_message(self, number, message): # now create a session logging.info("Trying connecting AirMore on Android Device (" + self.get_srv_info() + ")") session = AirmoreSession(self.amipaddr, self.amport) if not session.is_server_running: logging.error("AirMore is not Running on Android Device (" + self.get_srv_info() + ")") sys.exit(1) logging.info("AirMore is Running on Android Device (" + self.get_srv_info() + ")") was_accepted = session.request_authorization() if not was_accepted: logging.error("AirMore is rejecting session on Android Device (" + self.get_srv_info() + ")") sys.exit(2) logging.error("AirMore is accpeting this session on Android Device (" + self.get_srv_info() + ")") service = MessagingService(session) logging.info("Sending to " + number + " message: " + message) service.send_message(number, message) logging.info("Message sent to " + number)
def connecting(self): try: ip = str(self.ip_input.text()) port = int(self.port_input.text()) ip4 = IPv4Address(ip) session = AirmoreSession(ip4, port) if session.is_server_running: self.status_connection.append("server is up") if session.request_authorization(): self.status_connection.append("you are connect to phone") except: self.status_connection.append("check the connection")
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
def cellphone(verbose: bool = False): ip = userinput("Airmore cellphone ip", validator="ip", always_use_default=True, maximum_attempts=1) if ip is None: ip = userinput("Airmore cellphone ip", validator="ip") device_ip = IPv4Address(ip) session = AirmoreSession(device_ip) if verbose: print("I'm going to connect with your cellphone!") print("Open up Airmore!") if (session.request_authorization()): return session raise ValueError( "Unable to connect to device, you might need to restart AirMore!")
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
class SmsSender: def __init__(self, ip, port): try: self.__session = AirmoreSession(IPv4Address(ip), port) self.__service = MessagingService(self.__session) accepted = self.__session.request_authorization() if not accepted: raise Exception(f'Autorizzazione non accettata') except Exception as e: print(f'Error: {e}') def send(self, receiver, content): try: self.__service.send_message(receiver, content) except Exception as e: print(f'Error: {e}') def send_all(self, rows): counter = 1 sleep_each = 10 sleep_second = 5 for row in rows: if counter % sleep_each == 0: print("sleep") sleep(sleep_second) data = dict(row) # self.send(data['Cellulare'], f"Sono disponibili {data['Pronti']} libri su {data['Totale']}") self.send( '3356760194', f"Sono disponibili {data['Pronti']} libri su {data['Totale']}") counter += 1 print("FINITO") def close(self): self.__session.close()
from pyairmore.services.messaging import MessagingService # to send messages from flask import Flask, render_template,abort,request from pymongo import MongoClient import requests import json from datetime import datetime import os app = Flask(__name__) ip = IPv4Address("192.168.0.144") # let's create an IP address object # now create a session session = AirmoreSession(ip) #authorization was_accepted = session.request_authorization() #sendign messages service = MessagingService(session) @app.route("/",methods=["GET"]) def main(): return render_template("broadcast.html") @app.route("/send_weather",methods=["POST"]) def weather_update(): #send village_id = request.get_json()["village_id"] #getting the data from the broadcast website filee_read = open("village_database/{}.txt".format(village_id),"r") numbers = filee_read.read().split(",") message = "WEATHER UPDATE BROADCAST MESSAGE: MAX TEMP:32C, MIN TEMP:28C,LOW CHANCES OF RAIN." for i in numbers: service.send_message(i,message)
from ipaddress import IPv4Address from pyairmore.request import AirmoreSession from pyairmore.services.messaging import MessagingService import sys ip = IPv4Address(f'{sys.argv[1]}') session = AirmoreSession(ip, 2333) print(session.is_server_running) req_authorization = session.request_authorization() service = MessagingService(session) service.send_message(f'+91{sys.argv[2]}', f'{sys.argv[3]}')
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)