introduce Batch size and a README
This commit is contained in:
parent
ea40103538
commit
bde794d745
3 changed files with 13 additions and 3 deletions
7
README.md
Normal file
7
README.md
Normal file
|
@ -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: ``
|
|
@ -3,5 +3,6 @@
|
||||||
# See https://docs.pixelfed.org/running-pixelfed/installation.html#setting-up-services
|
# See https://docs.pixelfed.org/running-pixelfed/installation.html#setting-up-services
|
||||||
"access_token": "sdg;lkjrglksjh;lkshj;lksjthrst;hoijrt;ihj;sithj;itjh",
|
"access_token": "sdg;lkjrglksjh;lkshj;lksjthrst;hoijrt;ihj;sithj;itjh",
|
||||||
"visibility": "unlisted",
|
"visibility": "unlisted",
|
||||||
|
"batch_size": 10,
|
||||||
"default_text": "Instagram dump from @title@ @batch@ #instabackup #instaimport #instaexit"
|
"default_text": "Instagram dump from @title@ @batch@ #instabackup #instaimport #instaexit"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use serde::Deserialize;
|
use std::path::Path;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ struct Config {
|
||||||
access_token: String,
|
access_token: String,
|
||||||
visibility: String, // Should be "unlisted"
|
visibility: String, // Should be "unlisted"
|
||||||
default_text: String,
|
default_text: String,
|
||||||
|
batch_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_config() -> Result<Config, Box<dyn Error>> {
|
fn load_config() -> Result<Config, Box<dyn Error>> {
|
||||||
|
@ -92,9 +94,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let config = load_config()?;
|
let config = load_config()?;
|
||||||
let images = get_jpeg_files(&args[1]);
|
let images = get_jpeg_files(&args[1]);
|
||||||
let client = Client::new();
|
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)?;
|
upload_images_batch(&client, &config, chunk, i + 1, total_batches, &title)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue