From 93f1f3ad274de032e1b023eb1262cee1c61181ae Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 2 Oct 2016 15:36:33 -0400 Subject: Initial commit --- .gitmodules | 6 +++++ CMakeLists.txt | 13 +++++++++++ manifesto.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/libtwittercpp | 1 + vendor/yaml-cpp | 1 + 5 files changed, 86 insertions(+) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 manifesto.cpp create mode 160000 vendor/libtwittercpp create mode 160000 vendor/yaml-cpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8544219 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "vendor/libtwittercpp"] + path = vendor/libtwittercpp + url = https://github.com/hatkirby/libtwittercpp +[submodule "vendor/yaml-cpp"] + path = vendor/yaml-cpp + url = https://github.com/jbeder/yaml-cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..348f7cc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required (VERSION 3.1) +project (manifesto) + +set(CMAKE_BUILD_TYPE Debug) + +add_subdirectory(vendor/libtwittercpp) +add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) + +include_directories(vendor/libtwittercpp/src vendor/yaml-cpp/include) +add_executable(manifesto manifesto.cpp) +set_property(TARGET manifesto PROPERTY CXX_STANDARD 11) +set_property(TARGET manifesto PROPERTY CXX_STANDARD_REQUIRED ON) +target_link_libraries(manifesto yaml-cpp twitter++) diff --git a/manifesto.cpp b/manifesto.cpp new file mode 100644 index 0000000..6b59213 --- /dev/null +++ b/manifesto.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + YAML::Node config = YAML::LoadFile("config.yml"); + + 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); + + long loc = 0; + if (config["current_location"]) + { + loc = config["current_location"].as(); + } + + std::list tweets; + { + std::ifstream corpus(config["corpus"].as()); + corpus.ignore(loc); + + char buffer[140]; + while (corpus) + { + corpus.read(buffer, 140); + tweets.push_back(std::string(buffer, 140)); + } + } + + while (!tweets.empty()) + { + try + { + std::string nextTweet = tweets.front(); + client.updateStatus(nextTweet); + + std::cout << "Tweeted!" << std::endl; + + loc += 140; + { + std::ofstream fout("config.yml"); + config["current_location"] = loc; + fout << config; + } + + tweets.pop_front(); + } catch (const twitter::twitter_error& e) + { + std::cout << "Twitter error: " << e.what() << std::endl; + } + + std::cout << "Waiting..." << std::endl; + + std::this_thread::sleep_for(std::chrono::hours(6)); + } +} diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 index 0000000..febadca --- /dev/null +++ b/vendor/libtwittercpp @@ -0,0 +1 @@ +Subproject commit febadca7d4e0460aa78f95b53b5e36e51fd2f97d diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000 index 0000000..85af926 --- /dev/null +++ b/vendor/yaml-cpp @@ -0,0 +1 @@ +Subproject commit 85af926ddc5f3c8fb438001743e65ec3a039ceec -- cgit 1.4.1