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 | |
| 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.
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | CMakeLists.txt | 14 | ||||
| m--------- | vendor/libtwittercpp | 0 | ||||
| m--------- | vendor/twitcurl | 0 | ||||
| m--------- | vendor/verbly | 0 | ||||
| -rw-r--r-- | wordplay.cpp | 37 |
6 files changed, 23 insertions, 31 deletions
| diff --git a/.gitmodules b/.gitmodules index b678533..43303e3 100644 --- a/.gitmodules +++ b/.gitmodules | |||
| @@ -4,9 +4,6 @@ | |||
| 4 | [submodule "vendor/verbly"] | 4 | [submodule "vendor/verbly"] |
| 5 | path = vendor/verbly | 5 | path = vendor/verbly |
| 6 | url = https://github.com/hatkirby/verbly | 6 | url = https://github.com/hatkirby/verbly |
| 7 | [submodule "vendor/twitcurl"] | ||
| 8 | path = vendor/twitcurl | ||
| 9 | url = https://github.com/swatkat/twitcurl | ||
| 10 | [submodule "vendor/yaml-cpp"] | 7 | [submodule "vendor/yaml-cpp"] |
| 11 | path = vendor/yaml-cpp | 8 | path = vendor/yaml-cpp |
| 12 | url = https://github.com/jbeder/yaml-cpp | 9 | 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 @@ | |||
| 1 | cmake_minimum_required (VERSION 3.1) | 1 | cmake_minimum_required (VERSION 3.1) |
| 2 | project (wordplay) | 2 | project (wordplay) |
| 3 | 3 | ||
| 4 | find_package(PkgConfig) | 4 | add_subdirectory(vendor/libtwittercpp) |
| 5 | pkg_check_modules(sqlite3 sqlite3 REQUIRED) | ||
| 6 | |||
| 7 | add_subdirectory(vendor/twitcurl/libtwitcurl) | ||
| 8 | include_directories(vendor/twitcurl/libtwitcurl) | ||
| 9 | |||
| 10 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) | 5 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) |
| 11 | include_directories(vendor/yaml-cpp/include) | ||
| 12 | |||
| 13 | add_subdirectory(vendor/verbly) | 6 | add_subdirectory(vendor/verbly) |
| 14 | include_directories(vendor/verbly/lib) | 7 | |
| 8 | include_directories(vendor/verbly/lib vendor/libtwittercpp/src vendor/yaml-cpp/include) | ||
| 15 | 9 | ||
| 16 | add_executable(wordplay wordplay.cpp) | 10 | add_executable(wordplay wordplay.cpp) |
| 17 | set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) | 11 | set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) |
| 18 | set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) | 12 | set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) |
| 19 | target_link_libraries(wordplay verbly ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl) | 13 | target_link_libraries(wordplay verbly twitter++ yaml-cpp) |
| diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 | |||
| Subproject d783c17151a98466e304b1e5f33bfca0be885fd | |||
| diff --git a/vendor/twitcurl b/vendor/twitcurl deleted file mode 160000 | |||
| Subproject 6659e86de7481e50977b7569c75138f7f69ad3c | |||
| diff --git a/vendor/verbly b/vendor/verbly | |||
| Subproject 04338f2b040fee5142904c062e0e38c83660103 | Subproject 1f898f3bd66c29672275c2c884b17ba662ced62 | ||
| 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 | } |
