dominic 修订了这个 Gist . 转到此修订
1 file changed, 68 insertions
lh.py(文件已创建)
@@ -0,0 +1,68 @@ | |||
1 | + | #!/usr/bin/env python3 | |
2 | + | ||
3 | + | """ | |
4 | + | Author: Dominic OE7DRT <quick.hat4396@qtztsjosmprqmgtunjyf.com> | |
5 | + | """ | |
6 | + | ||
7 | + | """open the lastheard page on brandmeister | |
8 | + | """ | |
9 | + | ||
10 | + | import re, argparse, webbrowser | |
11 | + | ||
12 | + | def main(): | |
13 | + | """main function""" | |
14 | + | ||
15 | + | parser = argparse.ArgumentParser(description='Opens a last-heard table on Brandmeister in your browser') | |
16 | + | ||
17 | + | subparser = parser.add_subparsers(dest='selection') | |
18 | + | ||
19 | + | talkgroup = subparser.add_parser('tg') | |
20 | + | callsign = subparser.add_parser('call') | |
21 | + | dmrid = subparser.add_parser('id') | |
22 | + | ||
23 | + | talkgroup.add_argument('TG', help='Talkgroup', type=int) | |
24 | + | callsign.add_argument('CALLSIGN', help='Callsign', type=str) | |
25 | + | dmrid.add_argument('DMRID', help='DMR-ID (Integer)', type=int) | |
26 | + | ||
27 | + | args = parser.parse_args() | |
28 | + | ||
29 | + | if args.selection == 'tg': | |
30 | + | tg_pattern = re.compile("^([1-9]|[1-9][0-9]{1,6})$") | |
31 | + | if tg_pattern.match(str(args.TG)): | |
32 | + | url = 'https://brandmeister.network/?page=lh&DestinationID={}'.format(args.TG) | |
33 | + | #print(url) | |
34 | + | else: | |
35 | + | print("not a valid tg number:", args.TG) | |
36 | + | exit(1) | |
37 | + | ||
38 | + | elif args.selection == 'call': | |
39 | + | call_pattern = re.compile("^[a-zA-Z0-9]{1,3}[0123456789][a-zA-Z0-9]{0,2}[a-zA-Z]$") | |
40 | + | if call_pattern.match(str(args.CALLSIGN)): | |
41 | + | url = 'https://brandmeister.network/?page=lh&SourceCall={}'.format(args.CALLSIGN.upper()) | |
42 | + | #print(url) | |
43 | + | else: | |
44 | + | print("not a valid callsign:", args.CALLSIGN) | |
45 | + | exit(1) | |
46 | + | ||
47 | + | elif args.selection == 'id': | |
48 | + | dmrid_userid_pattern = re.compile("^[0-9]{7}$") | |
49 | + | dmrid_repeater_pattern = re.compile("^[0-9]{6}$") | |
50 | + | if dmrid_userid_pattern.match(str(args.DMRID)): | |
51 | + | url = 'https://brandmeister.network/?page=lh&SourceID={}'.format(args.DMRID) | |
52 | + | #print(url) | |
53 | + | elif dmrid_repeater_pattern.match(str(args.DMRID)): | |
54 | + | url = 'https://brandmeister.network/?page=lh&ContextID={}'.format(args.DMRID) | |
55 | + | #print(url) | |
56 | + | else: | |
57 | + | print("not a valid DMR-ID:", args.DMRID) | |
58 | + | exit(1) | |
59 | + | else: | |
60 | + | parser.print_help() | |
61 | + | exit(1) | |
62 | + | ||
63 | + | webbrowser.open(url, new=0, autoraise=True) | |
64 | + | #print(url) | |
65 | + | ||
66 | + | ||
67 | + | if __name__ == "__main__": | |
68 | + | main() |
上一页
下一页