-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
67 lines (52 loc) · 1.88 KB
/
run.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
import os
from argparse import ArgumentParser, Namespace
from time import sleep
import schedule
from src import App
from src.config import CREDENTIAL
from src.models import OZON, WILDBERRIES
from src.utils import logger
from src.utils.logger import initialize_file_logger
def parse_args() -> Namespace:
parser = ArgumentParser()
parser.add_argument("-oz", "--ozon",
help="Parse Ozon",
action="store_true")
parser.add_argument("-wb", "--wildberries",
help="Parse Wildberries",
action="store_true")
parser.add_argument("-u", "--update-immediately",
help="Updates immediately, ignoring schedule",
action="store_true")
parser.add_argument("-b", "--binary",
help="Path to chrome binary",
type=str,
default=r"C:\Program Files\Google\Chrome\Application\chrome.exe")
parser.add_argument("-t", "--start-time",
help="Time to start updating",
type=str,
default=os.getenv("START_TIME", "00:00"))
return parser.parse_args()
def main() -> None:
args = parse_args()
if args.ozon:
marketplace = OZON
elif args.wildberries:
marketplace = WILDBERRIES
else:
logger.warning("No marketplace specified. Use -h for help")
return
initialize_file_logger(marketplace.name)
app = App(CREDENTIAL, marketplace, args.binary)
logger.debug("App initialized")
schedule.every().day.at(args.start_time).do(app.update)
if args.update_immediately:
app.update()
while True:
schedule.run_pending()
sleep(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
logger.info("Stopped by KeyboardInterrupt")