Skip to content

Instantly share code, notes, and snippets.

@kgtkr
Created January 14, 2018 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgtkr/fda171d69e67411a90b14c9eda327e86 to your computer and use it in GitHub Desktop.
Save kgtkr/fda171d69e67411a90b14c9eda327e86 to your computer and use it in GitHub Desktop.
extern crate clap;
extern crate egg_mode;
extern crate futures;
extern crate tokio_core;
use clap::{App, Arg};
use tokio_core::reactor::Core;
fn main() {
let app = App::new("time-tweet")
.version("0.1.0")
.author("tkr <kgtkr.jp@gmail.com>")
.about("正確な時間にツイート")
.arg(
Arg::with_name("consumer_key")
.help("コンシューマーキー")
.long("consumer-key")
.visible_alias("ck")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("consumer_secret")
.help("コンシューマーシークレット")
.long("consumer-secret")
.visible_alias("cs")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("token_key")
.help("トークンキー")
.long("token_key")
.visible_alias("tk")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("token_secret")
.help("トークンシークレット")
.long("token-secret")
.visible_alias("ts")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("msg")
.help("ツイート内容")
.long("msg")
.short("m")
.takes_value(true)
.required(true),
);
let matches = app.get_matches();
let ck = matches.value_of("consumer_key").unwrap();
let cs = matches.value_of("consumer_secret").unwrap();
let tk = matches.value_of("token_key").unwrap();
let ts = matches.value_of("token_secret").unwrap();
let msg = matches.value_of("msg").unwrap();
let mut core = Core::new().unwrap();
let handle = core.handle();
let token = egg_mode::Token::Access {
consumer: egg_mode::KeyPair::new(ck.to_string(), cs.to_string()),
access: egg_mode::KeyPair::new(tk.to_string(), ts.to_string()),
};
core.run(egg_mode::tweet::DraftTweet::new(msg).send(&token, &handle))
.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment