From 473b327ceed3afb5e5683002b39fd9c1947cb25a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 1 Mar 2018 16:03:16 -0500 Subject: 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. --- lunatic.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'lunatic.cpp') diff --git a/lunatic.cpp b/lunatic.cpp index 09dcc41..ca3140a 100644 --- a/lunatic.cpp +++ b/lunatic.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include "database.h" int main(int argc, char** argv) { @@ -14,6 +16,8 @@ int main(int argc, char** argv) return -1; } + Magick::InitializeMagick(nullptr); + std::string configfile(argv[1]); YAML::Node config = YAML::LoadFile(configfile); @@ -23,7 +27,9 @@ int main(int argc, char** argv) auth.setAccessKey(config["access_key"].as()); auth.setAccessSecret(config["access_secret"].as()); - twitter::client client(auth); + //twitter::client client(auth); + + database db(config["database"].as()); std::random_device randomDevice; std::mt19937 rng(randomDevice()); @@ -32,6 +38,40 @@ int main(int argc, char** argv) { std::cout << "Generating tweet" << std::endl; + achievement ach = db.getRandomAchievement(); + std::string imageName = db.getRandomImageForGame(ach.gameId); + std::string imagePath = config["images"].as() + + "/" + 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 achievements; std::ifstream datafile(config["achievements"].as()); @@ -53,7 +93,7 @@ int main(int argc, char** argv) } std::uniform_int_distribution dist(0, achievements.size() - 1); - std::string achievement = achievements[dist(rng)]; + std::string achievement = achievements[dist(rng)];*/ std::string header; if (std::bernoulli_distribution(1.0 / 50.0)(rng)) @@ -63,16 +103,16 @@ int main(int argc, char** argv) header = "YOU GOT A MOON!"; } - std::string action = header + "\n" + achievement; + std::string action = header + "\n" + ach.title; action.resize(140); - try + /*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; -- cgit 1.4.1