#include #include #include #include #include #include #include "verbly/verbly.h" class fill_blanks { private: verbly::data& database; public: fill_blanks(verbly::data& database) : database(database) { } void visit(std::unique_ptr& it) { switch (it->token_type()) { case verbly::type::utterance: { auto& action = *dynamic_cast(it.get()); for (auto& tkn : action) { if (!tkn->complete()) { visit(tkn); break; } } break; } case verbly::type::fillin: { auto& tkn = *dynamic_cast(it.get()); switch (tkn.fillin_type()) { case verbly::fillin_type::participle_phrase: { const verbly::verb& v = database.verbs().random(true).limit(1).run().front(); /*verbly::utterance_token phrase = verbly::random(v.frames).make_utterance(); while (std::begin(phrase)->token_type() != verbly::type::verb) { phrase.erase(std::begin(phrase)); } *std::begin(phrase) = verbly::verb_token(v).conjugate(verbly::conjugation::present_participle); *it = phrase;*/ auto avt = std::make_unique(v); avt->conjugate(verbly::conjugation::present_participle); it = std::move(avt); break; } case verbly::fillin_type::adjective: { const verbly::adjective& adj = database.adjectives().random(true).limit(1).run().front(); it = std::make_unique(adj.value); break; } default: { it = std::make_unique("*the reality of the situation*"); break; } } break; } } } }; int main(int argc, char** argv) { srand(time(NULL)); YAML::Node config = YAML::LoadFile("config.yml"); const char* host = config["host"].as().c_str(); const char* user = config["user"].as().c_str(); const char* pass = config["pass"].as().c_str(); const char* db = config["db"].as().c_str(); 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()); for (;;) { std::cout << "Generating tweet" << std::endl; std::vector forms; forms.push_back({ new verbly::string_token("the furries are"), new verbly::fillin_token(verbly::fillin_type::participle_phrase) }); forms.push_back({ new verbly::string_token("the furries are"), new verbly::fillin_token(verbly::fillin_type::adjective) }); verbly::data database {"data.sqlite3"}; fill_blanks yeah {database}; std::unique_ptr action = std::make_unique(forms[rand() % forms.size()]); while (!action->complete()) { yeah.visit(action); } std::string result = action->compile(); result.resize(140); std::cout << result << std::endl; /* 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 * */ 3); } }