add excel reader
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
|
__pycache__
|
||||||
|
.~contact.xlsx
|
||||||
@@ -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()
|
||||||
Binary file not shown.
@@ -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)
|
||||||
@@ -1,23 +1,48 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
from gsmmodem import GsmModem
|
from gsmmodem import GsmModem
|
||||||
from gsmmodem.modem import SentSms
|
from gsmmodem.modem import SentSms
|
||||||
|
|
||||||
|
from utils.logging import init_logger
|
||||||
|
|
||||||
PORT = "/dev/tty.usbmodem11101"
|
PORT = "/dev/tty.usbmodem11101"
|
||||||
BAUDRATE = 115200
|
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
|
# check pin
|
||||||
cmd_check_pin = "AT+cpin?\r"
|
cmd_check_pin = "AT+cpin?\r"
|
||||||
msg = send_command(cmd_check_pin)
|
msg = send_command(cmd_check_pin, ser)
|
||||||
if b'OK' in msg:
|
if b'OK' in msg:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def send_command(cmd: str) -> bytes:
|
def send_command(cmd: str, ser) -> bytes:
|
||||||
print("send command {}".format(cmd))
|
print("send command {}".format(cmd))
|
||||||
ser.write(cmd.encode())
|
ser.write(cmd.encode())
|
||||||
msg = ser.read(100)
|
msg = ser.read(100)
|
||||||
@@ -25,6 +50,16 @@ def send_command(cmd: str) -> bytes:
|
|||||||
return msg
|
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):
|
def send_sms(sms_destination: str, msg: str):
|
||||||
print('Initializing modem...')
|
print('Initializing modem...')
|
||||||
modem = GsmModem(PORT, BAUDRATE)
|
modem = GsmModem(PORT, BAUDRATE)
|
||||||
@@ -41,11 +76,51 @@ def send_sms(sms_destination: str, msg: str):
|
|||||||
modem.close()
|
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__':
|
if __name__ == '__main__':
|
||||||
# enable verbose logs
|
# enable verbose logs for all port
|
||||||
cmd = "AT+CMEE=2\r"
|
# create modems for all the available port
|
||||||
send_command(cmd)
|
modem_list = []
|
||||||
if has_sim():
|
for port in get_devices_ports():
|
||||||
send_sms("+33649614591","Modem pool test")
|
modem_list.append(create_modem_for_port(port))
|
||||||
else:
|
# cmd = "AT+CMEE=2\r"
|
||||||
print("no cart sim")
|
# 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")
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user