mirror of
https://github.com/SkyfallWasTaken/arcade-monitor.git
synced 2024-11-12 20:52:24 +00:00
Run every 20 minutes, send user agent
This commit is contained in:
parent
c20a2a3a88
commit
25cef90288
2 changed files with 11 additions and 3 deletions
12
src/items.rs
12
src/items.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use reqwest::Client;
|
||||||
use scraper::{Html, Selector};
|
use scraper::{Html, Selector};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use worker::*;
|
use worker::*;
|
||||||
|
@ -24,10 +25,17 @@ pub struct ShopItem {
|
||||||
|
|
||||||
pub type ShopItems = Vec<ShopItem>;
|
pub type ShopItems = Vec<ShopItem>;
|
||||||
|
|
||||||
pub async fn try_fetch(shop_url: Url) -> Result<ShopItems> {
|
const USER_AGENT: &str = "Arcade-Monitor/1.0 (+@SkyfallWasTaken)";
|
||||||
let mut response = Fetch::Url(shop_url).send().await?;
|
|
||||||
|
|
||||||
|
pub async fn try_fetch(shop_url: Url) -> Result<ShopItems> {
|
||||||
|
let client = Client::new();
|
||||||
|
let response = client
|
||||||
|
.get(shop_url)
|
||||||
|
.header("User-Agent", USER_AGENT)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
let doc_html = response.text().await?;
|
let doc_html = response.text().await?;
|
||||||
|
|
||||||
let doc = Html::parse_document(&doc_html);
|
let doc = Html::parse_document(&doc_html);
|
||||||
let selector = Selector::parse("#__NEXT_DATA__").unwrap();
|
let selector = Selector::parse("#__NEXT_DATA__").unwrap();
|
||||||
let json: serde_json::Value = serde_json::from_str(
|
let json: serde_json::Value = serde_json::from_str(
|
||||||
|
|
|
@ -6,7 +6,7 @@ compatibility_date = "2024-06-29"
|
||||||
command = "cargo install worker-build && worker-build --release"
|
command = "cargo install worker-build && worker-build --release"
|
||||||
|
|
||||||
[triggers]
|
[triggers]
|
||||||
crons = ["0 * * * *"] # Run every hour
|
crons = ["*/20 * * * *"] # Run every twenty minutes
|
||||||
|
|
||||||
[placement]
|
[placement]
|
||||||
mode = "smart"
|
mode = "smart"
|
||||||
|
|
Loading…
Reference in a new issue