summary refs log tree commit diff stats
path: root/composite.cpp
blob: 2b33fb19702ed4d1b5cac032c6a870f234784fb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <verbly.h>
#include <yaml-cpp/yaml.h>
#include <twitter.h>
#include <chrono>
#include <string>
#include <thread>
#include <iostream>

int main(int argc, char** argv)
{
  if (argc != 2)
  {
    std::cout << "usage: composite [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<std::string>());
  auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
  auth.setAccessKey(config["access_key"].as<std::string>());
  auth.setAccessSecret(config["access_secret"].as<std::string>());
  
  twitter::client client(auth);
  verbly::data database(config["verbly_datafile"].as<std::string>());
    
  for (;;)
  {
    std::cout << "Generating..." << std::endl;
    auto nq = database.nouns().with_stress({{true, false, false}}).random().limit(1).run().front();
    std::string noun = nq.singular_form();
    noun[0] = std::toupper(noun[0]);
    
    std::string output = "Full Metal " + noun;
    std::cout << output << std::endl;
    
    try
    {
      client.updateStatus(output);
    } catch (const twitter::twitter_error& e)
    {
      std::cout << "Twitter error: " << e.what() << std::endl;
    }
    
    std::cout << "Waiting..." << std::endl;
    std::this_thread::sleep_for(std::chrono::hours(1));
  }
}