summary refs log tree commit diff stats
path: root/troublemaker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'troublemaker.cpp')
-rw-r--r--troublemaker.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/troublemaker.cpp b/troublemaker.cpp index 31381dc..d924894 100644 --- a/troublemaker.cpp +++ b/troublemaker.cpp
@@ -10,6 +10,7 @@
10#include <iostream> 10#include <iostream>
11#include <list> 11#include <list>
12#include <yaml-cpp/yaml.h> 12#include <yaml-cpp/yaml.h>
13#include <fstream>
13 14
14struct userstats { 15struct userstats {
15 int total = 0; 16 int total = 0;
@@ -42,6 +43,33 @@ int main(int argc, char** argv)
42 std::map<twitter::user_id, userstats> stats; 43 std::map<twitter::user_id, userstats> stats;
43 std::mutex stats_mutex; 44 std::mutex stats_mutex;
44 45
46 // Read in old data
47 {
48 std::ifstream datafile("data.txt");
49
50 if (datafile.is_open())
51 {
52 std::string line;
53 while (std::getline(datafile, line))
54 {
55 std::istringstream iss(line);
56
57 twitter::user_id uid;
58 iss >> uid;
59
60 userstats& s = stats[uid];
61 iss >> s.total;
62 iss >> s.days;
63 iss >> s.day2;
64 iss >> s.day3;
65 iss >> s.day4;
66 iss >> s.day5;
67 iss >> s.day6;
68 iss >> s.day7;
69 }
70 }
71 }
72
45 twitter::client client(auth); 73 twitter::client client(auth);
46 client.setUserStreamNotifyCallback([&] (twitter::notification n) { 74 client.setUserStreamNotifyCallback([&] (twitter::notification n) {
47 std::lock_guard<std::mutex> friend_guard(friends_mutex); 75 std::lock_guard<std::mutex> friend_guard(friends_mutex);
@@ -150,9 +178,12 @@ int main(int argc, char** argv)
150 std::cout << "Twitter error while getting friends: " << resp << std::endl; 178 std::cout << "Twitter error while getting friends: " << resp << std::endl;
151 } 179 }
152 180
181 std::cout << "stat rotation" << std::endl;
153 // This is all just for stats rotation 182 // This is all just for stats rotation
154 { 183 {
155 std::lock_guard<std::mutex> stats_guard(stats_mutex); 184 std::lock_guard<std::mutex> stats_guard(stats_mutex);
185 std::ofstream datafile("data.txt", std::ofstream::out | std::ofstream::trunc);
186
156 for (auto mapping : stats) 187 for (auto mapping : stats)
157 { 188 {
158 auto& s = mapping.second; 189 auto& s = mapping.second;
@@ -167,9 +198,18 @@ int main(int argc, char** argv)
167 s.day4 = s.day3; 198 s.day4 = s.day3;
168 s.day3 = s.day2; 199 s.day3 = s.day2;
169 s.day2 = s.day1; 200 s.day2 = s.day1;
170 s.day1 = 0;
171 201
172 s.total = s.day2 + s.day3 + s.day4 + s.day5 + s.day6 + s.day7; 202 s.total = s.day2 + s.day3 + s.day4 + s.day5 + s.day6 + s.day7;
203
204 datafile << mapping.first << " ";
205 datafile << s.total << " ";
206 datafile << s.days << " ";
207 datafile << s.day2 << " ";
208 datafile << s.day3 << " ";
209 datafile << s.day4 << " ";
210 datafile << s.day5 << " ";
211 datafile << s.day6 << " ";
212 datafile << s.day7 << std::endl;
173 } 213 }
174 } 214 }
175 } 215 }