From bde794d7455a15052f7e4438b959970aa2457c7b Mon Sep 17 00:00:00 2001 From: Falko Zurell Date: Fri, 17 Jan 2025 15:45:48 +0100 Subject: [PATCH] introduce Batch size and a README --- README.md | 7 +++++++ config.json.example | 1 + src/main.rs | 8 +++++--- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..838c338 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Instagram Pixelfed Batch Upload + +This program takes a folder and iterates over the images and creates Pixelfed postings with a specified batch size. +The description of the post can be given via the config.json. +Two variables in the post description can be give (see the `config.json.example` ). + +Usage: `` diff --git a/config.json.example b/config.json.example index 8cb64a6..97a2d67 100644 --- a/config.json.example +++ b/config.json.example @@ -3,5 +3,6 @@ # See https://docs.pixelfed.org/running-pixelfed/installation.html#setting-up-services "access_token": "sdg;lkjrglksjh;lkshj;lksjthrst;hoijrt;ihj;sithj;itjh", "visibility": "unlisted", + "batch_size": 10, "default_text": "Instagram dump from @title@ @batch@ #instabackup #instaimport #instaexit" } diff --git a/src/main.rs b/src/main.rs index 65c4e3e..ae1c331 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::fs; -use serde::Deserialize; +use std::path::Path; +use serde::{Deserialize, Serialize}; use reqwest::blocking::Client; use std::error::Error; @@ -9,6 +10,7 @@ struct Config { access_token: String, visibility: String, // Should be "unlisted" default_text: String, + batch_size: usize, } fn load_config() -> Result> { @@ -92,9 +94,9 @@ fn main() -> Result<(), Box> { let config = load_config()?; let images = get_jpeg_files(&args[1]); let client = Client::new(); - let total_batches = (images.len() + 19) / 20; + let total_batches = (images.len() + config.batch_size - 1) / config.batch_size; - for (i, chunk) in images.chunks(20).enumerate() { + for (i, chunk) in images.chunks(config.batch_size).enumerate() { upload_images_batch(&client, &config, chunk, i + 1, total_batches, &title)?; }