Created
May 28, 2024 02:36
-
-
Save pog5/64435402ce731cd16a16956fab006087 to your computer and use it in GitHub Desktop.
Checks the Last-Modified response header of a URL every 60 seconds, if it changes, it sends a alert to a discord webhook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module main | |
import time | |
import net.http | |
const webhook_url = "https://discord.com/api/webhooks/channelid/webhookid" | |
const target_url = "https://www.website.com/index.html" | |
fn main() { | |
mut last_modified_header := "" | |
for { | |
resp := http.get(target_url) or { | |
eprintln("Couldn't get url") | |
return | |
} | |
last_modified := resp.header.get(http.CommonHeader.last_modified)! | |
if last_modified != last_modified_header { | |
send_discord_message(last_modified) | |
last_modified_header = last_modified | |
} | |
time.sleep(60 * time.second) | |
} | |
} | |
fn send_discord_message(message string) { | |
warning := ":warning: Last-Modified is now `" + message + "`" | |
eprint(warning) | |
result := http.post_json(webhook_url, '{ "content":"' + warning + '"}') or { | |
eprint("Couldnt send message to webhook: ") | |
eprintln(err) | |
return | |
} | |
eprintln(result.body) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment