about summary refs log tree commit diff stats
path: root/blessed.cpp
blob: 367d0d14895a835568e5ab9462470e323060a980 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <yaml-cpp/yaml.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <sstream>
#include <twitcurl.h>
#include <verbly.h>

int main(int argc, char** argv)
{
  srand(time(NULL));
  
  YAML::Node config = YAML::LoadFile("config.yml");
    
  twitCurl twitter;
  twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>());
  twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>());
  twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>());
  twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>());
  
  verbly::data database {"data.sqlite3"};
  
  std::vector<std::string> emojis;
  std::ifstream emojifile("emojis.txt");
  if (!emojifile.is_open())
  {
    std::cout << "Could not find emoji." << std::endl;
    return -1;
  }

  for (;;)
  {
    std::string line;
    if (!getline(emojifile, line))
    {
      break;
    }
  
    if (line.back() == '\r')
    {
      line.pop_back();
    }
    
    emojis.push_back(line);
  }
  
  for (;;)
  {
    std::cout << "Generating tweet" << std::endl;
    
    std::string exclamation;
    for (;;)
    {
      verbly::verb v = database.verbs().random(true).limit(1).has_pronunciation(true).run().front();
      auto rhyms = database.nouns().rhymes_with(v).random(true).limit(1).not_derived_from(v).is_not_proper(true).run();
      if (!rhyms.empty())
      {
        auto n = rhyms.front();
        if (n.base_form() != v.base_form())
        {
          exclamation = "god " + v.base_form() + " this " + n.base_form();
          break;
        }
      }
    }
    
    std::string emojibef;
    std::string emojiaft;
    do
    {
      std::string em = emojis[rand() % emojis.size()];
      emojibef += em;
      emojiaft = em + emojiaft;
    } while (rand() % 4 < 3);
    
    std::string result = emojibef + " " + exclamation + " " + emojiaft;
    result.resize(140);
    
    std::string replyMsg;
    if (twitter.statusUpdate(result))
    {
      twitter.getLastWebResponse(replyMsg);
      std::cout << "Twitter message: " << replyMsg << std::endl;
    } else {
      twitter.getLastCurlError(replyMsg);
      std::cout << "Curl error: " << replyMsg << std::endl;
    }
    
    std::cout << "Waiting" << std::endl;
    sleep(60 * 60);
  }
}