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
This commit is contained in:
Aleksei Voronov 2023-11-29 10:45:47 +01:00
parent 85efe62fdf
commit 3f979af5d8
1 changed files with 19 additions and 2 deletions

View File

@ -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<String>,
/// DIDs of the users to force the country for, comma-separated
#[arg(long, value_delimiter(','))]
did: Vec<String>,
/// 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(())
}