about summary refs log tree commit diff stats
path: root/blessed.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-03-17 01:16:51 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-03-17 01:16:51 -0400
commit64c87158afe212d73e5007d48097c4877d56b19b (patch)
tree9f4df23a4c7295e421f11ab1dfab581edc5575eb /blessed.cpp
downloadblessed-64c87158afe212d73e5007d48097c4877d56b19b.tar.gz
blessed-64c87158afe212d73e5007d48097c4877d56b19b.tar.bz2
blessed-64c87158afe212d73e5007d48097c4877d56b19b.zip
Initial commit
Diffstat (limited to 'blessed.cpp')
-rw-r--r--blessed.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/blessed.cpp b/blessed.cpp new file mode 100644 index 0000000..367d0d1 --- /dev/null +++ b/blessed.cpp
@@ -0,0 +1,92 @@
1#include <yaml-cpp/yaml.h>
2#include <iostream>
3#include <cstdlib>
4#include <ctime>
5#include <sstream>
6#include <twitcurl.h>
7#include <verbly.h>
8
9int main(int argc, char** argv)
10{
11 srand(time(NULL));
12
13 YAML::Node config = YAML::LoadFile("config.yml");
14
15 twitCurl twitter;
16 twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>());
17 twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>());
18 twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>());
19 twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>());
20
21 verbly::data database {"data.sqlite3"};
22
23 std::vector<std::string> emojis;
24 std::ifstream emojifile("emojis.txt");
25 if (!emojifile.is_open())
26 {
27 std::cout << "Could not find emoji." << std::endl;
28 return -1;
29 }
30
31 for (;;)
32 {
33 std::string line;
34 if (!getline(emojifile, line))
35 {
36 break;
37 }
38
39 if (line.back() == '\r')
40 {
41 line.pop_back();
42 }
43
44 emojis.push_back(line);
45 }
46
47 for (;;)
48 {
49 std::cout << "Generating tweet" << std::endl;
50
51 std::string exclamation;
52 for (;;)
53 {
54 verbly::verb v = database.verbs().random(true).limit(1).has_pronunciation(true).run().front();
55 auto rhyms = database.nouns().rhymes_with(v).random(true).limit(1).not_derived_from(v).is_not_proper(true).run();
56 if (!rhyms.empty())
57 {
58 auto n = rhyms.front();
59 if (n.base_form() != v.base_form())
60 {
61 exclamation = "god " + v.base_form() + " this " + n.base_form();
62 break;
63 }
64 }
65 }
66
67 std::string emojibef;
68 std::string emojiaft;
69 do
70 {
71 std::string em = emojis[rand() % emojis.size()];
72 emojibef += em;
73 emojiaft = em + emojiaft;
74 } while (rand() % 4 < 3);
75
76 std::string result = emojibef + " " + exclamation + " " + emojiaft;
77 result.resize(140);
78
79 std::string replyMsg;
80 if (twitter.statusUpdate(result))
81 {
82 twitter.getLastWebResponse(replyMsg);
83 std::cout << "Twitter message: " << replyMsg << std::endl;
84 } else {
85 twitter.getLastCurlError(replyMsg);
86 std::cout << "Curl error: " << replyMsg << std::endl;
87 }
88
89 std::cout << "Waiting" << std::endl;
90 sleep(60 * 60);
91 }
92}