From 9ab9e5fcbc1534111d74c688bf7ad6d6ad46ff2b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 20 Oct 2016 08:58:20 -0400 Subject: Switched from twitcurl to libtwitter++ Also updated verbly, switched from C random interface to C++ random interface, and reworked the datafile to give the generated tweets a different feel. --- .gitmodules | 3 +++ CMakeLists.txt | 9 +++----- chemist.cpp | 63 ++++++++++++++++++++++++++++++++-------------------- data.txt | 59 +++++++++++++++++++++++++++++++----------------- vendor/libtwittercpp | 1 + vendor/twitcurl | 1 - vendor/verbly | 2 +- 7 files changed, 86 insertions(+), 52 deletions(-) create mode 160000 vendor/libtwittercpp delete mode 160000 vendor/twitcurl diff --git a/.gitmodules b/.gitmodules index 08a42de..2d58700 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/yaml-cpp"] path = vendor/yaml-cpp url = https://github.com/jbeder/yaml-cpp +[submodule "vendor/libtwittercpp"] + path = vendor/libtwittercpp + url = https://github.com/hatkirby/libtwittercpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d19b9..49b0d2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,15 +3,12 @@ project (chemist) set(CMAKE_BUILD_TYPE Debug) -find_package(PkgConfig) -pkg_check_modules(sqlite3 sqlite3 REQUIRED) - -add_subdirectory(vendor/twitcurl/libtwitcurl) add_subdirectory(vendor/verbly) add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) +add_subdirectory(vendor/libtwittercpp) -include_directories(vendor/twitcurl/libtwitcurl ${sqlite3_INCLUDE_DIR} vendor/verbly/lib vendor/yaml-cpp/include) +include_directories(vendor/verbly/lib vendor/yaml-cpp/include vendor/libtwittercpp/src) add_executable(chemist chemist.cpp) set_property(TARGET chemist PROPERTY CXX_STANDARD 11) set_property(TARGET chemist PROPERTY CXX_STANDARD_REQUIRED ON) -target_link_libraries(chemist verbly ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl) +target_link_libraries(chemist verbly twitter++ yaml-cpp) diff --git a/chemist.cpp b/chemist.cpp index fbf83a8..8b00d12 100644 --- a/chemist.cpp +++ b/chemist.cpp @@ -1,23 +1,24 @@ #include #include -#include -#include #include -#include #include -#include +#include +#include +#include +#include +#include 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()); - twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as()); - twitter.getOAuth().setOAuthTokenKey(config["access_key"].as()); - twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as()); + + twitter::auth auth; + auth.setConsumerKey(config["consumer_key"].as()); + auth.setConsumerSecret(config["consumer_secret"].as()); + auth.setAccessKey(config["access_key"].as()); + auth.setAccessSecret(config["access_secret"].as()); + + twitter::client client(auth); std::map> groups; std::ifstream datafile("data.txt"); @@ -51,6 +52,9 @@ int main(int argc, char** argv) } } + std::random_device random_device; + std::mt19937 random_engine{random_device()}; + verbly::data database {"data.sqlite3"}; for (;;) { @@ -77,6 +81,9 @@ int main(int argc, char** argv) if (canontkn == "NOUN") { result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form(); + } else if (canontkn == "ATTRIBUTE") + { + result = database.nouns().random().limit(1).full_hyponym_of(database.nouns().with_wnid(100024264).limit(1).run().front()).run().front().singular_form(); } else if (canontkn == "ADJECTIVE") { result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form(); @@ -85,7 +92,9 @@ int main(int argc, char** argv) result = database.verbs().random().limit(1).run().front().ing_form(); } else if (canontkn == "YEAR") { - result = std::to_string(rand() % 100 + 1916); + std::uniform_int_distribution yeardist(1916,2015); + int year = yeardist(random_engine); + result = std::to_string(year); } else if (canontkn == "REGION") { auto hem1 = database.nouns().with_singular_form("eastern hemisphere").limit(1).run().front(); @@ -103,9 +112,14 @@ int main(int argc, char** argv) { auto bp = database.nouns().with_singular_form("body part").limit(1).run().front(); result = database.nouns().full_hyponym_of({bp}).with_complexity(1).random().limit(1).run().front().singular_form(); + } else if (canontkn == "\\N") + { + result = "\n"; } else { auto group = groups[canontkn]; - result = group[rand() % group.size()]; + std::uniform_int_distribution groupdist(0, group.size()-1); + int groupind = groupdist(random_engine); + result = group[groupind]; } if (modifier == "indefinite") @@ -144,18 +158,19 @@ int main(int argc, char** argv) } action.resize(140); - - std::string replyMsg; - if (twitter.statusUpdate(action)) + + try { - twitter.getLastWebResponse(replyMsg); - std::cout << "Twitter message: " << replyMsg << std::endl; - } else { - twitter.getLastCurlError(replyMsg); - std::cout << "Curl error: " << replyMsg << std::endl; + client.updateStatus(action); + + std::cout << "Tweeted!" << std::endl; + } catch (const twitter::twitter_error& e) + { + std::cout << "Twitter error: " << e.what() << std::endl; } - std::cout << "Waiting" << std::endl; - sleep(60 * 60); + std::cout << "Waiting..." << std::endl; + + std::this_thread::sleep_for(std::chrono::hours(1)); } } diff --git a/data.txt b/data.txt index 8535d4e..77179de 100644 --- a/data.txt +++ b/data.txt @@ -1,27 +1,27 @@ MAIN -{PRIMARY} {SECONDARY} +{NAME} ({CLASS}){\n}{PRIMARY}{\n}{SECONDARY} PRIMARY -{NAME} is {CLASS:indefinite} commonly used to treat {SYNDROME}. -{NAME} is {CLASS:indefinite} primarily used for {SYNDROME}. -{NAME} is {CLASS:indefinite} prescribed for {SYNDROME}. -{NAME} is {CLASS:indefinite} approved for treatment of {SYNDROME}, and {SYNDROME}. -{NAME} is {CLASS:indefinite} used for {SYNDROME} and {SYNDROME}. -{NAME} is {CLASS:indefinite} used with {EXISTENT} to treat {syndrome}. -{NAME} is {CLASS:indefinite} used in cases of {EXISTENT} overdose. -{NAME} is {CLASS:indefinite} used recreationally as {CLASS:indefinite}. -{NAME} is {CLASS:indefinite} used recreationally for {verbing}. +Used to treat {SYNDROME} +Treats the {adjective} symptoms of {SYNDROME} +Cures {SYNDROME} +Approved to treat {SYNDROME} and {SYNDROME} +Prescribed for {SYNDROME} +Used with {EXISTENT} to treat {SYNDROME} +Used recreationally as {CLASS:indefinite} +Used recreationally for {verbing} SECONDARY -Developed due to the Great {Noun} Epidemic of {year} in {Region}. -Frequently prescribed off-label for {SYNDROME}. -Sometimes used for {SYNDROME} because of its {verbing} effect. -Illegal to own in the US because of its {verbing} effect. -Developed in {year} to replace {EXISTENT}. -Overtook {EXISTENT} due to its {adjective} effect. -Synthesized by {FamousName} in {year} in a {verbing} accident. -Used mainly in {year}, before {EXISTENT} became popular. -Only legal in {Region} because of its {verbing} effect. +Developed after {year} {Noun} Pandemic +Often used off-label for {SYNDROME} +Notable for its {adjective} effect +Controlled in the US due to its {adjective} effect +Developed in {year} to replace {EXISTENT} +May cause {ADJECTIVE} feelings +Obsoleted by {EXISTENT} +Contraindicated by {SYNDROME} +Contraindicated by {EXISTENT} +Decreases the {adjective} effects of {EXISTENT} SYNDROME irritable {noun} syndrome @@ -40,6 +40,16 @@ congenital {noun} disease {FamousName}'s disease {adjective} fever hypo{noun}ism +{EXISTENT} overdose +{CLASS} overdose +{CLASS} discontinuation syndrome +{noun} syndrome +low {ATTRIBUTE} + +CLASSIFIER +{CLASS:indefinite} +{NAME} +{EXISTENT} CLASS analgesic @@ -84,6 +94,7 @@ SSRI anxiolytic antipanic agent tricyclic +tetracyclic MAOI SNRI antiandrogen @@ -95,6 +106,7 @@ antiviral drug stimulant depressant aphrodisiac +{EXISTENT} prodrug EXISTENT fluoxetine @@ -153,6 +165,10 @@ Viagra heroin morphine crystal meth +mirtazapine +Remeron +Luvox +fluvoxamine NAME {PRENAME}{NAMEMID}{NAMEIFX} @@ -196,6 +212,7 @@ Me Dibu Des Ha +Mir NAMEMID pipra @@ -228,6 +245,7 @@ va piva flu oxy +taz {NAMEMID}{NAMEMID} {NAMEMID}{NAMEMID} @@ -257,4 +275,5 @@ rone ine caine rane -ide \ No newline at end of file +ide +epine \ No newline at end of file diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 index 0000000..febadca --- /dev/null +++ b/vendor/libtwittercpp @@ -0,0 +1 @@ +Subproject commit febadca7d4e0460aa78f95b53b5e36e51fd2f97d diff --git a/vendor/twitcurl b/vendor/twitcurl deleted file mode 160000 index 6659e86..0000000 --- a/vendor/twitcurl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6659e86de7481e50977b7569c75138f7f69ad3c7 diff --git a/vendor/verbly b/vendor/verbly index 965a320..6c2aca0 160000 --- a/vendor/verbly +++ b/vendor/verbly @@ -1 +1 @@ -Subproject commit 965a3206df834f846f2c560438c80a707dcee4cb +Subproject commit 6c2aca03c89b37e136ab4c7ea58b485dadc85bcd -- cgit 1.4.1