Skip to content

Commit

Permalink
Merge pull request #4 from gnosischain/feat/ui-revamp
Browse files Browse the repository at this point in the history
feat: add back python script
  • Loading branch information
Wagalidoom authored Nov 21, 2024
2 parents 5720158 + 37d8fb5 commit 4851d27
Show file tree
Hide file tree
Showing 5 changed files with 526 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/generateYmal.js
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();
1 change: 1 addition & 0 deletions src/scripts/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEMINI_API_KEY
6 changes: 6 additions & 0 deletions src/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requests
pyyaml
beautifulsoup4
html2text
google-generativeai
python-dotenv
22 changes: 22 additions & 0 deletions src/scripts/setup_environment.sh
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."
Loading

0 comments on commit 4851d27

Please sign in to comment.