-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
141 lines (118 loc) Β· 4.51 KB
/
setup.py
File metadata and controls
141 lines (118 loc) Β· 4.51 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
#!/usr/bin/env python3
"""
setup.py - Setup script for PLUS Product Scraper
This script helps users configure the scraper for first-time use
"""
import os
import sys
import subprocess
from pathlib import Path
import shutil
def print_header():
print("\n" + "="*60)
print(" π PLUS PRODUCT SCRAPER SETUP")
print("="*60)
print("Welcome! This script will help you set up the PLUS Product Scraper.")
print("Please follow the steps below to get started.\n")
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 8):
print("β Python 3.8 or higher is required.")
print(f" Current version: {sys.version}")
return False
print(f"β
Python version: {sys.version.split()[0]}")
return True
def create_directories():
"""Create necessary directories"""
print("\nπ Creating directories...")
directories = [
"scraper/data",
"scraper/data/products",
"scraper/data/analysis",
"data/analysis/images"
]
for directory in directories:
Path(directory).mkdir(parents=True, exist_ok=True)
print(f" β
Created: {directory}")
def install_dependencies():
"""Install required Python packages"""
print("\nπ¦ Installing dependencies...")
# Install scraper dependencies
print(" Installing scraper requirements...")
try:
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "scraper/requirements.txt"],
check=True, capture_output=True)
print(" β
Scraper dependencies installed")
except subprocess.CalledProcessError as e:
print(f" β Failed to install scraper dependencies: {e}")
return False
# Install analysis dependencies
print(" Installing analysis requirements...")
try:
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements_analysis.txt"],
check=True, capture_output=True)
print(" β
Analysis dependencies installed")
except subprocess.CalledProcessError as e:
print(f" β Failed to install analysis dependencies: {e}")
return False
return True
def setup_environment():
"""Set up environment configuration"""
print("\nβοΈ Setting up environment...")
env_path = Path("scraper/.env")
env_example_path = Path("scraper/.env.example")
if env_path.exists():
print(" βΉοΈ .env file already exists")
response = input(" Do you want to overwrite it? (y/N): ").lower()
if response != 'y':
print(" βοΈ Skipping environment setup")
return True
if env_example_path.exists():
shutil.copy(env_example_path, env_path)
print(" β
Created .env from template")
print(" β οΈ IMPORTANT: You must configure your .env file!")
print(" See SECURITY.md and scraper/COOKIES.md for instructions")
else:
print(" β .env.example not found")
return False
return True
def show_next_steps():
"""Show next steps for the user"""
print("\nπ Setup completed successfully!")
print("\nπ NEXT STEPS:")
print("1. π Configure your credentials:")
print(" - Edit scraper/.env file")
print(" - Add your CSRF token from PLUS.nl")
print(" - Set up cookies (see scraper/COOKIES.md)")
print("\n2. π·οΈ Run the scraper:")
print(" cd scraper")
print(" python main.py --all --limit 50")
print("\n3. π Analyze the data:")
print(" python analyze_data.py")
print("\n4. π Read the documentation:")
print(" - README.md - Main documentation")
print(" - SECURITY.md - Security and setup guide")
print(" - scraper/COOKIES.md - Cookie setup guide")
print("\nβ οΈ REMEMBER: This tool is for educational purposes only.")
print(" Please respect PLUS.nl's terms of service!")
def main():
"""Main setup function"""
print_header()
# Check Python version
if not check_python_version():
return 1
# Create directories
create_directories()
# Install dependencies
if not install_dependencies():
print("\nβ Setup failed during dependency installation")
return 1
# Setup environment
if not setup_environment():
print("\nβ Setup failed during environment configuration")
return 1
# Show next steps
show_next_steps()
return 0
if __name__ == "__main__":
sys.exit(main())