Created
October 11, 2018 10:05
-
-
Save serayuzgur/5ecc33e595b52c5806e4d3f893b86b31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const csv = require("csvtojson/v2"); | |
var fs = require("fs"); | |
const ibMap = {}; | |
const structured = {}; | |
function append(item) { | |
let province = {}; | |
let district = {}; | |
let subd = {}; | |
let neig = {}; | |
try { | |
province = structured[item["il_kodu"] + ":" + item["il"]]; | |
if (!province) { | |
structured[item["il_kodu"] + ":" + item["il"]] = province = {}; | |
} | |
district = province[item["ilçe"]]; | |
if (!district) { | |
province[item["ilçe"]] = district = {}; | |
} | |
subd = district[item["semt_bucak_belde"]]; | |
if (!subd) { | |
district[item["semt_bucak_belde"]] = subd = {}; | |
} | |
subd[item["Mahalle"]] = item["PK"]; | |
} catch (e) { | |
console.error({ item, province, district, subd, neig, structured }); | |
throw e; | |
} | |
} | |
csv({ delimiter: ";" }) | |
.subscribe((item, index) => { | |
ibMap[item["İL ADI"].toLocaleUpperCase("tr-TR")] = item["İL KODU"]; | |
}) | |
.fromFile("/Users/serayuzgur/Desktop/ib.csv") | |
.then(ib => { | |
csv({ delimiter: ";" }) | |
.subscribe((item, index) => { | |
item["il_kodu"] = ibMap[item["il"]]; | |
append(item); | |
}) | |
.fromFile("/Users/serayuzgur/Desktop/ptt.csv") | |
.then(ptt => { | |
console.log("Writing to file"); | |
var json = JSON.stringify(structured); | |
fs.unlinkSync("/Users/serayuzgur/Desktop/addressMeta.json"); | |
fs.writeFile( | |
"/Users/serayuzgur/Desktop/addressMeta.json", | |
json, | |
"utf8", | |
() => { | |
console.info("Done"); | |
}, | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment