about summary refs log tree commit diff stats
path: root/wordplay.cpp
blob: 4f621a12dbe27a8a090decb0a681c6559baa6894 (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
#include <yaml-cpp/yaml.h>
#include <string>
#include <iostream>
#include <list>
#include <algorithm>
#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");
  
  for (;;)
  {
    // Generate the most amazing jokes you've ever heard
    auto adjq = database.adjectives().has_pronunciation(true).has_synonyms(true).random(true).limit(1).run();
    if (adjq.empty())
    {
      continue;
    }
    
    verbly::adjective rhmadj = adjq.front();
    
    auto nounq = database.nouns().rhymes_with(rhmadj).not_derived_from(rhmadj).is_hyponym(true).random(true).limit(1).run();
    if (nounq.empty())
    {
      continue;
    }
    
    verbly::noun rhmnoun = nounq.front();
    
    auto hypq = database.nouns().hypernym_of(rhmnoun).random(true).limit(1).run();
    if (hypq.empty())
    {
      continue;
    }
    
    verbly::noun hyp = hypq.front();
    
    auto synq = database.adjectives().synonym_of(rhmadj).random(true).limit(1).run();
    if (synq.empty())
    {
      continue;
    }
    
    verbly::adjective syn = synq.front();
    
    std::stringstream result;
    if (syn.starts_with_vowel_sound())
    {
      result << "What do you call an " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl;
    } else {
      result << "What do you call a " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl;
    }
    
    if (rhmadj.starts_with_vowel_sound())
    {
      result << "An " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl;
    } else {
      result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl;
    }
    
    std::string replyMsg;
    if (twitter.statusUpdate(result.str()))
    {
      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 * 3);
  }
}