From 93f1f3ad274de032e1b023eb1262cee1c61181ae Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 2 Oct 2016 15:36:33 -0400 Subject: Initial commit --- manifesto.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 manifesto.cpp (limited to 'manifesto.cpp') 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)); + } +} -- cgit 1.4.1