about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-09-05 09:38:48 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-09-05 09:38:48 -0400
commit0d33589a9c457cd0c448817d3f21abd5a4125ec5 (patch)
tree53e3454c57be5a12de446151f4c4d41c63ab726b
parent4b2fd438e3a788e7ff07cc1f49fd0d91d7d1e068 (diff)
downloadyandere-0d33589a9c457cd0c448817d3f21abd5a4125ec5.tar.gz
yandere-0d33589a9c457cd0c448817d3f21abd5a4125ec5.tar.bz2
yandere-0d33589a9c457cd0c448817d3f21abd5a4125ec5.zip
Remembered to remove chemist.cpp
-rw-r--r--chemist.cpp161
1 files changed, 0 insertions, 161 deletions
diff --git a/chemist.cpp b/chemist.cpp deleted file mode 100644 index fbf83a8..0000000 --- a/chemist.cpp +++ /dev/null
@@ -1,161 +0,0 @@
1#include <yaml-cpp/yaml.h>
2#include <iostream>
3#include <cstdlib>
4#include <ctime>
5#include <sstream>
6#include <twitcurl.h>
7#include <verbly.h>
8#include <unistd.h>
9
10int main(int argc, char** argv)
11{
12 srand(time(NULL));
13
14 YAML::Node config = YAML::LoadFile("config.yml");
15
16 twitCurl twitter;
17 twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>());
18 twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>());
19 twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>());
20 twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>());
21
22 std::map<std::string, std::vector<std::string>> groups;
23 std::ifstream datafile("data.txt");
24 if (!datafile.is_open())
25 {
26 std::cout << "Could not find data.txt" << std::endl;
27 return 1;
28 }
29
30 bool newgroup = true;
31 std::string line;
32 std::string curgroup;
33 while (getline(datafile, line))
34 {
35 if (line.back() == '\r')
36 {
37 line.pop_back();
38 }
39
40 if (newgroup)
41 {
42 curgroup = line;
43 newgroup = false;
44 } else {
45 if (line.empty())
46 {
47 newgroup = true;
48 } else {
49 groups[curgroup].push_back(line);
50 }
51 }
52 }
53
54 verbly::data database {"data.sqlite3"};
55 for (;;)
56 {
57 std::cout << "Generating tweet" << std::endl;
58 std::string action = "{Main}";
59 int tknloc;
60 while ((tknloc = action.find("{")) != std::string::npos)
61 {
62 std::string token = action.substr(tknloc+1, action.find("}")-tknloc-1);
63 std::string modifier;
64 int modloc;
65 if ((modloc = token.find(":")) != std::string::npos)
66 {
67 modifier = token.substr(modloc+1);
68 token = token.substr(0, modloc);
69 }
70
71 std::string canontkn;
72 std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) {
73 return std::toupper(ch);
74 });
75
76 std::string result;
77 if (canontkn == "NOUN")
78 {
79 result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form();
80 } else if (canontkn == "ADJECTIVE")
81 {
82 result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form();
83 } else if (canontkn == "VERBING")
84 {
85 result = database.verbs().random().limit(1).run().front().ing_form();
86 } else if (canontkn == "YEAR")
87 {
88 result = std::to_string(rand() % 100 + 1916);
89 } else if (canontkn == "REGION")
90 {
91 auto hem1 = database.nouns().with_singular_form("eastern hemisphere").limit(1).run().front();
92 auto hem2 = database.nouns().with_singular_form("western hemisphere").limit(1).run().front();
93 verbly::filter<verbly::noun> region{hem1, hem2};
94 region.set_orlogic(true);
95
96 result = database.nouns().full_part_holonym_of(region).random().limit(1).run().front().singular_form();
97 } else if (canontkn == "FAMOUSNAME")
98 {
99 auto person = database.nouns().with_singular_form("person").limit(1).run().front();
100 auto ptypes = database.nouns().full_hyponym_of({person}).is_class().random().limit(1).run().front();
101 result = database.nouns().instance_of({ptypes}).random().limit(1).run().front().singular_form();
102 } else if (canontkn == "BODYPART")
103 {
104 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();
106 } else {
107 auto group = groups[canontkn];
108 result = group[rand() % group.size()];
109 }
110
111 if (modifier == "indefinite")
112 {
113 if ((result.length() > 1) && (isupper(result[0])) && (isupper(result[1])))
114 {
115 result = "an " + result;
116 } else if ((result[0] == 'a') || (result[0] == 'e') || (result[0] == 'i') || (result[0] == 'o') || (result[0] == 'u'))
117 {
118 result = "an " + result;
119 } else {
120 result = "a " + result;
121 }
122 }
123
124 std::string finalresult;
125 if (islower(token[0]))
126 {
127 std::transform(std::begin(result), std::end(result), std::back_inserter(finalresult), [] (char ch) {
128 return std::tolower(ch);
129 });
130 } else if (isupper(token[0]) && !isupper(token[1]))
131 {
132 auto words = verbly::split<std::list<std::string>>(result, " ");
133 for (auto& word : words)
134 {
135 word[0] = std::toupper(word[0]);
136 }
137
138 finalresult = verbly::implode(std::begin(words), std::end(words), " ");
139 } else {
140 finalresult = result;
141 }
142
143 action.replace(tknloc, action.find("}")-tknloc+1, finalresult);
144 }
145
146 action.resize(140);
147
148 std::string replyMsg;
149 if (twitter.statusUpdate(action))
150 {
151 twitter.getLastWebResponse(replyMsg);
152 std::cout << "Twitter message: " << replyMsg << std::endl;
153 } else {
154 twitter.getLastCurlError(replyMsg);
155 std::cout << "Curl error: " << replyMsg << std::endl;
156 }
157
158 std::cout << "Waiting" << std::endl;
159 sleep(60 * 60);
160 }
161}