From f33210aebfa4fc8055566fe3bc2f38713b7fe1fb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 6 Feb 2017 21:05:15 -0500 Subject: Updated verbly (new API) Also updated libtwitter++, and blacklisted ethnic slurs. --- blessed.cpp | 67 ++++++++++++++++++++++++++-------------------------- vendor/libtwittercpp | 2 +- vendor/verbly | 2 +- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/blessed.cpp b/blessed.cpp index 2649f45..8bb8d3f 100644 --- a/blessed.cpp +++ b/blessed.cpp @@ -20,19 +20,19 @@ int main(int argc, char** argv) std::random_device random_device; std::mt19937 random_engine{random_device()}; - + YAML::Node config = YAML::LoadFile(configfile); - + 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); - - verbly::data database {config["verbly_datafile"].as()}; - + + verbly::database database {config["verbly_datafile"].as()}; + std::vector emojis; { std::ifstream emojifile(config["emoji_file"].as()); @@ -49,33 +49,33 @@ int main(int argc, char** argv) { line.pop_back(); } - + emojis.push_back(line); } } - + std::uniform_int_distribution emojidist(0, emojis.size()-1); std::bernoulli_distribution continuedist(1.0/2.0); - + + verbly::query verbQuery = database.forms( + (verbly::notion::partOfSpeech == verbly::part_of_speech::verb) + && (verbly::pronunciation::rhymes)); + for (;;) { std::cout << "Generating tweet..." << std::endl; - - std::string exclamation; - while (exclamation.empty()) - { - verbly::verb v = database.verbs().random().limit(1).has_pronunciation().run().front(); - auto rhyms = database.nouns().rhymes_with(v).random().limit(1).is_not_proper().run(); - if (!rhyms.empty()) - { - auto n = rhyms.front(); - if (n.base_form() != v.base_form()) - { - exclamation = "god " + v.base_form() + " this " + n.base_form(); - } - } - } - + + verbly::form verb = verbQuery.first(); + + verbly::form noun = database.forms( + (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) + && (verbly::pronunciation::rhymes %= verb) + && (verbly::form::proper == false) + && (verbly::form::id != verb.getId()) + && !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862))).first(); + + std::string exclamation = "god " + verb.getText() + " this " + noun.getText(); + std::string emojibef; std::string emojiaft; int emn = 0; @@ -86,7 +86,7 @@ int main(int argc, char** argv) emojibef += em; emojiaft = em + emojiaft; } while (continuedist(random_engine)); - + std::string result; if (emn > 3) { @@ -94,22 +94,23 @@ int main(int argc, char** argv) } else { result = emojibef + " " + exclamation + " " + emojiaft; } - + result.resize(140); std::cout << result << std::endl; - + try { client.updateStatus(result); - + std::cout << "Tweeted!" << std::endl; + std::cout << "Waiting..." << std::endl; + + std::this_thread::sleep_for(std::chrono::hours(1)); + + std::cout << std::endl; } 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(1)); } } diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp index d783c17..df90612 160000 --- a/vendor/libtwittercpp +++ b/vendor/libtwittercpp @@ -1 +1 @@ -Subproject commit d783c17151a98466e304b1e5f33bfca0be885fd8 +Subproject commit df906121dd862c0f704e44f28ee079158c431c41 diff --git a/vendor/verbly b/vendor/verbly index 1f898f3..f1f67e6 160000 --- a/vendor/verbly +++ b/vendor/verbly @@ -1 +1 @@ -Subproject commit 1f898f3bd66c29672275c2c884b17ba662ced626 +Subproject commit f1f67e62cebb4144f0599196263cd93b41fa972e -- cgit 1.4.1