From d5c32fc3f885a7b8f719c9f27dbba36e287222f0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 13 Dec 2016 19:24:06 -0500 Subject: Bot now takes path to config file as argument That config file now also has to contain the paths to the verbly datafile, the forms file, the fonts directory, and the color palettes file. --- infinite.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'infinite.cpp') diff --git a/infinite.cpp b/infinite.cpp index a491302..1409ba2 100644 --- a/infinite.cpp +++ b/infinite.cpp @@ -439,7 +439,15 @@ int main(int argc, char** argv) Magick::InitializeMagick(nullptr); - YAML::Node config = YAML::LoadFile("config.yml"); + if (argc != 2) + { + std::cout << "usage: infinite [configfile]" << std::endl; + return -1; + } + + std::string configfile(argv[1]); + YAML::Node config = YAML::LoadFile(configfile); + twitter::auth auth; auth.setConsumerKey(config["consumer_key"].as()); auth.setConsumerSecret(config["consumer_secret"].as()); @@ -451,10 +459,10 @@ int main(int argc, char** argv) // Parse forms file std::map> groups; { - std::ifstream datafile("forms.txt"); + std::ifstream datafile(config["forms_file"].as()); if (!datafile.is_open()) { - std::cout << "Could not find forms.txt" << std::endl; + std::cout << "Could not find forms file" << std::endl; return 1; } @@ -484,11 +492,12 @@ int main(int argc, char** argv) } // Read in fonts + std::string fontsdirname = config["fonts"].as(); std::vector fonts; { DIR* fontdir; struct dirent* ent; - if ((fontdir = opendir("fonts")) == nullptr) + if ((fontdir = opendir(fontsdirname.c_str())) == nullptr) { std::cout << "Couldn't find fonts." << std::endl; return -1; @@ -506,7 +515,9 @@ int main(int argc, char** argv) closedir(fontdir); } - verbly::data database {"data.sqlite3"}; + std::string colorsfile(config["colors"].as()); + + verbly::data database {config["verbly_datafile"].as()}; for (;;) { @@ -614,7 +625,7 @@ int main(int argc, char** argv) { std::cout << "Generating flame fractal..." << std::endl; - Fractal fractal = Fractal::random(); + Fractal fractal = Fractal::random(colorsfile); std::vector irradiance(target_w*target_h*sample_rate*sample_rate, Color(0.0, 0.0, 0.0, 0.0)); double x = (double)rand()/(double)RAND_MAX*2.0-1.0; @@ -730,7 +741,7 @@ int main(int argc, char** argv) // Put text on top of the fractal std::string subaction = action; std::string font = fonts[rand() % fonts.size()]; - if (font == "Le_Super_Type_SemiBold.ttf") + if (font.find("Le_Super_Type_SemiBold.ttf") != std::string::npos) { std::transform(std::begin(subaction), std::end(subaction), std::begin(subaction), [] (char ch) { return std::toupper(ch); @@ -741,7 +752,7 @@ int main(int argc, char** argv) textimage.type(Magick::TrueColorMatteType); textimage.fillColor(Magick::Color("white")); textimage.fontPointsize(72.0); - textimage.font("fonts/" + font); + textimage.font(fontsdirname + "/" + font); auto words = verbly::split>(subaction, " "); std::string towrite = ""; -- cgit 1.4.1