diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-10-02 15:36:33 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-10-02 15:36:33 -0400 |
| commit | 93f1f3ad274de032e1b023eb1262cee1c61181ae (patch) | |
| tree | 340eb7e2564df9cb08e699ac082d3938805a318e | |
| download | manifesto-93f1f3ad274de032e1b023eb1262cee1c61181ae.tar.gz manifesto-93f1f3ad274de032e1b023eb1262cee1c61181ae.tar.bz2 manifesto-93f1f3ad274de032e1b023eb1262cee1c61181ae.zip | |
Initial commit
| -rw-r--r-- | .gitmodules | 6 | ||||
| -rw-r--r-- | CMakeLists.txt | 13 | ||||
| -rw-r--r-- | manifesto.cpp | 65 | ||||
| m--------- | vendor/libtwittercpp | 0 | ||||
| m--------- | vendor/yaml-cpp | 0 |
5 files changed, 84 insertions, 0 deletions
| diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8544219 --- /dev/null +++ b/.gitmodules | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | [submodule "vendor/libtwittercpp"] | ||
| 2 | path = vendor/libtwittercpp | ||
| 3 | url = https://github.com/hatkirby/libtwittercpp | ||
| 4 | [submodule "vendor/yaml-cpp"] | ||
| 5 | path = vendor/yaml-cpp | ||
| 6 | 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 @@ | |||
| 1 | cmake_minimum_required (VERSION 3.1) | ||
| 2 | project (manifesto) | ||
| 3 | |||
| 4 | set(CMAKE_BUILD_TYPE Debug) | ||
| 5 | |||
| 6 | add_subdirectory(vendor/libtwittercpp) | ||
| 7 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) | ||
| 8 | |||
| 9 | include_directories(vendor/libtwittercpp/src vendor/yaml-cpp/include) | ||
| 10 | add_executable(manifesto manifesto.cpp) | ||
| 11 | set_property(TARGET manifesto PROPERTY CXX_STANDARD 11) | ||
| 12 | set_property(TARGET manifesto PROPERTY CXX_STANDARD_REQUIRED ON) | ||
| 13 | 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 @@ | |||
| 1 | #include <yaml-cpp/yaml.h> | ||
| 2 | #include <twitter.h> | ||
| 3 | #include <fstream> | ||
| 4 | #include <iostream> | ||
| 5 | #include <thread> | ||
| 6 | #include <chrono> | ||
| 7 | |||
| 8 | int main(int argc, char** argv) | ||
| 9 | { | ||
| 10 | YAML::Node config = YAML::LoadFile("config.yml"); | ||
| 11 | |||
| 12 | twitter::auth auth; | ||
| 13 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | ||
| 14 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | ||
| 15 | auth.setAccessKey(config["access_key"].as<std::string>()); | ||
| 16 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | ||
| 17 | |||
| 18 | twitter::client client(auth); | ||
| 19 | |||
| 20 | long loc = 0; | ||
| 21 | if (config["current_location"]) | ||
| 22 | { | ||
| 23 | loc = config["current_location"].as<long>(); | ||
| 24 | } | ||
| 25 | |||
| 26 | std::list<std::string> tweets; | ||
| 27 | { | ||
| 28 | std::ifstream corpus(config["corpus"].as<std::string>()); | ||
| 29 | corpus.ignore(loc); | ||
| 30 | |||
| 31 | char buffer[140]; | ||
| 32 | while (corpus) | ||
| 33 | { | ||
| 34 | corpus.read(buffer, 140); | ||
| 35 | tweets.push_back(std::string(buffer, 140)); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | while (!tweets.empty()) | ||
| 40 | { | ||
| 41 | try | ||
| 42 | { | ||
| 43 | std::string nextTweet = tweets.front(); | ||
| 44 | client.updateStatus(nextTweet); | ||
| 45 | |||
| 46 | std::cout << "Tweeted!" << std::endl; | ||
| 47 | |||
| 48 | loc += 140; | ||
| 49 | { | ||
| 50 | std::ofstream fout("config.yml"); | ||
| 51 | config["current_location"] = loc; | ||
| 52 | fout << config; | ||
| 53 | } | ||
| 54 | |||
| 55 | tweets.pop_front(); | ||
| 56 | } catch (const twitter::twitter_error& e) | ||
| 57 | { | ||
| 58 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
| 59 | } | ||
| 60 | |||
| 61 | std::cout << "Waiting..." << std::endl; | ||
| 62 | |||
| 63 | std::this_thread::sleep_for(std::chrono::hours(6)); | ||
| 64 | } | ||
| 65 | } | ||
| diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 | |||
| Subproject febadca7d4e0460aa78f95b53b5e36e51fd2f97 | |||
| diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000 | |||
| Subproject 85af926ddc5f3c8fb438001743e65ec3a039cee | |||
