Save region, clear edition before saving.
This commit is contained in:
parent
7ba637b6a4
commit
5eac3f26dc
1 changed files with 37 additions and 8 deletions
|
@ -3,9 +3,10 @@ import std.csv;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.typecons;
|
import std.typecons;
|
||||||
import etc.c.sqlite3;
|
import etc.c.sqlite3;
|
||||||
import std.string : toStringz, fromStringz, empty, strip, split;
|
import std.string;
|
||||||
import std.exception;
|
import std.exception;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
|
import std.path : baseName;
|
||||||
|
|
||||||
private class SQLiteException : Exception {
|
private class SQLiteException : Exception {
|
||||||
this(int code, string msg1, string msg2, string file = __FILE__, size_t line = __LINE__) {
|
this(int code, string msg1, string msg2, string file = __FILE__, size_t line = __LINE__) {
|
||||||
|
@ -17,6 +18,36 @@ extern(C) private int callback(void */*NotUsed*/, int /*argc*/, char **/*argv*/,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Regions : int {
|
||||||
|
Unknown, Europe, Japan, USA, Asia, Germany, Spain, Korea, All, Italy,
|
||||||
|
France, Russia, Poland, Netherlands, Portugal, India, Belgium,
|
||||||
|
UnitedKingdom, Australia
|
||||||
|
};
|
||||||
|
|
||||||
|
private int region_id(string path) pure {
|
||||||
|
switch (baseName(path, ".png")) {
|
||||||
|
case "E": return Regions.Europe;
|
||||||
|
case "J": return Regions.Japan;
|
||||||
|
case "U": return Regions.USA;
|
||||||
|
case "A": return Regions.Asia;
|
||||||
|
case "G": return Regions.Germany;
|
||||||
|
case "S": return Regions.Spain;
|
||||||
|
case "K": return Regions.Korea;
|
||||||
|
case "W": return Regions.All;
|
||||||
|
case "I": return Regions.Italy;
|
||||||
|
case "F": return Regions.France;
|
||||||
|
case "R": return Regions.Russia;
|
||||||
|
case "P": return Regions.Poland;
|
||||||
|
case "N": return Regions.Netherlands;
|
||||||
|
case "Pt": return Regions.Portugal;
|
||||||
|
case "In": return Regions.India;
|
||||||
|
case "Be": return Regions.Belgium;
|
||||||
|
case "Uk": return Regions.UnitedKingdom;
|
||||||
|
case "Au": return Regions.Australia;
|
||||||
|
default: return Regions.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void insert_into_sqlite(sqlite3* db, string path) {
|
private void insert_into_sqlite(sqlite3* db, string path) {
|
||||||
auto file = File(path, "r");
|
auto file = File(path, "r");
|
||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
|
@ -33,15 +64,13 @@ private void insert_into_sqlite(sqlite3* db, string path) {
|
||||||
// Expected CSV format: title,edition,version,languages,serial,region
|
// Expected CSV format: title,edition,version,languages,serial,region
|
||||||
foreach (record; file.byLine.joiner("\n").csvReader!(Tuple!(string, string, string, string, string, string))) {
|
foreach (record; file.byLine.joiner("\n").csvReader!(Tuple!(string, string, string, string, string, string))) {
|
||||||
const int ver = cast(int)((record[2].empty ? 0.0 : to!double(record[2])) * 100.0);
|
const int ver = cast(int)((record[2].empty ? 0.0 : to!double(record[2])) * 100.0);
|
||||||
string[] serials = record[4].split(";");
|
string serials = record[4];
|
||||||
string languages = record[3];
|
string languages = record[3];
|
||||||
string edition = record[1];
|
string edition = record[1].splitter(";").map!strip.join(";");
|
||||||
string title = record[0];
|
string title = record[0];
|
||||||
string region = record[5];
|
string region = record[5];
|
||||||
const int region_id = 0;
|
|
||||||
|
|
||||||
foreach (serial; serials) {
|
foreach (serial; serials.splitter(";").map!strip) {
|
||||||
serial = serial.strip;
|
|
||||||
if (serial in serials_seen) {
|
if (serial in serials_seen) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -55,8 +84,8 @@ private void insert_into_sqlite(sqlite3* db, string path) {
|
||||||
else
|
else
|
||||||
sqlite3_bind_null(statement, 4);
|
sqlite3_bind_null(statement, 4);
|
||||||
sqlite3_bind_text(statement, 5, serial.ptr, cast(int)serial.length, SQLITE_STATIC); //serial
|
sqlite3_bind_text(statement, 5, serial.ptr, cast(int)serial.length, SQLITE_STATIC); //serial
|
||||||
sqlite3_bind_int(statement, 6, region_id); //region
|
sqlite3_bind_int(statement, 6, region_id(region)); //region
|
||||||
stderr.writefln("insert into: \"%s\", \"%s\", \"%d\", \"%s\", \"%s\", \"%d\"", record[0], record[1], ver, record[3], serial, region_id);
|
//stderr.writefln("insert into: \"%s\", \"%s\", \"%d\", \"%s\", \"%s\", \"%d\", \"%s\"", title, edition, ver, languages, serial, region_id(region), region);
|
||||||
|
|
||||||
const int step_ret = sqlite3_step(statement);
|
const int step_ret = sqlite3_step(statement);
|
||||||
if (step_ret && SQLITE_DONE != step_ret)
|
if (step_ret && SQLITE_DONE != step_ret)
|
||||||
|
|
Loading…
Reference in a new issue