blob: 9f95dc9620fa359200ac971165a81d1738ee43a4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#include <yaml-cpp/yaml.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <sstream>
#include <twitcurl.h>
#include <verbly.h>
class fill_blanks {
private:
verbly::data& database;
public:
fill_blanks(verbly::data& database) : database(database)
{
}
void visit(std::unique_ptr<verbly::token>& it)
{
switch (it->token_type())
{
case verbly::token::type::utterance:
{
auto& action = *dynamic_cast<verbly::utterance_token*>(it.get());
for (auto& tkn : action)
{
if (!tkn->complete())
{
visit(tkn);
break;
}
}
break;
}
case verbly::token::type::fillin:
{
auto& tkn = *dynamic_cast<verbly::fillin_token*>(it.get());
switch (tkn.fillin_type())
{
case verbly::fillin_type::participle_phrase:
{
verbly::verb v = database.verbs().random(true).limit(1).run().front();
/*verbly::utterance_token phrase = verbly::random(v.frames).make_utterance();
while (std::begin(phrase)->token_type() != verbly::type::verb)
{
phrase.erase(std::begin(phrase));
}
*std::begin(phrase) = verbly::verb_token(v).conjugate(verbly::conjugation::present_participle);
*it = phrase;*/
auto avt = std::make_unique<verbly::verb_token>(v);
avt->inflect(verbly::verb_token::inflection::ing_form);
it = std::move(avt);
break;
}
case verbly::fillin_type::adjective:
{
verbly::adjective adj = database.adjectives().random(true).limit(1).run().front();
it = std::make_unique<verbly::string_token>(adj.base_form());
break;
}
case verbly::fillin_type::adverb:
{
verbly::adverb adv = database.adverbs().random(true).limit(1).run().front();
it = std::make_unique<verbly::string_token>(adv.base_form());
break;
}
default:
{
it = std::make_unique<verbly::string_token>("*the reality of the situation*");
break;
}
}
break;
}
}
}
};
int main(int argc, char** argv)
{
srand(time(NULL));
YAML::Node config = YAML::LoadFile("config.yml");
twitCurl twitter;
twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>());
twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>());
twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>());
twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>());
for (;;)
{
std::cout << "Generating tweet" << std::endl;
std::vector<verbly::utterance_token> forms;
forms.push_back({
new verbly::string_token("the furries are"),
new verbly::fillin_token(verbly::fillin_type::participle_phrase)
});
forms.push_back({
new verbly::string_token("the furries are"),
new verbly::fillin_token(verbly::fillin_type::adjective)
});
forms.push_back({
new verbly::string_token("the furries are"),
new verbly::fillin_token(verbly::fillin_type::adverb),
new verbly::fillin_token(verbly::fillin_type::adjective)
});
verbly::data database {"data.sqlite3"};
fill_blanks yeah {database};
std::unique_ptr<verbly::token> action = std::make_unique<verbly::utterance_token>(forms[rand() % forms.size()]);
while (!action->complete())
{
yeah.visit(action);
}
std::string result = action->compile();
result.resize(140);
std::string replyMsg;
if (twitter.statusUpdate(result))
{
twitter.getLastWebResponse(replyMsg);
std::cout << "Twitter message: " << replyMsg << std::endl;
} else {
twitter.getLastCurlError(replyMsg);
std::cout << "Curl error: " << replyMsg << std::endl;
}
std::cout << "Waiting" << std::endl;
sleep(60 * 60 * 3);
}
}
|