diff --git a/.gitignore b/.gitignore index 85e7c1d..17fecdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /.idea/ +__pycache__ +.~contact.xlsx \ No newline at end of file diff --git a/commandor.py b/commandor.py new file mode 100644 index 0000000..1df0123 --- /dev/null +++ b/commandor.py @@ -0,0 +1,30 @@ +import subprocess + +PACKAGE_NAME = "com.lpa.appointement" +ACTIVITY_NAME = "MainActivity" + + +class Commandor: + + def __init__(self): + pass + + def reload_page(self): + # specifying an explicit component name + self.clear_app_data() + subprocess.call("adb shell am start -n {}/.{}".format(PACKAGE_NAME, ACTIVITY_NAME), shell=True) + pass + + def clear_app_data(self): + subprocess.call("adb shell pm clear {}".format(PACKAGE_NAME), shell=True) + + def send_telephone_number(self): + pass + + def send_otp(self): + pass + + +if __name__ == '__main__': + commandor = Commandor() + commandor.reload_page() diff --git a/contact.xlsx b/contact.xlsx new file mode 100644 index 0000000..e7945f0 Binary files /dev/null and b/contact.xlsx differ diff --git a/excel_reader.py b/excel_reader.py new file mode 100644 index 0000000..4cb2c16 --- /dev/null +++ b/excel_reader.py @@ -0,0 +1,30 @@ +import json + +import pandas as pandas + +from pojo.contact_pojo import ContactPojo + + +class ExcelReader: + # read the contact list from the exel file + def read_file(self) -> list: + contact_list_in_json = pandas.read_excel(r'./contact.xlsx').to_json(orient='records') + contact_dict_list = json.loads(contact_list_in_json) + contact_list = [] + for contact_dict in contact_dict_list: + name = contact_dict['name'].split(' ') + first_name = name[0] + last_name = name[-1] + contact = ContactPojo(phone_number=contact_dict['phone'], + last_name=last_name, + first_name=first_name, + ccid=contact_dict['ccid'], + passport_number=contact_dict['passport']) + contact_list.append(contact) + return contact_list + + +if __name__ == '__main__': + reader = ExcelReader() + data = reader.read_file() + print(data) diff --git a/main.py b/main.py index 6e98af5..2e3b040 100644 --- a/main.py +++ b/main.py @@ -1,23 +1,48 @@ +import logging + import serial from gsmmodem import GsmModem from gsmmodem.modem import SentSms +from utils.logging import init_logger + PORT = "/dev/tty.usbmodem11101" BAUDRATE = 115200 -ser = serial.Serial(PORT, BAUDRATE, timeout=1) -def has_sim() -> bool: +# ser = serial.Serial(PORT, BAUDRATE, timeout=1) + + +def get_devices_ports() -> list: + return ["/dev/tty.usbmodem1121101", + "/dev/tty.usbmodem1121103", + "/dev/tty.usbmodem1121105", + "/dev/tty.usbmodem1121107", + "/dev/tty.usbmodem1121201", + "/dev/tty.usbmodem1121203", + "/dev/tty.usbmodem1121205", + "/dev/tty.usbmodem1121207", + "/dev/tty.usbmodem1121301", + # "/dev/tty.usbmodem1121303", + "/dev/tty.usbmodem1121305", + "/dev/tty.usbmodem1121307", + "/dev/tty.usbmodem1121401", + "/dev/tty.usbmodem1121403", + "/dev/tty.usbmodem1121405", + "/dev/tty.usbmodem1121407"] + + +def has_sim(ser) -> bool: # check pin cmd_check_pin = "AT+cpin?\r" - msg = send_command(cmd_check_pin) + msg = send_command(cmd_check_pin, ser) if b'OK' in msg: return True else: return False -def send_command(cmd: str) -> bytes: +def send_command(cmd: str, ser) -> bytes: print("send command {}".format(cmd)) ser.write(cmd.encode()) msg = ser.read(100) @@ -25,6 +50,16 @@ def send_command(cmd: str) -> bytes: return msg +def get_phone_number(): + cmd = "AT+CNUM\r" + send_command(cmd) + + +def get_sim_ccid(): + cmd = "AT+CCID\r" + send_command(cmd) + + def send_sms(sms_destination: str, msg: str): print('Initializing modem...') modem = GsmModem(PORT, BAUDRATE) @@ -41,11 +76,51 @@ def send_sms(sms_destination: str, msg: str): modem.close() +def create_modem_for_port(port: str) -> GsmModem: + print('Initializing modem... for ' + port) + # Uncomment the following line to see what the modem is doing: + init_logger() + modem = GsmModem(port, BAUDRATE) + modem.connect('0000') + number = modem.ownNumber + print("The SIM card phone number is:") + print(number) + cmd = "AT+CCID\r" + ccid = modem.write(cmd, True) + print("The SIM card ccid is:" + " ".join(ccid)) + return modem + + +def start_to_handle_sms(modem: GsmModem): + modem.smsReceivedCallback = handle_sms + # modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handle_sms) + modem.smsTextMode = False + # modem.connect('0000') + print('Waiting for SMS message...') + try: + modem.rxThread.join( + 2 ** 31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal + finally: + modem.close() + + +def handle_sms(sms): + print(u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text)) + + if __name__ == '__main__': - # enable verbose logs - cmd = "AT+CMEE=2\r" - send_command(cmd) - if has_sim(): - send_sms("+33649614591","Modem pool test") - else: - print("no cart sim") + # enable verbose logs for all port + # create modems for all the available port + modem_list = [] + for port in get_devices_ports(): + modem_list.append(create_modem_for_port(port)) + # cmd = "AT+CMEE=2\r" + # send_command(cmd) + + # if has_sim(): + # # send_sms("+33649614591", "Modem pool test") + # modem = show_own_phone_number() + # get_sim_ccid() + # # start_to_handle_sms(modem) + # else: + # print("no cart sim") diff --git a/pojo/__init__.py b/pojo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pojo/__pycache__/__init__.cpython-39.pyc b/pojo/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..c9fcfb6 Binary files /dev/null and b/pojo/__pycache__/__init__.cpython-39.pyc differ diff --git a/pojo/__pycache__/contact_pojo.cpython-39.pyc b/pojo/__pycache__/contact_pojo.cpython-39.pyc new file mode 100644 index 0000000..edc9673 Binary files /dev/null and b/pojo/__pycache__/contact_pojo.cpython-39.pyc differ diff --git a/pojo/contact_pojo.py b/pojo/contact_pojo.py new file mode 100644 index 0000000..e97c0e5 --- /dev/null +++ b/pojo/contact_pojo.py @@ -0,0 +1,17 @@ +from dataclasses import dataclass + + +@dataclass +class ContactPojo: + phone: str + passport: str + last_name: str + first_name: str + ccid: str + + def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, ccid: str): + self.phone = phone_number + self.passport = passport_number + self.last_name = last_name + self.first_name = first_name + self.ccid = ccid diff --git a/pojo/serial_modem.py b/pojo/serial_modem.py new file mode 100644 index 0000000..9b3590e --- /dev/null +++ b/pojo/serial_modem.py @@ -0,0 +1,10 @@ +from gsmmodem import GsmModem + + +class SerialModem(): + ccid: str + phone_number: str + modem: GsmModem + + def __init__(self, modem: GsmModem): + self.modem = modem diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/logging.py b/utils/logging.py new file mode 100644 index 0000000..0d3936c --- /dev/null +++ b/utils/logging.py @@ -0,0 +1,9 @@ +import logging + + +def init_logger(): + logging.basicConfig(filename="scrapy.log", + filemode='a', + format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', + datefmt='%D:%H:%M:%S', + level=logging.DEBUG)