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. --- fractal.cpp | 6 +++--- fractal.h | 2 +- infinite.cpp | 27 +++++++++++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/fractal.cpp b/fractal.cpp index 145886a..a911177 100644 --- a/fractal.cpp +++ b/fractal.cpp @@ -508,7 +508,7 @@ int Fractal::load(const char* filename, Fractal& fractal) return 0; } -Fractal Fractal::random() +Fractal Fractal::random(std::string colorsfile) { Fractal fractal; @@ -577,10 +577,10 @@ Fractal Fractal::random() } std::vector colors; - std::ifstream colorfile("colors.txt"); + std::ifstream colorfile(colorsfile); if (!colorfile.is_open()) { - std::cout << "Could not find colors.txt" << std::endl; + std::cout << "Could not find colors file" << std::endl; exit(-1); } diff --git a/fractal.h b/fractal.h index af098f4..cfd39db 100644 --- a/fractal.h +++ b/fractal.h @@ -50,7 +50,7 @@ class Fractal { Color get_color(double c) const; static int load(const char* filename, Fractal& fractal); - static Fractal random(); + static Fractal random(std::string colorsfile); double filterlevel = 0.5; double gamma = 2.2; 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