summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-10-20 08:58:20 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-10-20 08:58:20 -0400
commit9ab9e5fcbc1534111d74c688bf7ad6d6ad46ff2b (patch)
treeaae2c4d60588f32c94c7367df0b35664e468f86b
parent4dade1b6f4f2b37a7ae9e6b1f7ca28e880fd7098 (diff)
downloadinsult-9ab9e5fcbc1534111d74c688bf7ad6d6ad46ff2b.tar.gz
insult-9ab9e5fcbc1534111d74c688bf7ad6d6ad46ff2b.tar.bz2
insult-9ab9e5fcbc1534111d74c688bf7ad6d6ad46ff2b.zip
Switched from twitcurl to libtwitter++
Also updated verbly, switched from C random interface to C++ random
interface, and reworked the datafile to give the generated tweets a
different feel.
-rw-r--r--.gitmodules3
-rw-r--r--CMakeLists.txt9
-rw-r--r--chemist.cpp63
-rw-r--r--data.txt59
m---------vendor/libtwittercpp0
m---------vendor/twitcurl0
m---------vendor/verbly0
7 files changed, 84 insertions, 50 deletions
diff --git a/.gitmodules b/.gitmodules index 08a42de..2d58700 100644 --- a/.gitmodules +++ b/.gitmodules
@@ -7,3 +7,6 @@
7[submodule "vendor/yaml-cpp"] 7[submodule "vendor/yaml-cpp"]
8 path = vendor/yaml-cpp 8 path = vendor/yaml-cpp
9 url = https://github.com/jbeder/yaml-cpp 9 url = https://github.com/jbeder/yaml-cpp
10[submodule "vendor/libtwittercpp"]
11 path = vendor/libtwittercpp
12 url = https://github.com/hatkirby/libtwittercpp
diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d19b9..49b0d2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -3,15 +3,12 @@ project (chemist)
3 3
4set(CMAKE_BUILD_TYPE Debug) 4set(CMAKE_BUILD_TYPE Debug)
5 5
6find_package(PkgConfig)
7pkg_check_modules(sqlite3 sqlite3 REQUIRED)
8
9add_subdirectory(vendor/twitcurl/libtwitcurl)
10add_subdirectory(vendor/verbly) 6add_subdirectory(vendor/verbly)
11add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) 7add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL)
8add_subdirectory(vendor/libtwittercpp)
12 9
13include_directories(vendor/twitcurl/libtwitcurl ${sqlite3_INCLUDE_DIR} vendor/verbly/lib vendor/yaml-cpp/include) 10include_directories(vendor/verbly/lib vendor/yaml-cpp/include vendor/libtwittercpp/src)
14add_executable(chemist chemist.cpp) 11add_executable(chemist chemist.cpp)
15set_property(TARGET chemist PROPERTY CXX_STANDARD 11) 12set_property(TARGET chemist PROPERTY CXX_STANDARD 11)
16set_property(TARGET chemist PROPERTY CXX_STANDARD_REQUIRED ON) 13set_property(TARGET chemist PROPERTY CXX_STANDARD_REQUIRED ON)
17target_link_libraries(chemist verbly ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl) 14target_link_libraries(chemist verbly twitter++ yaml-cpp)
diff --git a/chemist.cpp b/chemist.cpp index fbf83a8..8b00d12 100644 --- a/chemist.cpp +++ b/chemist.cpp
@@ -1,23 +1,24 @@
1#include <yaml-cpp/yaml.h> 1#include <yaml-cpp/yaml.h>
2#include <iostream> 2#include <iostream>
3#include <cstdlib>
4#include <ctime>
5#include <sstream> 3#include <sstream>
6#include <twitcurl.h>
7#include <verbly.h> 4#include <verbly.h>
8#include <unistd.h> 5#include <fstream>
6#include <twitter.h>
7#include <random>
8#include <chrono>
9#include <thread>
9 10
10int main(int argc, char** argv) 11int main(int argc, char** argv)
11{ 12{
12 srand(time(NULL));
13
14 YAML::Node config = YAML::LoadFile("config.yml"); 13 YAML::Node config = YAML::LoadFile("config.yml");
15 14
16 twitCurl twitter; 15 twitter::auth auth;
17 twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>()); 16 auth.setConsumerKey(config["consumer_key"].as<std::string>());
18 twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>()); 17 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
19 twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>()); 18 auth.setAccessKey(config["access_key"].as<std::string>());
20 twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>()); 19 auth.setAccessSecret(config["access_secret"].as<std::string>());
20
21 twitter::client client(auth);
21 22
22 std::map<std::string, std::vector<std::string>> groups; 23 std::map<std::string, std::vector<std::string>> groups;
23 std::ifstream datafile("data.txt"); 24 std::ifstream datafile("data.txt");
@@ -51,6 +52,9 @@ int main(int argc, char** argv)
51 } 52 }
52 } 53 }
53 54
55 std::random_device random_device;
56 std::mt19937 random_engine{random_device()};
57
54 verbly::data database {"data.sqlite3"}; 58 verbly::data database {"data.sqlite3"};
55 for (;;) 59 for (;;)
56 { 60 {
@@ -77,6 +81,9 @@ int main(int argc, char** argv)
77 if (canontkn == "NOUN") 81 if (canontkn == "NOUN")
78 { 82 {
79 result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form(); 83 result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form();
84 } else if (canontkn == "ATTRIBUTE")
85 {
86 result = database.nouns().random().limit(1).full_hyponym_of(database.nouns().with_wnid(100024264).limit(1).run().front()).run().front().singular_form();
80 } else if (canontkn == "ADJECTIVE") 87 } else if (canontkn == "ADJECTIVE")
81 { 88 {
82 result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form(); 89 result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form();
@@ -85,7 +92,9 @@ int main(int argc, char** argv)
85 result = database.verbs().random().limit(1).run().front().ing_form(); 92 result = database.verbs().random().limit(1).run().front().ing_form();
86 } else if (canontkn == "YEAR") 93 } else if (canontkn == "YEAR")
87 { 94 {
88 result = std::to_string(rand() % 100 + 1916); 95 std::uniform_int_distribution<int> yeardist(1916,2015);
96 int year = yeardist(random_engine);
97 result = std::to_string(year);
89 } else if (canontkn == "REGION") 98 } else if (canontkn == "REGION")
90 { 99 {
91 auto hem1 = database.nouns().with_singular_form("eastern hemisphere").limit(1).run().front(); 100 auto hem1 = database.nouns().with_singular_form("eastern hemisphere").limit(1).run().front();
@@ -103,9 +112,14 @@ int main(int argc, char** argv)
103 { 112 {
104 auto bp = database.nouns().with_singular_form("body part").limit(1).run().front(); 113 auto bp = database.nouns().with_singular_form("body part").limit(1).run().front();
105 result = database.nouns().full_hyponym_of({bp}).with_complexity(1).random().limit(1).run().front().singular_form(); 114 result = database.nouns().full_hyponym_of({bp}).with_complexity(1).random().limit(1).run().front().singular_form();
115 } else if (canontkn == "\\N")
116 {
117 result = "\n";
106 } else { 118 } else {
107 auto group = groups[canontkn]; 119 auto group = groups[canontkn];
108 result = group[rand() % group.size()]; 120 std::uniform_int_distribution<int> groupdist(0, group.size()-1);
121 int groupind = groupdist(random_engine);
122 result = group[groupind];
109 } 123 }
110 124
111 if (modifier == "indefinite") 125 if (modifier == "indefinite")
@@ -144,18 +158,19 @@ int main(int argc, char** argv)
144 } 158 }
145 159
146 action.resize(140); 160 action.resize(140);
147 161
148 std::string replyMsg; 162 try
149 if (twitter.statusUpdate(action))
150 { 163 {
151 twitter.getLastWebResponse(replyMsg); 164 client.updateStatus(action);
152 std::cout << "Twitter message: " << replyMsg << std::endl; 165
153 } else { 166 std::cout << "Tweeted!" << std::endl;
154 twitter.getLastCurlError(replyMsg); 167 } catch (const twitter::twitter_error& e)
155 std::cout << "Curl error: " << replyMsg << std::endl; 168 {
169 std::cout << "Twitter error: " << e.what() << std::endl;
156 } 170 }
157 171
158 std::cout << "Waiting" << std::endl; 172 std::cout << "Waiting..." << std::endl;
159 sleep(60 * 60); 173
174 std::this_thread::sleep_for(std::chrono::hours(1));
160 } 175 }
161} 176}
diff --git a/data.txt b/data.txt index 8535d4e..77179de 100644 --- a/data.txt +++ b/data.txt
@@ -1,27 +1,27 @@
1MAIN 1MAIN
2{PRIMARY} {SECONDARY} 2{NAME} ({CLASS}){\n}{PRIMARY}{\n}{SECONDARY}
3 3
4PRIMARY 4PRIMARY
5{NAME} is {CLASS:indefinite} commonly used to treat {SYNDROME}. 5Used to treat {SYNDROME}
6{NAME} is {CLASS:indefinite} primarily used for {SYNDROME}. 6Treats the {adjective} symptoms of {SYNDROME}
7{NAME} is {CLASS:indefinite} prescribed for {SYNDROME}. 7Cures {SYNDROME}
8{NAME} is {CLASS:indefinite} approved for treatment of {SYNDROME}, and {SYNDROME}. 8Approved to treat {SYNDROME} and {SYNDROME}
9{NAME} is {CLASS:indefinite} used for {SYNDROME} and {SYNDROME}. 9Prescribed for {SYNDROME}
10{NAME} is {CLASS:indefinite} used with {EXISTENT} to treat {syndrome}. 10Used with {EXISTENT} to treat {SYNDROME}
11{NAME} is {CLASS:indefinite} used in cases of {EXISTENT} overdose. 11Used recreationally as {CLASS:indefinite}
12{NAME} is {CLASS:indefinite} used recreationally as {CLASS:indefinite}. 12Used recreationally for {verbing}
13{NAME} is {CLASS:indefinite} used recreationally for {verbing}.
14 13
15SECONDARY 14SECONDARY
16Developed due to the Great {Noun} Epidemic of {year} in {Region}. 15Developed after {year} {Noun} Pandemic
17Frequently prescribed off-label for {SYNDROME}. 16Often used off-label for {SYNDROME}
18Sometimes used for {SYNDROME} because of its {verbing} effect. 17Notable for its {adjective} effect
19Illegal to own in the US because of its {verbing} effect. 18Controlled in the US due to its {adjective} effect
20Developed in {year} to replace {EXISTENT}. 19Developed in {year} to replace {EXISTENT}
21Overtook {EXISTENT} due to its {adjective} effect. 20May cause {ADJECTIVE} feelings
22Synthesized by {FamousName} in {year} in a {verbing} accident. 21Obsoleted by {EXISTENT}
23Used mainly in {year}, before {EXISTENT} became popular. 22Contraindicated by {SYNDROME}
24Only legal in {Region} because of its {verbing} effect. 23Contraindicated by {EXISTENT}
24Decreases the {adjective} effects of {EXISTENT}
25 25
26SYNDROME 26SYNDROME
27irritable {noun} syndrome 27irritable {noun} syndrome
@@ -40,6 +40,16 @@ congenital {noun} disease
40{FamousName}'s disease 40{FamousName}'s disease
41{adjective} fever 41{adjective} fever
42hypo{noun}ism 42hypo{noun}ism
43{EXISTENT} overdose
44{CLASS} overdose
45{CLASS} discontinuation syndrome
46{noun} syndrome
47low {ATTRIBUTE}
48
49CLASSIFIER
50{CLASS:indefinite}
51{NAME}
52{EXISTENT}
43 53
44CLASS 54CLASS
45analgesic 55analgesic
@@ -84,6 +94,7 @@ SSRI
84anxiolytic 94anxiolytic
85antipanic agent 95antipanic agent
86tricyclic 96tricyclic
97tetracyclic
87MAOI 98MAOI
88SNRI 99SNRI
89antiandrogen 100antiandrogen
@@ -95,6 +106,7 @@ antiviral drug
95stimulant 106stimulant
96depressant 107depressant
97aphrodisiac 108aphrodisiac
109{EXISTENT} prodrug
98 110
99EXISTENT 111EXISTENT
100fluoxetine 112fluoxetine
@@ -153,6 +165,10 @@ Viagra
153heroin 165heroin
154morphine 166morphine
155crystal meth 167crystal meth
168mirtazapine
169Remeron
170Luvox
171fluvoxamine
156 172
157NAME 173NAME
158{PRENAME}{NAMEMID}{NAMEIFX} 174{PRENAME}{NAMEMID}{NAMEIFX}
@@ -196,6 +212,7 @@ Me
196Dibu 212Dibu
197Des 213Des
198Ha 214Ha
215Mir
199 216
200NAMEMID 217NAMEMID
201pipra 218pipra
@@ -228,6 +245,7 @@ va
228piva 245piva
229flu 246flu
230oxy 247oxy
248taz
231{NAMEMID}{NAMEMID} 249{NAMEMID}{NAMEMID}
232{NAMEMID}{NAMEMID} 250{NAMEMID}{NAMEMID}
233 251
@@ -257,4 +275,5 @@ rone
257ine 275ine
258caine 276caine
259rane 277rane
260ide \ No newline at end of file 278ide
279epine \ No newline at end of file
diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000
Subproject febadca7d4e0460aa78f95b53b5e36e51fd2f97
diff --git a/vendor/twitcurl b/vendor/twitcurl deleted file mode 160000
Subproject 6659e86de7481e50977b7569c75138f7f69ad3c
diff --git a/vendor/verbly b/vendor/verbly
Subproject 965a3206df834f846f2c560438c80a707dcee4c Subproject 6c2aca03c89b37e136ab4c7ea58b485dadc85bc