8个稳定版本
2.0.2 | 2019年2月10日 |
---|---|
2.0.1 | 2019年1月12日 |
1.4.0 | 2018年12月31日 |
#4 in #tumblr
每月下载21次
40KB
941 代码行
简介
Rust的Tumblr API
用法
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
)
);
}
爬取防护照片
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; }
}
}
所有客户端方法都与Tumblr API同步。
待办事项
依赖项
~23–35MB
~716K SLoC