More on retrieving and parsing dates.
This commit is contained in:
parent
10eff684df
commit
861f9af1f9
5 changed files with 127 additions and 9 deletions
|
@ -1,6 +1,85 @@
|
|||
#include "utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using std::istringstream;
|
||||
using std::string;
|
||||
using namespace std::chrono;
|
||||
|
||||
std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||
istringstream stream(csv);
|
||||
string line;
|
||||
std::vector<WasteDate> dates;
|
||||
|
||||
// Get rid of the first line
|
||||
std::getline(stream, line);
|
||||
|
||||
while (std::getline(stream, line)) {
|
||||
string delimiter = ";";
|
||||
size_t pos = 0;
|
||||
string token;
|
||||
uint tokenPos = 0;
|
||||
while ((pos = line.find(delimiter)) != std::string::npos) {
|
||||
token = line.substr(0, pos);
|
||||
// std::cout << token << std::endl;
|
||||
|
||||
if (token.length() > 0) {
|
||||
istringstream liness(token);
|
||||
string day_str, month_str, year_str;
|
||||
getline(liness, day_str, '.');
|
||||
getline(liness, month_str, '.');
|
||||
getline(liness, year_str, '.');
|
||||
int day = atoi(day_str.c_str());
|
||||
int month = atoi(month_str.c_str());
|
||||
int year = atoi(year_str.c_str());
|
||||
year_month_day date{std::chrono::year{year}, std::chrono::month{(uint)month},
|
||||
std::chrono::day{(uint)day}};
|
||||
|
||||
std::vector<WasteDate>::iterator it;
|
||||
WasteDate wd;
|
||||
it = std::find_if(dates.begin(), dates.end(),
|
||||
[&date](const WasteDate &x) { return date == x.date; });
|
||||
if (it == dates.end()) {
|
||||
wd.date = date;
|
||||
dates.push_back(wd);
|
||||
wd = dates.back();
|
||||
} else {
|
||||
wd = *it;
|
||||
}
|
||||
|
||||
switch (tokenPos) {
|
||||
case 0:
|
||||
printf("Gelber Sack: %s\n", token.c_str());
|
||||
wd.wasteTypes.push_back(Waste::GelberSack);
|
||||
break;
|
||||
case 1:
|
||||
printf("Papiertonne: %s\n", token.c_str());
|
||||
wd.wasteTypes.push_back(Waste::Papiertonne);
|
||||
break;
|
||||
case 2:
|
||||
printf("Biotonne: %s\n", token.c_str());
|
||||
wd.wasteTypes.push_back(Waste::Biotonne);
|
||||
break;
|
||||
case 3:
|
||||
printf("Restmüll: %s\n", token.c_str());
|
||||
wd.wasteTypes.push_back(Waste::Restmuell);
|
||||
break;
|
||||
case 4:
|
||||
printf("Problemstoffmobil: %s\n", token.c_str());
|
||||
wd.wasteTypes.push_back(Waste::Problemstoffmobil);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
line.erase(0, pos + delimiter.length());
|
||||
++tokenPos;
|
||||
}
|
||||
}
|
||||
|
||||
return dates;
|
||||
}
|
||||
|
||||
int wifi_setup_impl(uint32_t country, const string &ssid, const string &pw, bool firstTry) {
|
||||
if (firstTry) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue