From 64c87158afe212d73e5007d48097c4877d56b19b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 17 Mar 2016 01:16:51 -0400 Subject: Initial commit --- blessed.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 blessed.cpp (limited to 'blessed.cpp') diff --git a/blessed.cpp b/blessed.cpp new file mode 100644 index 0000000..367d0d1 --- /dev/null +++ b/blessed.cpp @@ -0,0 +1,92 @@ +#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()); + + verbly::data database {"data.sqlite3"}; + + std::vector emojis; + std::ifstream emojifile("emojis.txt"); + if (!emojifile.is_open()) + { + std::cout << "Could not find emoji." << std::endl; + return -1; + } + + for (;;) + { + std::string line; + if (!getline(emojifile, line)) + { + break; + } + + if (line.back() == '\r') + { + line.pop_back(); + } + + emojis.push_back(line); + } + + for (;;) + { + std::cout << "Generating tweet" << std::endl; + + std::string exclamation; + for (;;) + { + verbly::verb v = database.verbs().random(true).limit(1).has_pronunciation(true).run().front(); + auto rhyms = database.nouns().rhymes_with(v).random(true).limit(1).not_derived_from(v).is_not_proper(true).run(); + if (!rhyms.empty()) + { + auto n = rhyms.front(); + if (n.base_form() != v.base_form()) + { + exclamation = "god " + v.base_form() + " this " + n.base_form(); + break; + } + } + } + + std::string emojibef; + std::string emojiaft; + do + { + std::string em = emojis[rand() % emojis.size()]; + emojibef += em; + emojiaft = em + emojiaft; + } while (rand() % 4 < 3); + + std::string result = emojibef + " " + exclamation + " " + emojiaft; + result.resize(140); + + std::string replyMsg; + if (twitter.statusUpdate(result)) + { + twitter.getLastWebResponse(replyMsg); + std::cout << "Twitter message: " << replyMsg << std::endl; + } else { + twitter.getLastCurlError(replyMsg); + std::cout << "Curl error: " << replyMsg << std::endl; + } + + std::cout << "Waiting" << std::endl; + sleep(60 * 60); + } +} -- cgit 1.4.1