-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all.py
More file actions
178 lines (146 loc) · 5.21 KB
/
run_all.py
File metadata and controls
178 lines (146 loc) · 5.21 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import argparse
import logging
import os
import sys
import time
from pathlib import Path
import subprocess
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(),
logging.FileHandler('run_all.log')
]
)
logger = logging.getLogger('run_all')
def run_command(command, description):
"""Run a command and log the output"""
logger.info(f"Running: {description}")
logger.info(f"Command: {command}")
try:
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
universal_newlines=True
)
# Stream output
for line in process.stdout:
logger.info(line.strip())
# Wait for process to complete
process.wait()
# Check return code
if process.returncode != 0:
logger.error(f"Command failed with return code {process.returncode}")
for line in process.stderr:
logger.error(line.strip())
return False
logger.info(f"Command completed successfully")
return True
except Exception as e:
logger.error(f"Error running command: {e}")
return False
def setup_environment():
"""Set up the environment"""
logger.info("Setting up environment...")
# Create directories
directories = [
"downloads",
"processed",
"advanced_processed",
"analysis_results",
"logs"
]
for directory in directories:
Path(directory).mkdir(exist_ok=True)
# Install requirements
run_command("pip install -r requirements.txt", "Installing requirements")
def download_titles(title_num=None):
"""Download titles"""
if title_num:
logger.info(f"Downloading Title {title_num}...")
return run_command(f"python process_all_titles.py --title {title_num}", f"Downloading Title {title_num}")
else:
logger.info("Downloading all titles...")
return run_command("python process_all_titles.py --all", "Downloading all titles")
def process_titles():
"""Process downloaded titles"""
logger.info("Processing titles...")
return run_command("python usc_processor.py", "Processing titles")
def run_advanced_processing():
"""Run advanced processing"""
logger.info("Running advanced processing...")
return run_command("python advanced_processor.py", "Advanced processing")
def run_data_analysis():
"""Run data analysis"""
logger.info("Running data analysis...")
return run_command("python data_analysis.py", "Data analysis")
def start_web_interface():
"""Start the web interface"""
logger.info("Starting web interface...")
return run_command("start python web_interface.py", "Web interface")
def start_api():
"""Start the API"""
logger.info("Starting API...")
return run_command("start python api.py", "API")
def setup_scheduled_updates():
"""Set up scheduled updates"""
logger.info("Setting up scheduled updates...")
return run_command("python scheduled_updates.py --setup", "Scheduled updates")
def run_all(args):
"""Run all components"""
# Set up environment
setup_environment()
# Download titles
if args.download:
if args.title:
download_titles(args.title)
else:
download_titles()
# Process titles
if args.process:
process_titles()
# Run advanced processing
if args.advanced:
run_advanced_processing()
# Run data analysis
if args.analysis:
run_data_analysis()
# Start web interface
if args.web:
start_web_interface()
# Start API
if args.api:
start_api()
# Set up scheduled updates
if args.schedule:
setup_scheduled_updates()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Run all components of the US Laws Processor')
parser.add_argument('--download', action='store_true', help='Download titles')
parser.add_argument('--title', type=int, help='Download a specific title')
parser.add_argument('--process', action='store_true', help='Process titles')
parser.add_argument('--advanced', action='store_true', help='Run advanced processing')
parser.add_argument('--analysis', action='store_true', help='Run data analysis')
parser.add_argument('--web', action='store_true', help='Start web interface')
parser.add_argument('--api', action='store_true', help='Start API')
parser.add_argument('--schedule', action='store_true', help='Set up scheduled updates')
parser.add_argument('--all', action='store_true', help='Run all components')
args = parser.parse_args()
# If --all is specified, run everything
if args.all:
args.download = True
args.process = True
args.advanced = True
args.analysis = True
args.web = True
args.api = True
args.schedule = True
# If no arguments are specified, show help
if not any(vars(args).values()):
parser.print_help()
else:
run_all(args)