forked from jorhelp/Ingram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_ingram.py
executable file
·68 lines (58 loc) · 2.2 KB
/
run_ingram.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python3
# coding: utf-8
# @Auth: Jor<[email protected]>
# @Date: Wed Apr 20 00:17:30 HKT 2022
# @Desc: Ingram
from gevent import monkey; monkey.patch_all(thread=False)
import os
from Ingram.utils import config
from Ingram.utils import logo
from Ingram.utils import color
from Ingram.utils import wx_send
from Ingram.utils import get_parse
from Ingram.utils import logger, config_logger
from Ingram.core import Core
def assemble_config(args):
#------- user defined configuration ------
config.WXUID = '' # weechat uid
config.WXTOKEN = '' # weechat token
#----------------- end -------------------
config.IN = args.in_file
config.OUT = args.out_dir
config.TH = args.th_num
config.DEBUG = args.debug
config.TIMEOUT = args.time_out
config.LOGFILE = os.path.join(config.OUT, 'log.txt') # log file
if args.port:
config.PORT = args.port
if not os.path.isfile(config.IN):
print(f"{color.red('the input file')} {color.yellow(config.IN)} {color.red('does not exists!')}")
exit(0)
if os.path.isfile(config.OUT):
print(f"{color.yellow(config.OUT)} {color.red('is a file, please use another name')}")
exit(0)
# mk out dir, and the config_logger will be success
if not os.path.isdir(config.OUT):
os.mkdir(config.OUT)
config_logger(config.LOGFILE, config.DEBUG) # logger configuration
if __name__ == '__main__':
try:
# logo
for icon, font in zip(*logo):
print(f"{color.yellow(icon, 'bright')} {color.magenta(font, 'bright')}")
assemble_config(get_parse()) # assemble global config vars
core = Core() # get ingram core
core() # run
logger.info('Ingram done!')
if config.WXUID and config.WXTOKEN:
try:
wx_send('Ingram done!')
except Exception as e:
logger.error(e)
except KeyboardInterrupt as e:
exit(0)
except Exception as e:
logger.warning(e)
print(f"{color.red('error occurred, see the')} {color.yellow(config.LOGFILE)} "
f"{color.red('for more information.')}")
exit(0)