-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (29 loc) · 957 Bytes
/
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
import os
import time
from datetime import datetime
from multiprocessing import Process
from pathlib import Path
from dotenv import load_dotenv
from services.reporter import scraper_report
from services.utils import run_spider
load_dotenv()
def run_processes(spider):
p1 = Process(target=run_spider, args=[spider])
p2 = Process(target=scraper_report, args=[spider])
p1.start()
date = datetime.utcnow().date().isoformat()
while not Path(f"data/meta/{spider}-{date}.csv").exists():
time.sleep(5)
continue
while True:
with open(f"data/meta/{spider}-{date}.csv") as reader:
if len(reader.readlines()) > 0:
break
time.sleep(2)
p2.start()
def initialize_scraping_session():
spiders = os.environ.get("INSTALLED_SPIDERS", None).split(",")
for spider in spiders:
run_processes(spider)
if __name__ == "__main__":
initialize_scraping_session()