diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-11 20:01:21 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-11 20:01:21 -0500 |
| commit | eb8c9f975f0105f7df40b45090f7b2c46f3ddcd3 (patch) | |
| tree | 2b58845920f456bb15cd6cbf4ed1b1378b077a12 | |
| download | fefisms-eb8c9f975f0105f7df40b45090f7b2c46f3ddcd3.tar.gz fefisms-eb8c9f975f0105f7df40b45090f7b2c46f3ddcd3.tar.bz2 fefisms-eb8c9f975f0105f7df40b45090f7b2c46f3ddcd3.zip | |
Created bot
| -rw-r--r-- | .gitmodules | 9 | ||||
| -rw-r--r-- | CMakeLists.txt | 12 | ||||
| -rw-r--r-- | fefisms.cpp | 103 | ||||
| m--------- | vendor/libtwittercpp | 0 | ||||
| m--------- | vendor/verbly | 0 | ||||
| m--------- | vendor/yaml-cpp | 0 |
6 files changed, 124 insertions, 0 deletions
| diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f4b3cdf --- /dev/null +++ b/.gitmodules | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | [submodule "vendor/verbly"] | ||
| 2 | path = vendor/verbly | ||
| 3 | url = git@github.com:hatkirby/verbly | ||
| 4 | [submodule "vendor/yaml-cpp"] | ||
| 5 | path = vendor/yaml-cpp | ||
| 6 | url = git@github.com:jbeder/yaml-cpp | ||
| 7 | [submodule "vendor/libtwittercpp"] | ||
| 8 | path = vendor/libtwittercpp | ||
| 9 | url = git@github.com:hatkirby/libtwittercpp | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a2a8f0f --- /dev/null +++ b/CMakeLists.txt | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | cmake_minimum_required (VERSION 3.1) | ||
| 2 | project (fefisms) | ||
| 3 | |||
| 4 | add_subdirectory(vendor/libtwittercpp) | ||
| 5 | add_subdirectory(vendor/verbly) | ||
| 6 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) | ||
| 7 | |||
| 8 | include_directories(vendor/libtwittercpp/src vendor/verbly/lib vendor/yaml-cpp/include) | ||
| 9 | add_executable(fefisms fefisms.cpp) | ||
| 10 | set_property(TARGET fefisms PROPERTY CXX_STANDARD 11) | ||
| 11 | set_property(TARGET fefisms PROPERTY CXX_STANDARD_REQUIRED ON) | ||
| 12 | target_link_libraries(fefisms verbly twitter++ yaml-cpp) | ||
| 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 | |||
| 9 | int 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 | |||
| diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 | |||
| Subproject df906121dd862c0f704e44f28ee079158c431c4 | |||
| diff --git a/vendor/verbly b/vendor/verbly new file mode 160000 | |||
| Subproject 88e931e8acbaf41b8d36e4ae00b06764793a144 | |||
| diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000 | |||
| Subproject bedb28fdb4fd52d97e02f6cb946cae631037089 | |||
