blob: ca3140a8fe3e0d1b7fef1c6da9272d2ab57302c0 (
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
|
#include <yaml-cpp/yaml.h>
#include <iostream>
#include <random>
#include <fstream>
#include <twitter.h>
#include <chrono>
#include <thread>
#include <Magick++.h>
#include "database.h"
int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "usage: lunatic [configfile]" << std::endl;
return -1;
}
Magick::InitializeMagick(nullptr);
std::string configfile(argv[1]);
YAML::Node config = YAML::LoadFile(configfile);
twitter::auth auth;
auth.setConsumerKey(config["consumer_key"].as<std::string>());
auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
auth.setAccessKey(config["access_key"].as<std::string>());
auth.setAccessSecret(config["access_secret"].as<std::string>());
//twitter::client client(auth);
database db(config["database"].as<std::string>());
std::random_device randomDevice;
std::mt19937 rng(randomDevice());
for (;;)
{
std::cout << "Generating tweet" << std::endl;
achievement ach = db.getRandomAchievement();
std::string imageName = db.getRandomImageForGame(ach.gameId);
std::string imagePath = config["images"].as<std::string>()
+ "/" + imageName;
try
{
Magick::Image image;
image.read(imagePath);
image.transform("1600x900");
image.scale("160x90");
image.scale("1600x900");
image.magick("png");
image.write("output.png");
} catch (const Magick::WarningCoder& ex)
{
// Ok
}
/*
// Reload achievements list every time in case it has been updated
std::vector<std::string> achievements;
std::ifstream datafile(config["achievements"].as<std::string>());
if (!datafile.is_open())
{
std::cout << "Could not find achievements file." << std::endl;
return 1;
}
std::string line;
while (getline(datafile, line))
{
if (line.back() == '\r')
{
line.pop_back();
}
achievements.push_back(line);
}
std::uniform_int_distribution<int> dist(0, achievements.size() - 1);
std::string achievement = achievements[dist(rng)];*/
std::string header;
if (std::bernoulli_distribution(1.0 / 50.0)(rng))
{
header = "YOU GOT A MULTI MOON!";
} else {
header = "YOU GOT A MOON!";
}
std::string action = header + "\n" + ach.title;
action.resize(140);
/*try
{
client.updateStatus(action);
} catch (const twitter::twitter_error& e)
{
std::cout << "Twitter error: " << e.what() << std::endl;
}*/
std::cout << action << std::endl;
std::cout << "Waiting" << std::endl;
std::this_thread::sleep_for(std::chrono::hours(1));
std::cout << std::endl;
}
}
|