diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-01-19 08:31:31 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-01-19 08:31:31 -0500 |
| commit | b9de9aed566b6ea24a449026ab72eccdeb7fddc5 (patch) | |
| tree | 8e4ea731acb49729a95f464c27ffb97ce4c66372 /furries.cpp | |
| download | furries-b9de9aed566b6ea24a449026ab72eccdeb7fddc5.tar.gz furries-b9de9aed566b6ea24a449026ab72eccdeb7fddc5.tar.bz2 furries-b9de9aed566b6ea24a449026ab72eccdeb7fddc5.zip | |
the furries are begun with basic functionality
Only adverbs and basic adjectives are implemented.
Diffstat (limited to 'furries.cpp')
| -rw-r--r-- | furries.cpp | 191 |
1 files changed, 191 insertions, 0 deletions
| diff --git a/furries.cpp b/furries.cpp new file mode 100644 index 0000000..94d0e71 --- /dev/null +++ b/furries.cpp | |||
| @@ -0,0 +1,191 @@ | |||
| 1 | #include <yaml-cpp/yaml.h> | ||
| 2 | #include <iostream> | ||
| 3 | #include <mysql.h> | ||
| 4 | #include <cstdlib> | ||
| 5 | #include <ctime> | ||
| 6 | #include <sstream> | ||
| 7 | #include <twitcurl.h> | ||
| 8 | |||
| 9 | int db_error(MYSQL* driver, const char* error) | ||
| 10 | { | ||
| 11 | std::cout << error << ": " << mysql_error(driver) << std::endl; | ||
| 12 | return 1; | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(int argc, char** argv) | ||
| 16 | { | ||
| 17 | srand(time(NULL)); | ||
| 18 | |||
| 19 | YAML::Node config = YAML::LoadFile("config.yml"); | ||
| 20 | const char* host = config["host"].as<std::string>().c_str(); | ||
| 21 | const char* user = config["user"].as<std::string>().c_str(); | ||
| 22 | const char* pass = config["pass"].as<std::string>().c_str(); | ||
| 23 | const char* db = config["db"].as<std::string>().c_str(); | ||
| 24 | |||
| 25 | MYSQL* driver = mysql_init(NULL); | ||
| 26 | if (!mysql_real_connect(driver, host, user, pass, db, 0, NULL, 0)) | ||
| 27 | { | ||
| 28 | return db_error(driver, "Error connecting to database"); | ||
| 29 | } | ||
| 30 | |||
| 31 | twitCurl twitter; | ||
| 32 | twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>()); | ||
| 33 | twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>()); | ||
| 34 | twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>()); | ||
| 35 | twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>()); | ||
| 36 | |||
| 37 | for (;;) | ||
| 38 | { | ||
| 39 | std::cout << "Generating tweet" << std::endl; | ||
| 40 | |||
| 41 | std::stringstream output; | ||
| 42 | output << "the furries are "; | ||
| 43 | |||
| 44 | //if (rand() % 2 == 0) | ||
| 45 | { | ||
| 46 | // Adverb(s) + Adjective | ||
| 47 | while (rand() % 4 == 0) | ||
| 48 | { | ||
| 49 | const char* getadverb = "SELECT ss1.word FROM wn_pertainym INNER JOIN wn_synset AS ss1 ON wn_pertainym.synset_id_1 = ss1.synset_id AND wn_pertainym.wnum_1 = ss1.w_num INNER JOIN wn_synset AS ss2 ON wn_pertainym.synset_id_2 = ss2.synset_id AND wn_pertainym.wnum_2 = ss2.w_num WHERE ss1.ss_type = 'r' ORDER BY RAND() LIMIT 1"; | ||
| 50 | if (mysql_query(driver, getadverb)) return db_error(driver, "Query failed"); | ||
| 51 | MYSQL_RES* getadverb2 = mysql_use_result(driver); if (getadverb2 == NULL) return db_error(driver, "Query failed"); | ||
| 52 | MYSQL_ROW getadverb3 = mysql_fetch_row(getadverb2); if (getadverb3 == NULL) return db_error(driver, "Query failed"); | ||
| 53 | output << getadverb3[0] << " "; | ||
| 54 | mysql_free_result(getadverb2); | ||
| 55 | } | ||
| 56 | |||
| 57 | const char* getword = "SELECT word FROM wn_synset WHERE ss_type = 'a' OR ss_type = 's' ORDER BY RAND() LIMIT 1"; | ||
| 58 | if (mysql_query(driver, getword)) return db_error(driver, "Query failed"); | ||
| 59 | MYSQL_RES* getword2 = mysql_use_result(driver); if (getword2 == NULL) return db_error(driver, "Query failed"); | ||
| 60 | MYSQL_ROW getword3 = mysql_fetch_row(getword2); if (getword3 == NULL) return db_error(driver, "Query failed"); | ||
| 61 | output << getword3[0]; | ||
| 62 | mysql_free_result(getword2); | ||
| 63 | } /*else { | ||
| 64 | // Verb phrase | ||
| 65 | const char* getword = "SELECT word FROM wn_synset WHERE ss_type = 'a ' OR ss_type = 's' ORDER BY RAND() LIMIT 1"; | ||
| 66 | if (mysql_query(driver, getword)) return db_error(driver, "Query failed"); | ||
| 67 | MYSQL_RES* getword2 = mysql_use_result(driver); if (getword2 == NULL) return db_error(driver, "Query failed"); | ||
| 68 | MYSQL_ROW getword3 = mysql_fetch_row(getword2); if (getword3 == NULL) return db_error(driver, "Query failed"); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | if (rand() % 2 == 0) | ||
| 75 | { | ||
| 76 | std::stringstream ispart; | ||
| 77 | ispart << "SELECT wn_verb_frame.f_num FROM wn_participle INNER JOIN wn_verb_frame ON wn_verb_frame.synset_id_1 = synset_id_2 AND (wn_verb_frame.w_num = wnum_2 OR wn_verb_frame.w_num = 0) WHERE wn_participle.synset_id_1 = " << wordssid << " AND wn_participle.wnum_1 = " << wordnum; | ||
| 78 | if (mysql_query(driver, ispart.str().c_str())) return db_error(driver, "Query failed"); | ||
| 79 | MYSQL_RES* ispart2 = mysql_use_result(driver); if (ispart2 == NULL) return db_error(driver, "Query failed"); | ||
| 80 | MYSQL_ROW ispart3 = mysql_fetch_row(ispart2); | ||
| 81 | mysql_free_result(ispart2); | ||
| 82 | |||
| 83 | if (ispart3 != NULL) | ||
| 84 | { | ||
| 85 | int frame = atoi(ispart3[0]); | ||
| 86 | std::cout << "frame " << frame << std::endl; | ||
| 87 | |||
| 88 | if (frame == 4 || frame == 22) | ||
| 89 | { | ||
| 90 | // the furries are ----ing *prepositional phrase* | ||
| 91 | // ex: the furries are laughing over there | ||
| 92 | } else if (frame == 5) | ||
| 93 | { | ||
| 94 | // the furries are ----ing something *adj/n* | ||
| 95 | // ex: the furries are regarding life inconsequential | ||
| 96 | } else if (frame == 6 || frame == 7) | ||
| 97 | { | ||
| 98 | // the furries are ----ing *adj/n* | ||
| 99 | // ex: the furries are turning gay | ||
| 100 | } else if (frame == 8 || frame == 9 || frame == 10 || frame == 11) | ||
| 101 | { | ||
| 102 | // the furries are ----ing something/somebody | ||
| 103 | // ex: the furries are holding hostages | ||
| 104 | } else if (frame == 12 || frame == 27) | ||
| 105 | { | ||
| 106 | // the furries are ----ing to somebody | ||
| 107 | // ex: the furries are appealing to God | ||
| 108 | } else if (frame == 13) | ||
| 109 | { | ||
| 110 | // the furries are ----ing on something | ||
| 111 | // ex: the furries are lecturing on heterosexuality | ||
| 112 | } else if (frame == 14) | ||
| 113 | { | ||
| 114 | // the furries are ----ing somebody something | ||
| 115 | // ex: the furries are reading your mom the menu | ||
| 116 | } else if (frame == 15) | ||
| 117 | { | ||
| 118 | // the furries are ----ing something to somebody | ||
| 119 | // ex: the furries are pitching a product to Apple | ||
| 120 | } else if (frame == 16) | ||
| 121 | { | ||
| 122 | // the furries are ----ing something from somebody | ||
| 123 | // ex: the furries are separating your money from you | ||
| 124 | } else if (frame == 17) | ||
| 125 | { | ||
| 126 | // the furries are ----ing somebody with something | ||
| 127 | // ex: the furries are injecting me with solemnity | ||
| 128 | } else if (frame == 18) | ||
| 129 | { | ||
| 130 | // the furries are ----ing somebody of something | ||
| 131 | // ex: the furries are depriving me of hope | ||
| 132 | } else if (frame == 19) | ||
| 133 | { | ||
| 134 | // the furries are ----ing something on somebody | ||
| 135 | // ex: the furries are forcing pervision on us | ||
| 136 | } else if (frame == 20 || frame == 21) | ||
| 137 | { | ||
| 138 | // the furries are ----ing somebody/something *prepositional phrase* | ||
| 139 | // ex: the furries are leaving us behind | ||
| 140 | } else if (frame == 24) | ||
| 141 | { | ||
| 142 | // the furries are ----ing somebody to INF | ||
| 143 | // ex: the furries are getting us to eat | ||
| 144 | } else if (frame == 25) | ||
| 145 | { | ||
| 146 | // the furries are ----ing somebody INF | ||
| 147 | // ex: the furries are making us procreate | ||
| 148 | } else if (frame == 26) | ||
| 149 | { | ||
| 150 | // the furries are ----ing that CLAUSE | ||
| 151 | // ex: the furries are understaing that life is precious | ||
| 152 | } else if (frame == 28) | ||
| 153 | { | ||
| 154 | // the furries are ----ing to INF | ||
| 155 | // ex: the furries are beginning to understand | ||
| 156 | } else if (frame == 29) | ||
| 157 | { | ||
| 158 | // the furries are ----ing whether to INF | ||
| 159 | // ex: the furries are deciding whether to hallucinate | ||
| 160 | } else if (frame == 30) | ||
| 161 | { | ||
| 162 | // the furries are ----ing somebody into V-ing something | ||
| 163 | // ex: the furries are tempting me into consecrating a magnet | ||
| 164 | } else if (frame == 31) | ||
| 165 | { | ||
| 166 | // the furries are ----ing something with something | ||
| 167 | // ex: the furries are replacing existence with solidarity | ||
| 168 | } | ||
| 169 | } | ||
| 170 | } | ||
| 171 | */ | ||
| 172 | |||
| 173 | std::string result = output.str(); | ||
| 174 | result.resize(140); | ||
| 175 | |||
| 176 | std::string replyMsg; | ||
| 177 | if (twitter.statusUpdate(result)) | ||
| 178 | { | ||
| 179 | twitter.getLastWebResponse(replyMsg); | ||
| 180 | std::cout << "Twitter message: " << replyMsg << std::endl; | ||
| 181 | } else { | ||
| 182 | twitter.getLastCurlError(replyMsg); | ||
| 183 | std::cout << "Curl error: " << replyMsg << std::endl; | ||
| 184 | } | ||
| 185 | |||
| 186 | std::cout << "Waiting" << std::endl; | ||
| 187 | sleep(60 * 60 * 3); | ||
| 188 | } | ||
| 189 | |||
| 190 | mysql_close(driver); | ||
| 191 | } | ||
