Created
March 17, 2016 17:15
-
-
Save keewon/2232d53c74a2bd8acb27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "rapidjson/document.h" | |
#include "rapidjson/writer.h" | |
#include "rapidjson/stringbuffer.h" | |
#include <cstdio> | |
#include <string> | |
#include <iostream> | |
//#include <regex> | |
#include <boost/regex.hpp> | |
using namespace rapidjson; | |
int main() { | |
Document d; | |
StringBuffer buffer; | |
Writer<StringBuffer> writer(buffer); | |
boost::regex r1("\\{\\s*\"\\$oid\"\\s*:\\s*\"([a-f0-9]+)\"\\s*\\}"); | |
boost::regex r2("\\{\\s*\"\\$numberLong\"\\s*:\\s*\"([\\-0-9]+)\"\\s*\\}"); | |
boost::regex r3("\\{\\s*\"\\$date\"\\s*:\\s*\"([0-9\\-\\:T\\.Z\\+]+)\"\\s*\\}"); | |
boost::regex r4("NumberLong\\(([\\-0-9]+)\\)"); | |
boost::regex r5("(\"\\[object Object\\]\")"); | |
boost::regex r6("(\"_id\")"); | |
std::string date_limit("2015-04-01"); | |
std::string line; | |
while (std::cin.good()) { | |
std::getline(std::cin, line); | |
if (!std::cin.good()) | |
break; | |
if (line.size() == 0) | |
continue; | |
line = boost::regex_replace(line, r1, "\"$1\""); | |
line = boost::regex_replace(line, r2, "$1"); | |
line = boost::regex_replace(line, r3, "\"$1\""); | |
line = boost::regex_replace(line, r4, "$1"); | |
line = boost::regex_replace(line, r5, "null"); | |
line = boost::regex_replace(line, r6, "\"bson_id\""); | |
d.Parse(line.c_str()); | |
Value& vt = d["t"]; | |
std::string t = vt.GetString(); | |
std::string year = t.substr(0, 4); | |
if (t.compare(date_limit) > 0) | |
continue; | |
buffer.Clear(); | |
writer.Reset(buffer); | |
d.Accept(writer); | |
std::cout << year << "\t" << buffer.GetString() << std::endl; | |
} | |
return 0; | |
} | |
// vim: ts=8 sts=4 sw=4 expandtab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment