forked from an1by/ZTEModemAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (43 loc) · 1.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import json
import modem
import utils
def main():
parser = argparse.ArgumentParser(description='ZTE MF79U API. (C) Aniby 2023.')
parser.add_argument('--file', metavar='F', help='Settings file in json format with "ip" and "password" keys.')
parser.add_argument('--ip', metavar='I', help='IP-address where hosts modem\'s GUI. By default: "192.168.0.1".')
parser.add_argument('--password', metavar='P', help='Password for modem\'s GUI. By default: "admin"')
parser.add_argument('--get', metavar='G', help='Data what you need from modem. Format: "attribute1 attribute2 &etc..."')
parser.add_argument('--debug', action=argparse.BooleanOptionalAction, help='Debug feature.')
args = parser.parse_args()
if (not args.get) or (len(args.get.split(' ')) <= 0):
utils.debug('Except data for get', "error", True)
return
dataToGet = args.get.split(' ')
if args.debug:
utils.debug_feature = True
if args.file:
with open(args.file, "r") as settings_file:
converted = json.load(settings_file);
if "ip" in converted:
modem.ip = converted["ip"]
if "password" in converted:
modem.password = converted["password"]
elif args.password or args.ip:
if args.password:
modem.password = args.password
if args.ip:
modem.ip = args.ip
else:
utils.debug('Except data for authorization', "error", True)
return
modem.auth(True)
if "sms_list" in dataToGet:
utils.debug(modem.getSMSList(), force=True)
dataToGet.remove("sms_list")
if "main_info" in dataToGet:
utils.debug(modem.getInfo(), force=True)
dataToGet.remove("main_info")
utils.debug(modem.getSomething(dataToGet), force=True)
if __name__ == '__main__':
main()