diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-08-20 14:07:45 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-08-20 14:07:45 -0400 |
commit | da9ff8e9d6c03167e4fbdb000aa7a421e46667ab (patch) | |
tree | 70d62a6a7cb1baf9519f4f09c6861f145e962301 | |
parent | 41a41649b29f8d5a4f797515aab6386bfe90275d (diff) | |
download | rawr-ebooks-da9ff8e9d6c03167e4fbdb000aa7a421e46667ab.tar.gz rawr-ebooks-da9ff8e9d6c03167e4fbdb000aa7a421e46667ab.tar.bz2 rawr-ebooks-da9ff8e9d6c03167e4fbdb000aa7a421e46667ab.zip |
Updated libtwitter++ (API changes)
-rw-r--r-- | ebooks.cpp | 48 | ||||
m--------- | vendor/libtwittercpp | 0 |
2 files changed, 16 insertions, 32 deletions
diff --git a/ebooks.cpp b/ebooks.cpp index dd9c7bd..fd9ca83 100644 --- a/ebooks.cpp +++ b/ebooks.cpp | |||
@@ -75,20 +75,10 @@ int main(int argc, char** args) | |||
75 | return form; | 75 | return form; |
76 | }); | 76 | }); |
77 | 77 | ||
78 | std::mutex stats_mutex; | 78 | twitter::stream user_stream(client, [&kgramstats] (const twitter::notification& n) { |
79 | |||
80 | twitter::user me; | ||
81 | auto resp = client.getUser(me); | ||
82 | if (resp != twitter::response::ok) | ||
83 | { | ||
84 | std::cout << "Could not get current Twitter user" << std::endl; | ||
85 | return -1; | ||
86 | } | ||
87 | |||
88 | client.setUserStreamNotifyCallback([&] (twitter::notification n) { | ||
89 | if (n.getType() == twitter::notification::type::tweet) | 79 | if (n.getType() == twitter::notification::type::tweet) |
90 | { | 80 | { |
91 | if ((!n.getTweet().isRetweet()) && (n.getTweet().getAuthor() != me)) | 81 | if ((!n.getTweet().isRetweet()) && (n.getTweet().isMyTweet())) |
92 | { | 82 | { |
93 | std::string original = n.getTweet().getText(); | 83 | std::string original = n.getTweet().getText(); |
94 | std::string canonical; | 84 | std::string canonical; |
@@ -98,42 +88,36 @@ int main(int argc, char** args) | |||
98 | 88 | ||
99 | if (canonical.find("@rawr_ebooks") != std::string::npos) | 89 | if (canonical.find("@rawr_ebooks") != std::string::npos) |
100 | { | 90 | { |
101 | std::string doc = client.generateReplyPrefill(n.getTweet()); | 91 | std::string doc = n.getTweet().generateReplyPrefill(); |
92 | doc += kgramstats.randomSentence(140 - doc.length()); | ||
93 | doc.resize(140); | ||
94 | |||
95 | try | ||
102 | { | 96 | { |
103 | std::lock_guard<std::mutex> stats_lock(stats_mutex); | 97 | n.getTweet().reply(doc); |
104 | doc += kgramstats.randomSentence(140 - doc.length()); | 98 | } catch (const twitter::twitter_error& error) |
105 | doc.resize(140); | ||
106 | } | ||
107 | |||
108 | twitter::tweet tw; | ||
109 | twitter::response resp = client.updateStatus(doc, tw, n.getTweet()); | ||
110 | if (resp != twitter::response::ok) | ||
111 | { | 99 | { |
112 | std::cout << "Twitter error while tweeting: " << resp << std::endl; | 100 | std::cout << "Twitter error while tweeting: " << error.what() << std::endl; |
113 | } | 101 | } |
114 | } | 102 | } |
115 | } | 103 | } |
116 | } | 104 | } |
117 | }); | 105 | }); |
118 | 106 | ||
119 | client.startUserStream(); | ||
120 | std::this_thread::sleep_for(std::chrono::minutes(1)); | 107 | std::this_thread::sleep_for(std::chrono::minutes(1)); |
121 | 108 | ||
122 | std::cout << "Generating..." << std::endl; | 109 | std::cout << "Generating..." << std::endl; |
123 | for (;;) | 110 | for (;;) |
124 | { | 111 | { |
125 | std::string doc; | 112 | std::string doc = kgramstats.randomSentence(140); |
126 | { | ||
127 | std::lock_guard<std::mutex> stats_lock(stats_mutex); | ||
128 | doc = kgramstats.randomSentence(140); | ||
129 | } | ||
130 | doc.resize(140); | 113 | doc.resize(140); |
131 | 114 | ||
132 | twitter::tweet tw; | 115 | try |
133 | resp = client.updateStatus(doc, tw); | 116 | { |
134 | if (resp != twitter::response::ok) | 117 | client.updateStatus(doc); |
118 | } catch (const twitter::twitter_error& error) | ||
135 | { | 119 | { |
136 | std::cout << "Twitter error while tweeting: " << resp << std::endl; | 120 | std::cout << "Twitter error while tweeting: " << error.what() << std::endl; |
137 | } | 121 | } |
138 | 122 | ||
139 | int waitlen = rand() % delay; | 123 | int waitlen = rand() % delay; |
diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp | |||
Subproject 9fdcbee29350846db7f136b023da64bb2e6a93f | Subproject 6c9f541f34c58ac817f88ffb5e069b929bbbc27 | ||