From 3f979af5d8f896a20110f7ede6b92984e1651d2f Mon Sep 17 00:00:00 2001 From: Aleksei Voronov Date: Wed, 29 Nov 2023 10:45:47 +0100 Subject: [PATCH] Add a way to force profile country by DID This is useful to fixup broken profiles. Ideally, of course, we should be retrying a few times and then giving up, but that seems kinda too much for a little hobby project. Also, metrics would be nice, but, you know --- src/bin/force_profile_country.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bin/force_profile_country.rs b/src/bin/force_profile_country.rs index 1062901..1526949 100644 --- a/src/bin/force_profile_country.rs +++ b/src/bin/force_profile_country.rs @@ -2,7 +2,7 @@ extern crate nederlandskie; use std::env; -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use clap::Parser; use dotenv::dotenv; @@ -11,9 +11,13 @@ use nederlandskie::services::{Bluesky, Database}; #[derive(Parser, Debug)] struct Args { /// Handles of the users to force the country for, comma-separated - #[arg(long, required(true), value_delimiter(','))] + #[arg(long, value_delimiter(','))] handle: Vec, + /// DIDs of the users to force the country for, comma-separated + #[arg(long, value_delimiter(','))] + did: Vec, + /// Country to use, two letters #[arg(long)] country: String, @@ -25,6 +29,10 @@ async fn main() -> Result<()> { let args = Args::parse(); + if args.handle.is_empty() && args.did.is_empty() { + bail!("Either --handle or --did must be supplied"); + } + let database_url = env::var("DATABASE_URL").context("DATABASE_URL environment variable must be set")?; @@ -47,5 +55,14 @@ async fn main() -> Result<()> { ); } + for did in &args.did { + database.force_profile_country(&did, &args.country).await?; + + println!( + "Stored '{}' as the country for profile with did '{}'", + args.country, did + ); + } + Ok(()) }