mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-22 14:16:19 +00:00
bringup farmacity
This commit is contained in:
parent
d1d496514c
commit
1118bcf75d
6 changed files with 64 additions and 0 deletions
|
@ -3,25 +3,31 @@ export enum Supermercado {
|
||||||
Carrefour = "Carrefour",
|
Carrefour = "Carrefour",
|
||||||
Coto = "Coto",
|
Coto = "Coto",
|
||||||
Jumbo = "Jumbo",
|
Jumbo = "Jumbo",
|
||||||
|
Farmacity = "Farmacity",
|
||||||
}
|
}
|
||||||
export const supermercados: Supermercado[] = [
|
export const supermercados: Supermercado[] = [
|
||||||
Supermercado.Carrefour,
|
Supermercado.Carrefour,
|
||||||
Supermercado.Coto,
|
Supermercado.Coto,
|
||||||
Supermercado.Dia,
|
Supermercado.Dia,
|
||||||
Supermercado.Jumbo,
|
Supermercado.Jumbo,
|
||||||
|
Supermercado.Farmacity,
|
||||||
];
|
];
|
||||||
export const hosts: { [host: string]: Supermercado } = {
|
export const hosts: { [host: string]: Supermercado } = {
|
||||||
"diaonline.supermercadosdia.com.ar": Supermercado.Dia,
|
"diaonline.supermercadosdia.com.ar": Supermercado.Dia,
|
||||||
"www.carrefour.com.ar": Supermercado.Carrefour,
|
"www.carrefour.com.ar": Supermercado.Carrefour,
|
||||||
"www.cotodigital3.com.ar": Supermercado.Coto,
|
"www.cotodigital3.com.ar": Supermercado.Coto,
|
||||||
"www.jumbo.com.ar": Supermercado.Jumbo,
|
"www.jumbo.com.ar": Supermercado.Jumbo,
|
||||||
|
"www.farmacity.com": Supermercado.Farmacity,
|
||||||
};
|
};
|
||||||
export const hostBySupermercado = Object.fromEntries(
|
export const hostBySupermercado = Object.fromEntries(
|
||||||
Object.entries(hosts).map(([a, b]) => [b, a])
|
Object.entries(hosts).map(([a, b]) => [b, a])
|
||||||
) as Record<Supermercado, string>;
|
) as Record<Supermercado, string>;
|
||||||
|
|
||||||
|
// también actualizar en sitio/src/routes/ean/[ean]/+page.svelte
|
||||||
export const colorBySupermercado: { [supermercado in Supermercado]: string } = {
|
export const colorBySupermercado: { [supermercado in Supermercado]: string } = {
|
||||||
[Supermercado.Dia]: "#d52b1e",
|
[Supermercado.Dia]: "#d52b1e",
|
||||||
[Supermercado.Carrefour]: "#19549d",
|
[Supermercado.Carrefour]: "#19549d",
|
||||||
[Supermercado.Coto]: "#e20025",
|
[Supermercado.Coto]: "#e20025",
|
||||||
[Supermercado.Jumbo]: "#2dc850",
|
[Supermercado.Jumbo]: "#2dc850",
|
||||||
|
[Supermercado.Farmacity]: "#EF7603",
|
||||||
};
|
};
|
||||||
|
|
|
@ -285,6 +285,7 @@ async fn get_urls(supermercado: &Supermercado) -> Result<Vec<String>, anyhow::Er
|
||||||
Supermercado::Jumbo => sites::jumbo::get_urls().await?,
|
Supermercado::Jumbo => sites::jumbo::get_urls().await?,
|
||||||
Supermercado::Carrefour => sites::carrefour::get_urls().await?,
|
Supermercado::Carrefour => sites::carrefour::get_urls().await?,
|
||||||
Supermercado::Coto => sites::coto::get_urls().await?,
|
Supermercado::Coto => sites::coto::get_urls().await?,
|
||||||
|
Supermercado::Farmacity => sites::farmacity::get_urls().await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,6 +306,9 @@ async fn scrap_url(
|
||||||
sites::coto::parse(url, &tl::parse(body, tl::ParserOptions::default())?)
|
sites::coto::parse(url, &tl::parse(body, tl::ParserOptions::default())?)
|
||||||
}
|
}
|
||||||
"www.jumbo.com.ar" => sites::jumbo::scrap(client, url, body).await,
|
"www.jumbo.com.ar" => sites::jumbo::scrap(client, url, body).await,
|
||||||
|
"www.farmacity.com" => {
|
||||||
|
sites::farmacity::parse(url, &tl::parse(body, tl::ParserOptions::default())?)
|
||||||
|
}
|
||||||
s => bail!("Unknown host {}", s),
|
s => bail!("Unknown host {}", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
50
scraper-rs/src/sites/farmacity.rs
Normal file
50
scraper-rs/src/sites/farmacity.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use anyhow::Context;
|
||||||
|
use simple_error::bail;
|
||||||
|
|
||||||
|
use crate::sites::common;
|
||||||
|
use crate::PrecioPoint;
|
||||||
|
|
||||||
|
use super::vtex;
|
||||||
|
use super::vtex::find_product_ld;
|
||||||
|
use super::vtex::AvailabilityLd;
|
||||||
|
|
||||||
|
pub fn parse(url: String, dom: &tl::VDom) -> Result<PrecioPoint, anyhow::Error> {
|
||||||
|
let ean = common::get_meta_content(dom, "product:retailer_item_id")
|
||||||
|
.context("Parsing EAN")?
|
||||||
|
.to_string();
|
||||||
|
let precio_centavos = common::price_from_meta(dom)?;
|
||||||
|
|
||||||
|
let (name, image_url, in_stock) = match find_product_ld(dom) {
|
||||||
|
Some(pm) => {
|
||||||
|
let p = pm?;
|
||||||
|
(
|
||||||
|
Some(p.name),
|
||||||
|
Some(p.image),
|
||||||
|
Some(
|
||||||
|
p.offers.offers.first().context("No offer")?.availability
|
||||||
|
== AvailabilityLd::InStock,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => bail!("No JSON/LD"),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(PrecioPoint {
|
||||||
|
ean,
|
||||||
|
fetched_at: crate::now_sec(),
|
||||||
|
in_stock,
|
||||||
|
name,
|
||||||
|
image_url,
|
||||||
|
parser_version: 5,
|
||||||
|
precio_centavos,
|
||||||
|
url,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_urls() -> anyhow::Result<Vec<String>> {
|
||||||
|
let urls = vec![
|
||||||
|
"https://www.farmacity.com/sitemap/product-0.xml",
|
||||||
|
"https://www.farmacity.com/sitemap/product-1.xml",
|
||||||
|
];
|
||||||
|
vtex::get_urls_from_sitemap(urls).await
|
||||||
|
}
|
|
@ -2,5 +2,6 @@ pub mod carrefour;
|
||||||
mod common;
|
mod common;
|
||||||
pub mod coto;
|
pub mod coto;
|
||||||
pub mod dia;
|
pub mod dia;
|
||||||
|
pub mod farmacity;
|
||||||
pub mod jumbo;
|
pub mod jumbo;
|
||||||
pub mod vtex;
|
pub mod vtex;
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub enum Supermercado {
|
||||||
Jumbo,
|
Jumbo,
|
||||||
Carrefour,
|
Carrefour,
|
||||||
Coto,
|
Coto,
|
||||||
|
Farmacity,
|
||||||
}
|
}
|
||||||
impl Supermercado {
|
impl Supermercado {
|
||||||
pub fn host(&self) -> &'static str {
|
pub fn host(&self) -> &'static str {
|
||||||
|
@ -14,6 +15,7 @@ impl Supermercado {
|
||||||
Self::Carrefour => "www.carrefour.com.ar",
|
Self::Carrefour => "www.carrefour.com.ar",
|
||||||
Self::Coto => "www.cotodigital3.com.ar",
|
Self::Coto => "www.cotodigital3.com.ar",
|
||||||
Self::Jumbo => "www.jumbo.com.ar",
|
Self::Jumbo => "www.jumbo.com.ar",
|
||||||
|
Self::Farmacity => "www.farmacity.com",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
[Supermercado.Carrefour]: "bg-[#19549d] focus:ring-[#19549d]",
|
[Supermercado.Carrefour]: "bg-[#19549d] focus:ring-[#19549d]",
|
||||||
[Supermercado.Coto]: "bg-[#e20025] focus:ring-[#e20025]",
|
[Supermercado.Coto]: "bg-[#e20025] focus:ring-[#e20025]",
|
||||||
[Supermercado.Jumbo]: "bg-[#2dc850] focus:ring-[#2dc850]",
|
[Supermercado.Jumbo]: "bg-[#2dc850] focus:ring-[#2dc850]",
|
||||||
|
[Supermercado.Farmacity]: "bg-[#EF7603] focus:ring-[#EF7603]",
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue