diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-12-01 09:06:11 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-12-01 09:06:11 -0500 |
| commit | 0b419d526ced4826dd9e59e3d04ef97fd33983f6 (patch) | |
| tree | 913581821b6360c821376c8ef9255944868921f4 /wordplay.cpp | |
| parent | 62287325587649ee62188522a1cb429c53edff72 (diff) | |
| download | wordplay-0b419d526ced4826dd9e59e3d04ef97fd33983f6.tar.gz wordplay-0b419d526ced4826dd9e59e3d04ef97fd33983f6.tar.bz2 wordplay-0b419d526ced4826dd9e59e3d04ef97fd33983f6.zip | |
Switched from twitcurl to libtwitter++
Also updated verbly to remove dependence on json submodule, replaced the UNIX-dependent sleep call with the sleep functionality in the C++ standard library, and changed the tweet delay from 3 hours to 1 hour.
Diffstat (limited to 'wordplay.cpp')
| -rw-r--r-- | wordplay.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
| diff --git a/wordplay.cpp b/wordplay.cpp index 8beb225..dedd812 100644 --- a/wordplay.cpp +++ b/wordplay.cpp | |||
| @@ -3,21 +3,22 @@ | |||
| 3 | #include <iostream> | 3 | #include <iostream> |
| 4 | #include <list> | 4 | #include <list> |
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <twitcurl.h> | 6 | #include <twitter.h> |
| 7 | #include <verbly.h> | 7 | #include <verbly.h> |
| 8 | #include <unistd.h> | 8 | #include <chrono> |
| 9 | #include <thread> | ||
| 9 | 10 | ||
| 10 | int main(int argc, char** argv) | 11 | int main(int argc, char** argv) |
| 11 | { | 12 | { |
| 12 | srand(time(NULL)); | ||
| 13 | |||
| 14 | YAML::Node config = YAML::LoadFile("config.yml"); | 13 | YAML::Node config = YAML::LoadFile("config.yml"); |
| 15 | 14 | ||
| 16 | twitCurl twitter; | 15 | twitter::auth auth; |
| 17 | twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>()); | 16 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); |
| 18 | twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>()); | 17 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); |
| 19 | twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>()); | 18 | auth.setAccessKey(config["access_key"].as<std::string>()); |
| 20 | twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>()); | 19 | auth.setAccessSecret(config["access_secret"].as<std::string>()); |
| 20 | |||
| 21 | twitter::client client(auth); | ||
| 21 | 22 | ||
| 22 | verbly::data database("data.sqlite3"); | 23 | verbly::data database("data.sqlite3"); |
| 23 | 24 | ||
| @@ -71,18 +72,18 @@ int main(int argc, char** argv) | |||
| 71 | result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; | 72 | result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; |
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | std::string replyMsg; | 75 | try |
| 75 | if (twitter.statusUpdate(result.str())) | ||
| 76 | { | 76 | { |
| 77 | twitter.getLastWebResponse(replyMsg); | 77 | client.updateStatus(result.str()); |
| 78 | std::cout << "Twitter message: " << replyMsg << std::endl; | 78 | |
| 79 | } else { | 79 | std::cout << "Tweeted!" << std::endl; |
| 80 | twitter.getLastCurlError(replyMsg); | 80 | } catch (const twitter::twitter_error& e) |
| 81 | std::cout << "Curl error: " << replyMsg << std::endl; | 81 | { |
| 82 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | std::cout << "Waiting" << std::endl; | 85 | std::cout << "Waiting..." << std::endl; |
| 85 | 86 | ||
| 86 | sleep(60 * 60 * 3); | 87 | std::this_thread::sleep_for(std::chrono::hours(1)); |
| 87 | } | 88 | } |
| 88 | } | 89 | } |
