-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (37 loc) · 1.17 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
51
52
53
import subprocess
import time
import os
import importlib.util
def check_dependencies():
packageNames = [ "scrapy", "scrapyrt", "requests" ]
unInstalledPackages = []
for pckg in packageNames:
package_spec = importlib.util.find_spec(pckg)
if package_spec is None:
unInstalledPackages.append(pckg)
return unInstalledPackages
def install_dependencies(unInstalledPackages):
for pckg in unInstalledPackages:
subprocess.run(['pip3', 'install', pckg])
def start_scrapyrt():
scrapyrt_process = subprocess.Popen(['scrapyrt'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
time.sleep(5)
return scrapyrt_process
def run_console_script():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
subprocess.run(['python3', 'flight-tracker.py'])
def main():
unInstalledPackages = check_dependencies()
if unInstalledPackages:
install_dependencies(unInstalledPackages)
scrapyrt_process = start_scrapyrt()
try:
run_console_script()
finally:
scrapyrt_process.terminate()
scrapyrt_process.wait()
if __name__ == "__main__":
main()