about summary refs log tree commit diff stats
path: root/cadence.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-03-26 15:33:06 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-03-26 15:33:06 -0400
commit0e6355329f241a3e3c8b38cb4146fda4470e6ed0 (patch)
treedf5853ba6df148e8eeb0082d090dfbcd9f94f651 /cadence.cpp
parent09acb46a9c32257b0003eb152d32c15b43b95dfe (diff)
downloadcadence-0e6355329f241a3e3c8b38cb4146fda4470e6ed0.tar.gz
cadence-0e6355329f241a3e3c8b38cb4146fda4470e6ed0.tar.bz2
cadence-0e6355329f241a3e3c8b38cb4146fda4470e6ed0.zip
Whitespace changes
Diffstat (limited to 'cadence.cpp')
-rw-r--r--cadence.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/cadence.cpp b/cadence.cpp index c91ca4a..80e4a05 100644 --- a/cadence.cpp +++ b/cadence.cpp
@@ -24,16 +24,16 @@ int main(int argc, char** argv)
24 24
25 std::string configfile(argv[1]); 25 std::string configfile(argv[1]);
26 YAML::Node config = YAML::LoadFile(configfile); 26 YAML::Node config = YAML::LoadFile(configfile);
27 27
28 // Set up the Twitter client. 28 // Set up the Twitter client.
29 twitter::auth auth; 29 twitter::auth auth;
30 auth.setConsumerKey(config["consumer_key"].as<std::string>()); 30 auth.setConsumerKey(config["consumer_key"].as<std::string>());
31 auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); 31 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
32 auth.setAccessKey(config["access_key"].as<std::string>()); 32 auth.setAccessKey(config["access_key"].as<std::string>());
33 auth.setAccessSecret(config["access_secret"].as<std::string>()); 33 auth.setAccessSecret(config["access_secret"].as<std::string>());
34 34
35 twitter::client client(auth); 35 twitter::client client(auth);
36 36
37 // Read in the forms file. 37 // Read in the forms file.
38 std::map<std::string, std::vector<std::string>> groups; 38 std::map<std::string, std::vector<std::string>> groups;
39 std::ifstream datafile(config["forms"].as<std::string>()); 39 std::ifstream datafile(config["forms"].as<std::string>());
@@ -42,7 +42,7 @@ int main(int argc, char** argv)
42 std::cout << "Could not find forms file." << std::endl; 42 std::cout << "Could not find forms file." << std::endl;
43 return 1; 43 return 1;
44 } 44 }
45 45
46 bool newgroup = true; 46 bool newgroup = true;
47 std::string line; 47 std::string line;
48 std::string curgroup; 48 std::string curgroup;
@@ -52,7 +52,7 @@ int main(int argc, char** argv)
52 { 52 {
53 line.pop_back(); 53 line.pop_back();
54 } 54 }
55 55
56 if (newgroup) 56 if (newgroup)
57 { 57 {
58 curgroup = line; 58 curgroup = line;
@@ -70,10 +70,10 @@ int main(int argc, char** argv)
70 // Initialize the random number generator. 70 // Initialize the random number generator.
71 std::random_device random_device; 71 std::random_device random_device;
72 std::mt19937 random_engine{random_device()}; 72 std::mt19937 random_engine{random_device()};
73 73
74 // Connect to the AcousticBrainz data file. 74 // Connect to the AcousticBrainz data file.
75 sqlite3* ppdb = nullptr; 75 sqlite3* ppdb = nullptr;
76 76
77 if (sqlite3_open_v2(config["acoustic_datafile"].as<std::string>().c_str(), &ppdb, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) 77 if (sqlite3_open_v2(config["acoustic_datafile"].as<std::string>().c_str(), &ppdb, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK)
78 { 78 {
79 // We still have to free the resources allocated. In the event that 79 // We still have to free the resources allocated. In the event that
@@ -82,19 +82,19 @@ int main(int argc, char** argv)
82 sqlite3_close_v2(ppdb); 82 sqlite3_close_v2(ppdb);
83 83
84 std::cout << "Could not open acoustic datafile." << std::endl; 84 std::cout << "Could not open acoustic datafile." << std::endl;
85 85
86 return 1; 86 return 1;
87 } 87 }
88 88
89 for (;;) 89 for (;;)
90 { 90 {
91 std::cout << "Generating tweet..." << std::endl; 91 std::cout << "Generating tweet..." << std::endl;
92 92
93 std::string mood = moods[std::uniform_int_distribution<int>(0, moods.size()-1)(random_engine)]; 93 std::string mood = moods[std::uniform_int_distribution<int>(0, moods.size()-1)(random_engine)];
94 94
95 std::string songTitle; 95 std::string songTitle;
96 std::string songArtist; 96 std::string songArtist;
97 97
98 sqlite3_stmt* ppstmt; 98 sqlite3_stmt* ppstmt;
99 std::string query = "SELECT title, artist FROM songs WHERE category = ? ORDER BY RANDOM() LIMIT 1"; 99 std::string query = "SELECT title, artist FROM songs WHERE category = ? ORDER BY RANDOM() LIMIT 1";
100 100
@@ -102,12 +102,12 @@ int main(int argc, char** argv)
102 { 102 {
103 std::cout << "Error reading from acoustic datafile:" << std::endl; 103 std::cout << "Error reading from acoustic datafile:" << std::endl;
104 std::cout << sqlite3_errmsg(ppdb) << std::endl; 104 std::cout << sqlite3_errmsg(ppdb) << std::endl;
105 105
106 return 1; 106 return 1;
107 } 107 }
108 108
109 sqlite3_bind_text(ppstmt, 1, mood.c_str(), mood.length(), SQLITE_TRANSIENT); 109 sqlite3_bind_text(ppstmt, 1, mood.c_str(), mood.length(), SQLITE_TRANSIENT);
110 110
111 if (sqlite3_step(ppstmt) == SQLITE_ROW) 111 if (sqlite3_step(ppstmt) == SQLITE_ROW)
112 { 112 {
113 songTitle = reinterpret_cast<const char*>(sqlite3_column_blob(ppstmt, 0)); 113 songTitle = reinterpret_cast<const char*>(sqlite3_column_blob(ppstmt, 0));
@@ -115,10 +115,10 @@ int main(int argc, char** argv)
115 } else { 115 } else {
116 std::cout << "Error reading from acoustic datafile:" << std::endl; 116 std::cout << "Error reading from acoustic datafile:" << std::endl;
117 std::cout << sqlite3_errmsg(ppdb) << std::endl; 117 std::cout << sqlite3_errmsg(ppdb) << std::endl;
118 118
119 return 1; 119 return 1;
120 } 120 }
121 121
122 sqlite3_finalize(ppstmt); 122 sqlite3_finalize(ppstmt);
123 123
124 std::string action = "{" + cadence::uppercase(mood) + "}"; 124 std::string action = "{" + cadence::uppercase(mood) + "}";
@@ -133,12 +133,12 @@ int main(int argc, char** argv)
133 modifier = token.substr(modloc+1); 133 modifier = token.substr(modloc+1);
134 token = token.substr(0, modloc); 134 token = token.substr(0, modloc);
135 } 135 }
136 136
137 std::string canontkn; 137 std::string canontkn;
138 std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) { 138 std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) {
139 return std::toupper(ch); 139 return std::toupper(ch);
140 }); 140 });
141 141
142 std::string result; 142 std::string result;
143 if (canontkn == "\\N") 143 if (canontkn == "\\N")
144 { 144 {
@@ -157,10 +157,10 @@ int main(int argc, char** argv)
157 } else { 157 } else {
158 std::cout << "Badly formatted forms file:" << std::endl; 158 std::cout << "Badly formatted forms file:" << std::endl;
159 std::cout << "No such form as " + canontkn << std::endl; 159 std::cout << "No such form as " + canontkn << std::endl;
160 160
161 return 1; 161 return 1;
162 } 162 }
163 163
164 if (modifier == "indefinite") 164 if (modifier == "indefinite")
165 { 165 {
166 if ((result.length() > 1) && (isupper(result[0])) && (isupper(result[1]))) 166 if ((result.length() > 1) && (isupper(result[0])) && (isupper(result[1])))
@@ -173,7 +173,7 @@ int main(int argc, char** argv)
173 result = "a " + result; 173 result = "a " + result;
174 } 174 }
175 } 175 }
176 176
177 std::string finalresult; 177 std::string finalresult;
178 if (islower(token[0])) 178 if (islower(token[0]))
179 { 179 {
@@ -187,21 +187,21 @@ int main(int argc, char** argv)
187 { 187 {
188 word[0] = std::toupper(word[0]); 188 word[0] = std::toupper(word[0]);
189 } 189 }
190 190
191 finalresult = cadence::implode(std::begin(words), std::end(words), " "); 191 finalresult = cadence::implode(std::begin(words), std::end(words), " ");
192 } else { 192 } else {
193 finalresult = result; 193 finalresult = result;
194 } 194 }
195 195
196 action.replace(tknloc, action.find("}")-tknloc+1, finalresult); 196 action.replace(tknloc, action.find("}")-tknloc+1, finalresult);
197 } 197 }
198 198
199 if (action.size() <= 140) 199 if (action.size() <= 140)
200 { 200 {
201 try 201 try
202 { 202 {
203 client.updateStatus(action); 203 client.updateStatus(action);
204 204
205 std::cout << action << std::endl; 205 std::cout << action << std::endl;
206 } catch (const twitter::twitter_error& e) 206 } catch (const twitter::twitter_error& e)
207 { 207 {
@@ -209,9 +209,9 @@ int main(int argc, char** argv)
209 } 209 }
210 210
211 std::cout << "Waiting..." << std::endl; 211 std::cout << "Waiting..." << std::endl;
212 212
213 std::this_thread::sleep_for(std::chrono::hours(1)); 213 std::this_thread::sleep_for(std::chrono::hours(1));
214 214
215 std::cout << std::endl; 215 std::cout << std::endl;
216 } else { 216 } else {
217 std::cout << "Tweet was too long, regenerating." << std::endl; 217 std::cout << "Tweet was too long, regenerating." << std::endl;