From aec538929aa73600be65e6bebf8322ed928f7fcf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 19 Mar 2016 09:17:07 -0400 Subject: Initial commit --- wordplay.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 wordplay.cpp (limited to 'wordplay.cpp') diff --git a/wordplay.cpp b/wordplay.cpp new file mode 100644 index 0000000..74ac40d --- /dev/null +++ b/wordplay.cpp @@ -0,0 +1,87 @@ +#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"); + + for (;;) + { + // Generate the most amazing jokes you've ever heard + auto adjq = database.adjectives().has_pronunciation(true).has_synonyms(true).random(true).limit(1).run(); + if (adjq.empty()) + { + continue; + } + + verbly::adjective rhmadj = adjq.front(); + + auto nounq = database.nouns().rhymes_with(rhmadj).not_derived_from(rhmadj).is_hyponym(true).random(true).limit(1).run(); + if (nounq.empty()) + { + continue; + } + + verbly::noun rhmnoun = nounq.front(); + + auto hypq = database.nouns().hypernym_of(rhmnoun).random(true).limit(1).run(); + if (hypq.empty()) + { + continue; + } + + verbly::noun hyp = hypq.front(); + + auto synq = database.adjectives().synonym_of(rhmadj).random(true).limit(1).run(); + if (synq.empty()) + { + continue; + } + + verbly::adjective syn = synq.front(); + + std::stringstream result; + if (syn.starts_with_vowel_sound()) + { + result << "What do you call an " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl; + } else { + result << "What do you call a " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl; + } + + if (rhmadj.starts_with_vowel_sound()) + { + result << "An " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; + } else { + result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; + } + + std::string replyMsg; + if (twitter.statusUpdate(result.str())) + { + 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); + } +} \ No newline at end of file -- cgit 1.4.1