-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
117 lines (98 loc) · 3.38 KB
/
setup.py
File metadata and controls
117 lines (98 loc) · 3.38 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
import subprocess
import sys
import time
import os
def run_command(command):
"""Run a command and print the output"""
print(f"Running: {command}")
try:
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
universal_newlines=True
)
# Stream output
for line in process.stdout:
print(line.strip())
# Wait for process to complete
process.wait()
# Check return code
if process.returncode != 0:
print(f"Command failed with return code {process.returncode}")
for line in process.stderr:
print(line.strip())
return False
print(f"Command completed successfully")
return True
except Exception as e:
print(f"Error running command: {e}")
return False
def install_requirements():
"""Install requirements incrementally"""
# Basic requirements (should work on all systems)
basic_requirements = [
"requests",
"beautifulsoup4",
"Flask"
]
# Advanced requirements (may require compilation)
advanced_requirements = [
"Flask-RESTful",
"pandas",
"matplotlib",
"seaborn",
"nltk"
]
# Optional requirements (may be difficult to install)
optional_requirements = [
"scikit-learn",
"networkx"
]
# Install basic requirements
print("Installing basic requirements...")
for req in basic_requirements:
if not run_command(f"{sys.executable} -m pip install {req}"):
print(f"Failed to install {req}")
return False
# Install advanced requirements
print("\nInstalling advanced requirements...")
for req in advanced_requirements:
if not run_command(f"{sys.executable} -m pip install {req}"):
print(f"Failed to install {req}, but continuing...")
# Install optional requirements
print("\nInstalling optional requirements...")
for req in optional_requirements:
if not run_command(f"{sys.executable} -m pip install {req}"):
print(f"Failed to install {req}, but continuing...")
return True
def create_directories():
"""Create necessary directories"""
directories = [
"downloads",
"processed",
"advanced_processed",
"analysis_results",
"logs",
"templates",
"static"
]
for directory in directories:
if not os.path.exists(directory):
os.makedirs(directory)
print(f"Created directory: {directory}")
if __name__ == "__main__":
print("Setting up US Laws Processor...")
# Create directories
create_directories()
# Install requirements
if install_requirements():
print("\nSetup completed successfully!")
print("\nYou can now run the following commands:")
print(" python download_usc_releases.py --list # List available titles")
print(" python process_all_titles.py --title 1 # Download and process Title 1")
print(" python web_interface.py # Start the web interface")
print(" python api.py # Start the API")
else:
print("\nSetup failed. Please check the error messages above.")