-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from gnosischain/feat/ui-revamp
feat: add back python script
- Loading branch information
Showing
5 changed files
with
526 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { spawn } from 'child_process'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import fs from 'fs'; | ||
|
||
// Convert the URL path of the current module to a directory path | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
// Execute the Python script | ||
const runPythonScript = () => { | ||
// Path to the Python executable in the virtual environment | ||
const pythonExecutable = path.join(__dirname, 'scripts/gip_scraper/bin/python'); | ||
|
||
// Log file paths | ||
const stdoutLog = path.join(__dirname, 'logs/python_stdout.log'); | ||
const stderrLog = path.join(__dirname, 'logs/python_stderr.log'); | ||
|
||
// Ensure log directory exists | ||
fs.mkdirSync(path.join(__dirname, 'logs'), { recursive: true }); | ||
|
||
// Spawn the Python process using the virtual environment's Python executable | ||
const pythonProcess = spawn(pythonExecutable, ['src/scripts/snapshot_crawler.py']); | ||
|
||
// Handle standard output | ||
pythonProcess.stdout.on('data', (data) => { | ||
console.log(data.toString()); | ||
fs.appendFileSync(stdoutLog, data); | ||
}); | ||
|
||
// Handle error output | ||
pythonProcess.stderr.on('data', (data) => { | ||
console.error(data.toString()); | ||
fs.appendFileSync(stderrLog, data); | ||
}); | ||
|
||
// Handle process exit | ||
pythonProcess.on('close', (code) => { | ||
console.log(`Python script exited with code ${code}`); | ||
}); | ||
}; | ||
|
||
runPythonScript(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEMINI_API_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
requests | ||
pyyaml | ||
beautifulsoup4 | ||
html2text | ||
google-generativeai | ||
python-dotenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
# Get the directory where the script is located | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
|
||
# Setup or confirm virtual environment | ||
ENV_DIR="$SCRIPT_DIR/gip_scraper" | ||
if [ ! -d "$ENV_DIR" ]; then | ||
echo "Setting up a new Python virtual environment..." | ||
python3 -m venv "$ENV_DIR" | ||
else | ||
echo "Using existing virtual environment." | ||
fi | ||
|
||
# Activate the virtual environment | ||
source "$ENV_DIR/bin/activate" | ||
|
||
# Install or update dependencies | ||
echo "Installing requirements from requirements.txt..." | ||
pip install -r "$SCRIPT_DIR/requirements.txt" | ||
|
||
echo "Environment setup is complete." |
Oops, something went wrong.