blob: 18a0a790667009df6bcd742d641ad707d0885b40 (
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
|
#include <cstdio>
#include <list>
#include <map>
#include "kgramstats.h"
#include <ctime>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <twitcurl.h>
#include <unistd.h>
#include <yaml-cpp/yaml.h>
int main(int argc, char** args)
{
srand(time(NULL));
YAML::Node config = YAML::LoadFile("config.yml");
int delay = config["delay"].as<int>();
std::ifstream infile(config["corpus"].as<std::string>().c_str());
std::string corpus;
std::string line;
while (getline(infile, line))
{
if (line.back() == '\r')
{
line.pop_back();
}
corpus += line + "\n ";
}
std::cout << "Preprocessing corpus..." << std::endl;
kgramstats* stats = new kgramstats(corpus, 4);
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>());
std::cout << "Generating..." << std::endl;
for (;;)
{
std::string doc = stats->randomSentence(rand() % 45 + 5);
std::string hi = doc;
hi.resize(140);
std::string replyMsg;
if (twitter.statusUpdate(hi))
{
twitter.getLastWebResponse(replyMsg);
std::cout << "Twitter message: " << replyMsg << std::endl;
} else {
twitter.getLastCurlError(replyMsg);
std::cout << "Curl error: " << replyMsg << std::endl;
}
sleep(rand() % delay);
}
return 0;
}
|