diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-10-02 15:36:33 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-10-02 15:36:33 -0400 |
commit | 93f1f3ad274de032e1b023eb1262cee1c61181ae (patch) | |
tree | 340eb7e2564df9cb08e699ac082d3938805a318e /manifesto.cpp | |
download | manifesto-93f1f3ad274de032e1b023eb1262cee1c61181ae.tar.gz manifesto-93f1f3ad274de032e1b023eb1262cee1c61181ae.tar.bz2 manifesto-93f1f3ad274de032e1b023eb1262cee1c61181ae.zip |
Initial commit
Diffstat (limited to 'manifesto.cpp')
-rw-r--r-- | manifesto.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/manifesto.cpp b/manifesto.cpp new file mode 100644 index 0000000..6b59213 --- /dev/null +++ b/manifesto.cpp | |||
@@ -0,0 +1,65 @@ | |||
1 | #include <yaml-cpp/yaml.h> | ||
2 | #include <twitter.h> | ||
3 | #include <fstream> | ||
4 | #include <iostream> | ||
5 | #include <thread> | ||
6 | #include <chrono> | ||
7 | |||
8 | int main(int argc, char** argv) | ||
9 | { | ||
10 | YAML::Node config = YAML::LoadFile("config.yml"); | ||
11 | |||
12 | twitter::auth auth; | ||
13 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | ||
14 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | ||
15 | auth.setAccessKey(config["access_key"].as<std::string>()); | ||
16 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | ||
17 | |||
18 | twitter::client client(auth); | ||
19 | |||
20 | long loc = 0; | ||
21 | if (config["current_location"]) | ||
22 | { | ||
23 | loc = config["current_location"].as<long>(); | ||
24 | } | ||
25 | |||
26 | std::list<std::string> tweets; | ||
27 | { | ||
28 | std::ifstream corpus(config["corpus"].as<std::string>()); | ||
29 | corpus.ignore(loc); | ||
30 | |||
31 | char buffer[140]; | ||
32 | while (corpus) | ||
33 | { | ||
34 | corpus.read(buffer, 140); | ||
35 | tweets.push_back(std::string(buffer, 140)); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | while (!tweets.empty()) | ||
40 | { | ||
41 | try | ||
42 | { | ||
43 | std::string nextTweet = tweets.front(); | ||
44 | client.updateStatus(nextTweet); | ||
45 | |||
46 | std::cout << "Tweeted!" << std::endl; | ||
47 | |||
48 | loc += 140; | ||
49 | { | ||
50 | std::ofstream fout("config.yml"); | ||
51 | config["current_location"] = loc; | ||
52 | fout << config; | ||
53 | } | ||
54 | |||
55 | tweets.pop_front(); | ||
56 | } catch (const twitter::twitter_error& e) | ||
57 | { | ||
58 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
59 | } | ||
60 | |||
61 | std::cout << "Waiting..." << std::endl; | ||
62 | |||
63 | std::this_thread::sleep_for(std::chrono::hours(6)); | ||
64 | } | ||
65 | } | ||