diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-20 16:41:32 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-20 16:41:32 -0400 |
commit | 1fd1aa09e34e63f4463503b012c9cd246a41b765 (patch) | |
tree | 8278a03f725bd156b65c40dcfe98f4a0047de057 | |
parent | 7f90d586f1eeca0354b0e4500645e72b5b9f1021 (diff) | |
download | snitch-1fd1aa09e34e63f4463503b012c9cd246a41b765.tar.gz snitch-1fd1aa09e34e63f4463503b012c9cd246a41b765.tar.bz2 snitch-1fd1aa09e34e63f4463503b012c9cd246a41b765.zip |
Added functionality to follow new followers not sent by the stream
-rw-r--r-- | snitch.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/snitch.cpp b/snitch.cpp index cd5153b..2357a7d 100644 --- a/snitch.cpp +++ b/snitch.cpp | |||
@@ -30,10 +30,10 @@ int main(int argc, char** argv) | |||
30 | streamed_friends = n.getFriends(); | 30 | streamed_friends = n.getFriends(); |
31 | } else if (n.getType() == twitter::notification::type::follow) | 31 | } else if (n.getType() == twitter::notification::type::follow) |
32 | { | 32 | { |
33 | streamed_friends.insert(n.getUserID()); | 33 | streamed_friends.insert(n.getUser().getID()); |
34 | } else if (n.getType() == twitter::notification::type::unfollow) | 34 | } else if (n.getType() == twitter::notification::type::unfollow) |
35 | { | 35 | { |
36 | streamed_friends.erase(n.getUserID()); | 36 | streamed_friends.erase(n.getUser().getID()); |
37 | } else if (n.getType() == twitter::notification::type::tweet) | 37 | } else if (n.getType() == twitter::notification::type::tweet) |
38 | { | 38 | { |
39 | // Only monitor people you are following | 39 | // Only monitor people you are following |
@@ -80,7 +80,7 @@ int main(int argc, char** argv) | |||
80 | client.startUserStream(); | 80 | client.startUserStream(); |
81 | for (;;) | 81 | for (;;) |
82 | { | 82 | { |
83 | std::this_thread::sleep_for(std::chrono::hours(4)); | 83 | std::this_thread::sleep_for(std::chrono::minutes(1)); |
84 | 84 | ||
85 | std::set<twitter::user_id> friends; | 85 | std::set<twitter::user_id> friends; |
86 | std::set<twitter::user_id> followers; | 86 | std::set<twitter::user_id> followers; |
@@ -90,22 +90,24 @@ int main(int argc, char** argv) | |||
90 | resp = client.getFollowers(followers); | 90 | resp = client.getFollowers(followers); |
91 | if (resp == twitter::response::ok) | 91 | if (resp == twitter::response::ok) |
92 | { | 92 | { |
93 | auto frit = std::begin(friends); | 93 | std::list<twitter::user_id> old_friends, new_followers; |
94 | auto foit = std::begin(followers); | 94 | std::set_difference(std::begin(friends), std::end(friends), std::begin(followers), std::end(followers), std::back_inserter(old_friends)); |
95 | std::set_difference(std::begin(followers), std::end(followers), std::begin(friends), std::end(friends), std::back_inserter(new_followers)); | ||
96 | for (auto f : old_friends) | ||
97 | { | ||
98 | resp = client.unfollow(f); | ||
99 | if (resp != twitter::response::ok) | ||
100 | { | ||
101 | std::cout << "Twitter error while unfollowing" << std::endl; | ||
102 | } | ||
103 | } | ||
95 | 104 | ||
96 | while (frit != std::end(friends)) | 105 | for (auto f : new_followers) |
97 | { | 106 | { |
98 | auto match = std::mismatch(frit, std::end(friends), foit); | 107 | resp = client.follow(f); |
99 | if (match.first != std::end(friends)) | 108 | if (resp != twitter::response::ok) |
100 | { | 109 | { |
101 | resp = client.unfollow(*match.first); | 110 | std::cout << "Twitter error while following" << std::endl; |
102 | if (resp != twitter::response::ok) | ||
103 | { | ||
104 | std::cout << "Twitter error while unfollowing" << std::endl; | ||
105 | } | ||
106 | |||
107 | frit = match.first; | ||
108 | frit++; | ||
109 | } | 111 | } |
110 | } | 112 | } |
111 | } else { | 113 | } else { |
@@ -114,6 +116,8 @@ int main(int argc, char** argv) | |||
114 | } else { | 116 | } else { |
115 | std::cout << "Twitter error while getting friends: " << resp << std::endl; | 117 | std::cout << "Twitter error while getting friends: " << resp << std::endl; |
116 | } | 118 | } |
119 | |||
120 | std::this_thread::sleep_for(std::chrono::hours(4)); | ||
117 | } | 121 | } |
118 | 122 | ||
119 | client.stopUserStream(); | 123 | client.stopUserStream(); |