Run every 20 minutes, send user agent

This commit is contained in:
SkyfallWasTaken 2024-07-09 22:11:31 +01:00
parent c20a2a3a88
commit 25cef90288
2 changed files with 11 additions and 3 deletions

View file

@ -1,3 +1,4 @@
use reqwest::Client;
use scraper::{Html, Selector};
use serde::{Deserialize, Serialize};
use worker::*;
@ -24,10 +25,17 @@ pub struct ShopItem {
pub type ShopItems = Vec<ShopItem>;
pub async fn try_fetch(shop_url: Url) -> Result<ShopItems> {
let mut response = Fetch::Url(shop_url).send().await?;
const USER_AGENT: &str = "Arcade-Monitor/1.0 (+@SkyfallWasTaken)";
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::parse_document(&doc_html);
let selector = Selector::parse("#__NEXT_DATA__").unwrap();
let json: serde_json::Value = serde_json::from_str(

View file

@ -6,7 +6,7 @@ compatibility_date = "2024-06-29"
command = "cargo install worker-build && worker-build --release"
[triggers]
crons = ["0 * * * *"] # Run every hour
crons = ["*/20 * * * *"] # Run every twenty minutes
[placement]
mode = "smart"