diff options
Diffstat (limited to 'lunatic.cpp')
-rw-r--r-- | lunatic.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/lunatic.cpp b/lunatic.cpp index 09dcc41..ca3140a 100644 --- a/lunatic.cpp +++ b/lunatic.cpp | |||
@@ -5,6 +5,8 @@ | |||
5 | #include <twitter.h> | 5 | #include <twitter.h> |
6 | #include <chrono> | 6 | #include <chrono> |
7 | #include <thread> | 7 | #include <thread> |
8 | #include <Magick++.h> | ||
9 | #include "database.h" | ||
8 | 10 | ||
9 | int main(int argc, char** argv) | 11 | int main(int argc, char** argv) |
10 | { | 12 | { |
@@ -14,6 +16,8 @@ int main(int argc, char** argv) | |||
14 | return -1; | 16 | return -1; |
15 | } | 17 | } |
16 | 18 | ||
19 | Magick::InitializeMagick(nullptr); | ||
20 | |||
17 | std::string configfile(argv[1]); | 21 | std::string configfile(argv[1]); |
18 | YAML::Node config = YAML::LoadFile(configfile); | 22 | YAML::Node config = YAML::LoadFile(configfile); |
19 | 23 | ||
@@ -23,7 +27,9 @@ int main(int argc, char** argv) | |||
23 | auth.setAccessKey(config["access_key"].as<std::string>()); | 27 | auth.setAccessKey(config["access_key"].as<std::string>()); |
24 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | 28 | auth.setAccessSecret(config["access_secret"].as<std::string>()); |
25 | 29 | ||
26 | twitter::client client(auth); | 30 | //twitter::client client(auth); |
31 | |||
32 | database db(config["database"].as<std::string>()); | ||
27 | 33 | ||
28 | std::random_device randomDevice; | 34 | std::random_device randomDevice; |
29 | std::mt19937 rng(randomDevice()); | 35 | std::mt19937 rng(randomDevice()); |
@@ -32,6 +38,40 @@ int main(int argc, char** argv) | |||
32 | { | 38 | { |
33 | std::cout << "Generating tweet" << std::endl; | 39 | std::cout << "Generating tweet" << std::endl; |
34 | 40 | ||
41 | achievement ach = db.getRandomAchievement(); | ||
42 | std::string imageName = db.getRandomImageForGame(ach.gameId); | ||
43 | std::string imagePath = config["images"].as<std::string>() | ||
44 | + "/" + imageName; | ||
45 | |||
46 | |||
47 | try | ||
48 | { | ||
49 | Magick::Image image; | ||
50 | image.read(imagePath); | ||
51 | image.transform("1600x900"); | ||
52 | image.scale("160x90"); | ||
53 | image.scale("1600x900"); | ||
54 | image.magick("png"); | ||
55 | image.write("output.png"); | ||
56 | } catch (const Magick::WarningCoder& ex) | ||
57 | { | ||
58 | // Ok | ||
59 | } | ||
60 | |||
61 | |||
62 | |||
63 | |||
64 | |||
65 | |||
66 | |||
67 | |||
68 | |||
69 | |||
70 | |||
71 | |||
72 | |||
73 | /* | ||
74 | |||
35 | // Reload achievements list every time in case it has been updated | 75 | // Reload achievements list every time in case it has been updated |
36 | std::vector<std::string> achievements; | 76 | std::vector<std::string> achievements; |
37 | std::ifstream datafile(config["achievements"].as<std::string>()); | 77 | std::ifstream datafile(config["achievements"].as<std::string>()); |
@@ -53,7 +93,7 @@ int main(int argc, char** argv) | |||
53 | } | 93 | } |
54 | 94 | ||
55 | std::uniform_int_distribution<int> dist(0, achievements.size() - 1); | 95 | std::uniform_int_distribution<int> dist(0, achievements.size() - 1); |
56 | std::string achievement = achievements[dist(rng)]; | 96 | std::string achievement = achievements[dist(rng)];*/ |
57 | 97 | ||
58 | std::string header; | 98 | std::string header; |
59 | if (std::bernoulli_distribution(1.0 / 50.0)(rng)) | 99 | if (std::bernoulli_distribution(1.0 / 50.0)(rng)) |
@@ -63,16 +103,16 @@ int main(int argc, char** argv) | |||
63 | header = "YOU GOT A MOON!"; | 103 | header = "YOU GOT A MOON!"; |
64 | } | 104 | } |
65 | 105 | ||
66 | std::string action = header + "\n" + achievement; | 106 | std::string action = header + "\n" + ach.title; |
67 | action.resize(140); | 107 | action.resize(140); |
68 | 108 | ||
69 | try | 109 | /*try |
70 | { | 110 | { |
71 | client.updateStatus(action); | 111 | client.updateStatus(action); |
72 | } catch (const twitter::twitter_error& e) | 112 | } catch (const twitter::twitter_error& e) |
73 | { | 113 | { |
74 | std::cout << "Twitter error: " << e.what() << std::endl; | 114 | std::cout << "Twitter error: " << e.what() << std::endl; |
75 | } | 115 | }*/ |
76 | 116 | ||
77 | std::cout << action << std::endl; | 117 | std::cout << action << std::endl; |
78 | std::cout << "Waiting" << std::endl; | 118 | std::cout << "Waiting" << std::endl; |