Crates.io | rumblr |
lib.rs | rumblr |
version | 2.0.2 |
source | src |
created_at | 2018-12-29 14:23:33.573165 |
updated_at | 2019-02-10 20:42:31.337563 |
description | Tumblr APIs Client |
homepage | |
repository | https://github.com/AurevoirXavier/rumblr |
max_upload_size | |
id | 104411 |
size | 40,465 |
Tumblr APIs for Rust
extern crate rumblr;
// --- external ---
use rumblr::TumblrClient;
fn main() {
// OAUTH
const CONSUMER_KEY: &'static str = "YOUR CONSUMER KEY";
const CONSUMER_SECRET: &'static str = "YOUR CONSUMER SECRET";
let client = TumblrClient::new()
.set_consumer(CONSUMER_KEY, CONSUMER_SECRET)
.proxy("http://127.0.0.1:1087")
.unwrap()
.oauth();
client.save_keys("rumblr.keys").unwrap();
// Already OAUTHed
let client = TumblrClient::new()
.proxy("http://127.0.0.1:1087")
.unwrap()
.load_keys("rumblr.keys")
.unwrap();
println!(
"{:?}",
client.legacy_post(
"your tumblr domain [e.g. (david.tumblr.com)]",
rumblr::PostAction::New,
rumblr::PostType::Photo {
caption: None,
link: None,
source: Some("https://uvwvu.xyz/favicon.png"),
data: None,
data64: None,
},
None
)
);
}
Crawl shield photos:
extern crate rumblr;
extern crate serde_json;
// --- external ---
use rumblr::{TumblrClient, GetBlogPostsOptionalParams};
use serde_json::Value;
fn main() {
let client = TumblrClient::new()
.proxy("http://127.0.0.1:1087")
.unwrap()
.load_keys("rumblr.keys")
.unwrap();
let limit = 10;
for i in 0u32.. {
let resp: Value = client.get_blog_posts(
"target tumblr domain [e.g. (david.tumblr.com)]",
Some(
GetBlogPostsOptionalParams::new()
.r#type("photo")
.limit(&limit.to_string())
.offset(&(i * limit).to_string())
)
);
let path = "export";
{
// --- std ---
use std::{
fs::create_dir,
path::Path,
};
let path = Path::new(path);
if !path.is_dir() { create_dir(path).unwrap(); }
}
let posts = resp["response"]["posts"].as_array().unwrap();
for post in posts {
let mut infos = String::new();
{
let photos = post["photos"].as_array().unwrap();
for photo in photos {
infos.push_str(photo["original_size"]["url"].as_str().unwrap());
infos.push('\n');
}
}
{
// --- std ---
use std::{
fs::File,
io::Write,
};
let mut f = File::create(&format!("{}/{}.txt", path, post["id"].as_u64().unwrap())).unwrap();
f.write_all(infos.as_bytes()).unwrap();
f.sync_all().unwrap();
}
}
if posts.len() != limit as usize { break; }
}
}
All client methods sync with Tumblr API.
Support Neue Post Format.