blob: 6b5921331cbb658daa4bdc703147d2339118bdd2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <yaml-cpp/yaml.h>
#include <twitter.h>
#include <fstream>
#include <iostream>
#include <thread>
#include <chrono>
int main(int argc, char** argv)
{
YAML::Node config = YAML::LoadFile("config.yml");
twitter::auth auth;
auth.setConsumerKey(config["consumer_key"].as<std::string>());
auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
auth.setAccessKey(config["access_key"].as<std::string>());
auth.setAccessSecret(config["access_secret"].as<std::string>());
twitter::client client(auth);
long loc = 0;
if (config["current_location"])
{
loc = config["current_location"].as<long>();
}
std::list<std::string> tweets;
{
std::ifstream corpus(config["corpus"].as<std::string>());
corpus.ignore(loc);
char buffer[140];
while (corpus)
{
corpus.read(buffer, 140);
tweets.push_back(std::string(buffer, 140));
}
}
while (!tweets.empty())
{
try
{
std::string nextTweet = tweets.front();
client.updateStatus(nextTweet);
std::cout << "Tweeted!" << std::endl;
loc += 140;
{
std::ofstream fout("config.yml");
config["current_location"] = loc;
fout << config;
}
tweets.pop_front();
} catch (const twitter::twitter_error& e)
{
std::cout << "Twitter error: " << e.what() << std::endl;
}
std::cout << "Waiting..." << std::endl;
std::this_thread::sleep_for(std::chrono::hours(6));
}
}
|