From 0b419d526ced4826dd9e59e3d04ef97fd33983f6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 1 Dec 2016 09:06:11 -0500 Subject: 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. --- .gitmodules | 3 --- CMakeLists.txt | 14 ++++---------- vendor/libtwittercpp | 1 + vendor/twitcurl | 1 - vendor/verbly | 2 +- wordplay.cpp | 37 +++++++++++++++++++------------------ 6 files changed, 25 insertions(+), 33 deletions(-) create mode 160000 vendor/libtwittercpp delete mode 160000 vendor/twitcurl diff --git a/.gitmodules b/.gitmodules index b678533..43303e3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "vendor/verbly"] path = vendor/verbly url = https://github.com/hatkirby/verbly -[submodule "vendor/twitcurl"] - path = vendor/twitcurl - url = https://github.com/swatkat/twitcurl [submodule "vendor/yaml-cpp"] path = vendor/yaml-cpp url = https://github.com/jbeder/yaml-cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a10537e..82fcc44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,13 @@ cmake_minimum_required (VERSION 3.1) project (wordplay) -find_package(PkgConfig) -pkg_check_modules(sqlite3 sqlite3 REQUIRED) - -add_subdirectory(vendor/twitcurl/libtwitcurl) -include_directories(vendor/twitcurl/libtwitcurl) - +add_subdirectory(vendor/libtwittercpp) add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) -include_directories(vendor/yaml-cpp/include) - add_subdirectory(vendor/verbly) -include_directories(vendor/verbly/lib) + +include_directories(vendor/verbly/lib vendor/libtwittercpp/src vendor/yaml-cpp/include) add_executable(wordplay wordplay.cpp) set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) -target_link_libraries(wordplay verbly ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl) +target_link_libraries(wordplay verbly twitter++ yaml-cpp) diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 index 0000000..d783c17 --- /dev/null +++ b/vendor/libtwittercpp @@ -0,0 +1 @@ +Subproject commit d783c17151a98466e304b1e5f33bfca0be885fd8 diff --git a/vendor/twitcurl b/vendor/twitcurl deleted file mode 160000 index 6659e86..0000000 --- a/vendor/twitcurl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6659e86de7481e50977b7569c75138f7f69ad3c7 diff --git a/vendor/verbly b/vendor/verbly index 04338f2..1f898f3 160000 --- a/vendor/verbly +++ b/vendor/verbly @@ -1 +1 @@ -Subproject commit 04338f2b040fee5142904c062e0e38c836601034 +Subproject commit 1f898f3bd66c29672275c2c884b17ba662ced626 diff --git a/wordplay.cpp b/wordplay.cpp index 8beb225..dedd812 100644 --- a/wordplay.cpp +++ b/wordplay.cpp @@ -3,21 +3,22 @@ #include #include #include -#include +#include #include -#include +#include +#include int main(int argc, char** argv) { - srand(time(NULL)); - YAML::Node config = YAML::LoadFile("config.yml"); - twitCurl twitter; - twitter.getOAuth().setConsumerKey(config["consumer_key"].as()); - twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as()); - twitter.getOAuth().setOAuthTokenKey(config["access_key"].as()); - twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as()); + twitter::auth auth; + auth.setConsumerKey(config["consumer_key"].as()); + auth.setConsumerSecret(config["consumer_secret"].as()); + auth.setAccessKey(config["access_key"].as()); + auth.setAccessSecret(config["access_secret"].as()); + + twitter::client client(auth); verbly::data database("data.sqlite3"); @@ -71,18 +72,18 @@ int main(int argc, char** argv) result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; } - std::string replyMsg; - if (twitter.statusUpdate(result.str())) + try { - twitter.getLastWebResponse(replyMsg); - std::cout << "Twitter message: " << replyMsg << std::endl; - } else { - twitter.getLastCurlError(replyMsg); - std::cout << "Curl error: " << replyMsg << std::endl; + client.updateStatus(result.str()); + + std::cout << "Tweeted!" << std::endl; + } catch (const twitter::twitter_error& e) + { + std::cout << "Twitter error: " << e.what() << std::endl; } - std::cout << "Waiting" << std::endl; + std::cout << "Waiting..." << std::endl; - sleep(60 * 60 * 3); + std::this_thread::sleep_for(std::chrono::hours(1)); } } -- cgit 1.4.1