forked from egg-mode-rs/egg-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.rs
90 lines (79 loc) · 2.39 KB
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
mod common;
use futures::future;
use futures::StreamExt;
use egg_mode::user;
//IMPORTANT: see common.rs for instructions on making sure this properly authenticates with
//Twitter.
#[tokio::main]
async fn main() {
let config = common::Config::load().await;
println!("");
println!("Heterogeneous multi-user lookup:");
let mut users: Vec<egg_mode::user::UserID> = vec![];
users.push(config.user_id.into());
users.push("SwiftOnSecurity".into());
for user in user::lookup(users, &config.token)
.await
.unwrap()
.response
.iter()
{
print_user(user)
}
println!("");
println!("Searching based on a term: (here, it's 'rustlang')");
user::search("rustlang", &config.token)
.with_page_size(5)
.take(5)
.for_each(|resp| {
let resp = resp.unwrap();
print_user(&resp);
future::ready(())
})
.await;
println!("");
println!("Who do you follow?");
user::friends_of(config.user_id, &config.token)
.with_page_size(5)
.take(5)
.for_each(|resp| {
let resp = resp.unwrap();
print_user(&resp);
future::ready(())
})
.await;
println!("");
println!("Who follows you?");
user::followers_of(config.user_id, &config.token)
.with_page_size(5)
.take(5)
.for_each(|resp| {
let resp = resp.unwrap();
print_user(&resp);
future::ready(())
})
.await;
}
fn print_user(user: &user::TwitterUser) {
println!("");
println!("{} (@{})", user.name, user.screen_name);
println!("Created at {}", user.created_at);
println!(
"Follows {}, followed by {}",
user.friends_count, user.followers_count
);
if let Some(ref desc) = user.description {
println!("{}", desc);
} else {
println!("(no description provided)");
}
match (&user.location, &user.url) {
(&Some(ref loc), &Some(ref link)) => println!("{} | {}", loc, link),
(&None, &Some(ref link)) => println!("{}", link),
(&Some(ref loc), &None) => println!("{}", loc),
(&None, &None) => (),
}
}