about summary refs log tree commit diff stats
path: root/wordplay.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-03-19 09:17:07 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-03-19 09:17:07 -0400
commitaec538929aa73600be65e6bebf8322ed928f7fcf (patch)
treecddfd984de04d553ccc2ffd83423894d0be175f9 /wordplay.cpp
downloadwordplay-aec538929aa73600be65e6bebf8322ed928f7fcf.tar.gz
wordplay-aec538929aa73600be65e6bebf8322ed928f7fcf.tar.bz2
wordplay-aec538929aa73600be65e6bebf8322ed928f7fcf.zip
Initial commit
Diffstat (limited to 'wordplay.cpp')
-rw-r--r--wordplay.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/wordplay.cpp b/wordplay.cpp new file mode 100644 index 0000000..74ac40d --- /dev/null +++ b/wordplay.cpp
@@ -0,0 +1,87 @@
1#include <yaml-cpp/yaml.h>
2#include <string>
3#include <iostream>
4#include <list>
5#include <algorithm>
6#include <twitcurl.h>
7#include <verbly.h>
8
9int main(int argc, char** argv)
10{
11 srand(time(NULL));
12
13 YAML::Node config = YAML::LoadFile("config.yml");
14
15 twitCurl twitter;
16 twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>());
17 twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>());
18 twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>());
19 twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>());
20
21 verbly::data database("data.sqlite3");
22
23 for (;;)
24 {
25 // Generate the most amazing jokes you've ever heard
26 auto adjq = database.adjectives().has_pronunciation(true).has_synonyms(true).random(true).limit(1).run();
27 if (adjq.empty())
28 {
29 continue;
30 }
31
32 verbly::adjective rhmadj = adjq.front();
33
34 auto nounq = database.nouns().rhymes_with(rhmadj).not_derived_from(rhmadj).is_hyponym(true).random(true).limit(1).run();
35 if (nounq.empty())
36 {
37 continue;
38 }
39
40 verbly::noun rhmnoun = nounq.front();
41
42 auto hypq = database.nouns().hypernym_of(rhmnoun).random(true).limit(1).run();
43 if (hypq.empty())
44 {
45 continue;
46 }
47
48 verbly::noun hyp = hypq.front();
49
50 auto synq = database.adjectives().synonym_of(rhmadj).random(true).limit(1).run();
51 if (synq.empty())
52 {
53 continue;
54 }
55
56 verbly::adjective syn = synq.front();
57
58 std::stringstream result;
59 if (syn.starts_with_vowel_sound())
60 {
61 result << "What do you call an " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl;
62 } else {
63 result << "What do you call a " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl;
64 }
65
66 if (rhmadj.starts_with_vowel_sound())
67 {
68 result << "An " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl;
69 } else {
70 result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl;
71 }
72
73 std::string replyMsg;
74 if (twitter.statusUpdate(result.str()))
75 {
76 twitter.getLastWebResponse(replyMsg);
77 std::cout << "Twitter message: " << replyMsg << std::endl;
78 } else {
79 twitter.getLastCurlError(replyMsg);
80 std::cout << "Curl error: " << replyMsg << std::endl;
81 }
82
83 std::cout << "Waiting" << std::endl;
84
85 sleep(60 * 60);
86 }
87} \ No newline at end of file