about summary refs log tree commit diff stats
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
downloadwordplay-aec538929aa73600be65e6bebf8322ed928f7fcf.tar.gz
wordplay-aec538929aa73600be65e6bebf8322ed928f7fcf.tar.bz2
wordplay-aec538929aa73600be65e6bebf8322ed928f7fcf.zip
Initial commit
-rw-r--r--.gitmodules12
-rw-r--r--CMakeLists.txt19
m---------vendor/twitcurl0
m---------vendor/verbly0
m---------vendor/yaml-cpp0
-rw-r--r--wordplay.cpp87
6 files changed, 118 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b678533 --- /dev/null +++ b/.gitmodules
@@ -0,0 +1,12 @@
1[submodule "verbly"]
2 path = verbly
3 url = https://github.com/hatkirby/verbly
4[submodule "vendor/verbly"]
5 path = vendor/verbly
6 url = https://github.com/hatkirby/verbly
7[submodule "vendor/twitcurl"]
8 path = vendor/twitcurl
9 url = https://github.com/swatkat/twitcurl
10[submodule "vendor/yaml-cpp"]
11 path = vendor/yaml-cpp
12 url = https://github.com/jbeder/yaml-cpp
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a7693ff --- /dev/null +++ b/CMakeLists.txt
@@ -0,0 +1,19 @@
1cmake_minimum_required (VERSION 2.6)
2project (wordplay)
3
4find_package(PkgConfig)
5pkg_check_modules(sqlite3 sqlite3 REQUIRED)
6
7add_subdirectory(vendor/twitcurl/libtwitcurl)
8include_directories(vendor/twitcurl/libtwitcurl)
9
10add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL)
11include_directories(vendor/yaml-cpp/include)
12
13add_subdirectory(vendor/verbly)
14include_directories(vendor/verbly/lib)
15
16add_executable(wordplay wordplay.cpp)
17set_property(TARGET wordplay PROPERTY CXX_STANDARD 11)
18set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON)
19target_link_libraries(wordplay ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl verbly)
diff --git a/vendor/twitcurl b/vendor/twitcurl new file mode 160000
Subproject 6659e86de7481e50977b7569c75138f7f69ad3c
diff --git a/vendor/verbly b/vendor/verbly new file mode 160000
Subproject be20f774b7be28a6c8b5359351dc1907d7ac7da
diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000
Subproject 57805dfd6a741e55477ea8d4d5b3b6f0272d1f0
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