fix: make scrape_media.py path resolution robust + include it in Nix build
Deploy Scraper / build-and-deploy (push) Canceled after 0s
Deploy Scraper / build-and-deploy (push) Canceled after 0s
- Nix flake now installs scrape_media.py to $out/bin so CI deploys it with the binary - run_playwright_scraper locates the script alongside the running binary (Nix store), the Cargo manifest dir (dev), /home/code/scraper, or $SCRAPER_SCRIPT_DIR - Fix var_os() Option match
This commit is contained in:
@@ -39,6 +39,8 @@
|
|||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
cp target/release/scraper $out/bin/scraper
|
cp target/release/scraper $out/bin/scraper
|
||||||
|
cp $src/scrape_media.py $out/bin/scrape_media.py
|
||||||
|
chmod +x $out/bin/scrape_media.py
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -175,8 +175,25 @@ async fn run_playwright_scraper(
|
|||||||
url: &str,
|
url: &str,
|
||||||
platform: &str,
|
platform: &str,
|
||||||
) -> Result<serde_json::Value, ScrapingError> {
|
) -> Result<serde_json::Value, ScrapingError> {
|
||||||
let script = env!("CARGO_MANIFEST_DIR");
|
// Locate scrape_media.py robustly: alongside the running binary (Nix store),
|
||||||
let scraper_script = format!("{}/scrape_media.py", script);
|
// the Cargo manifest dir (dev), or a few well-known absolute paths.
|
||||||
|
let exe_dir = std::env::current_exe()
|
||||||
|
.ok()
|
||||||
|
.and_then(|p| p.parent().map(|d| d.to_path_buf()));
|
||||||
|
let manifest_script = format!("{}/scrape_media.py", env!("CARGO_MANIFEST_DIR"));
|
||||||
|
let mut candid = vec![
|
||||||
|
exe_dir.map(|d| d.join("scrape_media.py").to_string_lossy().to_string()),
|
||||||
|
Some(manifest_script),
|
||||||
|
Some("/home/code/scraper/scrape_media.py".to_string()),
|
||||||
|
];
|
||||||
|
if let Some(rel) = std::env::var_os("SCRAPER_SCRIPT_DIR") {
|
||||||
|
candid.push(Some(format!("{}/scrape_media.py", rel.to_string_lossy())));
|
||||||
|
}
|
||||||
|
let scraper_script = candid
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.find(|p| std::path::Path::new(p).exists())
|
||||||
|
.ok_or_else(|| ScrapingError::Http("scrape_media.py not found".to_string()))?;
|
||||||
|
|
||||||
// Find a Python interpreter that has playwright installed.
|
// Find a Python interpreter that has playwright installed.
|
||||||
// The system `python3` may resolve to a different interpreter for the
|
// The system `python3` may resolve to a different interpreter for the
|
||||||
|
|||||||
Reference in New Issue
Block a user