about summary refs log tree commit diff stats
path: root/lunatic.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-03-01 16:03:16 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-03-01 16:03:16 -0500
commit473b327ceed3afb5e5683002b39fd9c1947cb25a (patch)
tree0dd2eac68605ad8cf34a2e2e54c6a44ad3ab14c1 /lunatic.cpp
parentd85fed8541a9580e820a907d83a2184b020572ba (diff)
downloadlunatic-473b327ceed3afb5e5683002b39fd9c1947cb25a.tar.gz
lunatic-473b327ceed3afb5e5683002b39fd9c1947cb25a.tar.bz2
lunatic-473b327ceed3afb5e5683002b39fd9c1947cb25a.zip
Redesigned persistent data formta
This is the start of a project to add imagery to the bot's output. We began by rewriting the scraper to use a SQLite datafile instead of dumping achievement names to a text file. This allows storage of additional information about each achievement, and allows for more sophisticated scraping.

Profiles to be scraped can be added on the command line using the scraper script, instead of being specified in a config file. The scraper can conduct full or delta scrapes; in a delta scrape, only each profile's recent games are scraped, whereas they are all scraped in a full scrape.

When a game is scraped for the first time, images from the store page of that game are saved locally to be used by the bot. The bot has been altered to not use Twitter, and instead generate a pixelated image based on an image from the game of the chosen achievement. This is just for development purposes. It also crashes occasionally due to picking an achievement from a game that does not have any images saved.

Sprites of the moons from Odyssey have been included in the repository. A short message denoting their copyright is included.
Diffstat (limited to 'lunatic.cpp')
-rw-r--r--lunatic.cpp50
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
9int main(int argc, char** argv) 11int 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;