aboutsummaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-11-12 13:00:01 -0500
committerXe Iaso <me@christine.website>2022-11-12 13:00:01 -0500
commitab86d9bf5d9accf681588dd48df581d77126708c (patch)
tree81ed60b3980764ae90fa01fe21a2345da93a9bed /src/bin
parent7a8123435b381db82b557d630bdae5df77b86608 (diff)
downloadxesite-ab86d9bf5d9accf681588dd48df581d77126708c.tar.xz
xesite-ab86d9bf5d9accf681588dd48df581d77126708c.zip
rip twitter
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/fetch_mastodon_post.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/bin/fetch_mastodon_post.rs b/src/bin/fetch_mastodon_post.rs
index 408d90c..c7f4275 100644
--- a/src/bin/fetch_mastodon_post.rs
+++ b/src/bin/fetch_mastodon_post.rs
@@ -15,11 +15,15 @@ async fn main() -> Result<()> {
}
let mut post_url = args[1].clone();
- if !post_url.ends_with(".json") {
- post_url = format!("{post_url}.json");
- }
- let toot: Toot = reqwest::get(&post_url)
+ let cli = reqwest::Client::builder()
+ .user_agent("github.com/Xe/site fetch_mastodon_post")
+ .build()?;
+
+ let toot: Toot = cli
+ .get(&post_url)
+ .header("Accept", "application/json")
+ .send()
.await?
.error_for_status()?
.json()
@@ -29,6 +33,9 @@ async fn main() -> Result<()> {
fs::create_dir_all("./data/toots")?;
+ if !post_url.ends_with(".json") {
+ post_url = format!("{post_url}.json");
+ }
let post_hash = xesite::hash_string(post_url);
debug!("wrote post to ./data/toots/{post_hash}.json");
@@ -36,10 +43,11 @@ async fn main() -> Result<()> {
let mut fout = fs::File::create(&format!("./data/toots/{post_hash}.json"))?;
serde_json::to_writer_pretty(&mut fout, &toot)?;
- let user_url = format!("{}.json", toot.attributed_to);
- debug!("fetching {user_url} ...");
-
- let user: User = reqwest::get(&user_url)
+ debug!("fetching {} ...", toot.attributed_to);
+ let user: User = cli
+ .get(&toot.attributed_to)
+ .header("Accept", "application/json")
+ .send()
.await?
.error_for_status()?
.json()
@@ -49,6 +57,7 @@ async fn main() -> Result<()> {
debug!("got user {} ({})", user.preferred_username, user.name);
+ let user_url = format!("{}.json", toot.attributed_to);
let user_hash = xesite::hash_string(user_url);
debug!("wrote post to ./data/users/{user_hash}.json");