summary refs log tree commit diff stats
path: root/fefisms.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fefisms.cpp')
-rw-r--r--fefisms.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/fefisms.cpp b/fefisms.cpp new file mode 100644 index 0000000..44e69b4 --- /dev/null +++ b/fefisms.cpp
@@ -0,0 +1,103 @@
1#include <verbly.h>
2#include <twitter.h>
3#include <yaml-cpp/yaml.h>
4#include <iostream>
5#include <chrono>
6#include <random>
7#include <thread>
8
9int main(int argc, char** argv)
10{
11 std::random_device random_device;
12 std::mt19937 random_engine{random_device()};
13
14 if (argc != 2)
15 {
16 std::cout << "usage: fefisms [configfile]" << std::endl;
17 return -1;
18 }
19
20 std::string configfile(argv[1]);
21 YAML::Node config = YAML::LoadFile(configfile);
22
23 twitter::auth auth;
24 auth.setConsumerKey(config["consumer_key"].as<std::string>());
25 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
26 auth.setAccessKey(config["access_key"].as<std::string>());
27 auth.setAccessSecret(config["access_secret"].as<std::string>());
28
29 twitter::client client(auth);
30
31 verbly::database database(config["verbly_datafile"].as<std::string>());
32
33 verbly::filter formFilter =
34 (verbly::form::complexity == 1)
35 && (verbly::form::proper == false);
36
37 verbly::filter cleanFilter =
38 !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862)); // Blacklist ethnic slurs
39
40 for (;;)
41 {
42 std::cout << "Generating tweet..." << std::endl;
43
44 verbly::token utterance;
45
46 verbly::inflection nounInfl = verbly::inflection::base;
47 verbly::inflection hypoInfl = verbly::inflection::base;
48
49 if (std::bernoulli_distribution(1.0/2.0)(random_engine))
50 {
51 hypoInfl = verbly::inflection::plural;
52 }
53
54 if (std::bernoulli_distribution(1.0/2.0)(random_engine))
55 {
56 nounInfl = verbly::inflection::plural;
57 }
58
59 verbly::word noun = database.words(
60 (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
61 && (verbly::word::forms(nounInfl) %= formFilter)
62 && cleanFilter
63 && (verbly::notion::hyponyms %=
64 (verbly::word::forms(hypoInfl) %= formFilter)
65 && cleanFilter)).first();
66
67 verbly::word hyponym = database.words(
68 (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
69 && (verbly::notion::hypernyms %= noun)
70 && cleanFilter
71 && (verbly::word::forms(hypoInfl) %= formFilter)).first();
72
73 if (std::bernoulli_distribution(1.0/2.0)(random_engine))
74 {
75 utterance << verbly::token(noun, nounInfl);
76 utterance << verbly::token(hyponym, hypoInfl);
77 } else {
78 utterance << verbly::token(hyponym, hypoInfl);
79 utterance << verbly::token(noun, nounInfl);
80 }
81
82 std::string action = utterance.compile();
83 std::cout << action << std::endl;
84
85 try
86 {
87 std::cout << "Tweeting..." << std::endl;
88
89 client.updateStatus(action);
90
91 std::cout << "Success!" << std::endl;
92 std::cout << "Waiting..." << std::endl;
93 } catch (const twitter::twitter_error& e)
94 {
95 std::cout << "Error while tweeting: " << e.what() << std::endl;
96 }
97
98 std::this_thread::sleep_for(std::chrono::hours(1));
99
100 std::cout << std::endl;
101 }
102}
103