i add der shtuff

This commit is contained in:
abbie 2023-08-06 18:42:26 +01:00
commit 86d5ba45c9
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
4 changed files with 1315 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1244
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

11
Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "megafarp"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.3.19", features = ["derive"] }
png = "0.11.0"
reqwest = { version = "0.11.18", features = ["blocking"] }

59
src/main.rs Normal file
View file

@ -0,0 +1,59 @@
use std::io::Write;
use std::fs::File;
use reqwest::header::USER_AGENT;
use std::io::BufWriter;
use std::path::Path;
use png::HasParameters;
use std::collections::HashMap;
use clap::Parser;
// megafarp, a program for farping 128x64 1 bit PNG images onto furpsocial.
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// Name of PNG file to take as input to farp.
#[clap(short, long)]
input: String,
/// Signature to use in the farp.
#[clap(short, long, default_value = "megafarp")]
signature: String,
}
fn main() {
let args = Args::parse();
derp(args.input, args.signature);
}
fn derp(input: String, sig: String) {
let decoder = png::Decoder::new(File::open(input).unwrap());
let (info ,mut reader) = decoder.read_info().unwrap();
let mut buf = vec![0; info.buffer_size()];
reader.next_frame(&mut buf).unwrap();
let mut luf = vec![];
let mut i: usize = 0;
while i < buf.len() {
if buf[i] > 127 { luf.push(0); }
else { luf.push(1); }
i = i + 3;
}
let mut w = String::new();
i = 0;
let mut x: usize = 0;
for v in luf {
if w == String::new() { w = format!("{}", v); }
else { w = format!("{}{}", w, v); }
}
let mut params = HashMap::new();
params.insert("image-bits", w.clone());
params.insert("signature",sig);
let headers = format!("image-bits={}&signature=megafarp", w);
let client = reqwest::blocking::Client::new();
let res = client.post("https://furp.colean.cc/farp.php")
.form(&params)
.header(USER_AGENT, "megafarp/0.1.0 (https://git.colean.cc/threeoh6000/megafarp)")
.send();
}