ctucx.git: ctucxbot

[nimlang] A telegram bot

commit 8a24e7921c45ef018745edce7e4768dd3114ddf6
parent d71683ed720e254b4fb4102e37c1bd1b9a237611
Author: ctucx <c@ctu.cx>
Date: Fri, 14 Aug 2020 14:17:53 +0200

add scripts to reformat DS100-datasets
4 files changed, 200 insertions(+), 0 deletions(-)
A
ds100.js
|
63
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A
package.json
|
5
+++++
A
test.nim
|
19
+++++++++++++++++++
A
yarn.lock
|
113
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/ds100.js b/ds100.js
@@ -0,0 +1,63 @@
+const stations  = require('db-stations')
+const fs = require('fs');
+const https = require('https');
+
+
+var ds100list        = {};
+var ds100reverseList = {};
+
+stations.full()
+.on('data',function(station){
+    var stuff = [];
+
+    station.ril100Identifiers.forEach(element => {
+        stuff.push(element.rilIdentifier)
+        ds100list[element.rilIdentifier] = {
+          'ibnr': station.id
+        };
+    })
+
+    ds100reverseList[station.id] = stuff.join(', ');
+
+	fs.writeFile("data/db/stations/"+station.id+".json", JSON.stringify({
+			'id':                  station.id,
+			'name':                station.name,
+			'latitude':            station.location.latitude,
+			'longitude':           station.location.longitude,
+			'category':            station.category,
+			'hasDBLounge':         station.hasDBLounge,
+			'hasSteplessAccess':   station.hasSteplessAccess,
+			'hasPublicFacilities': station.hasPublicFacilities
+    }), () => {});
+})
+.on('end',function(){
+
	https.get("https://api.railway-stations.org/de/stations", (res) => {
+   		let body = "";
+
+    	res.on("data", (chunk) => {
+        	body += chunk;
+    	});
+
+    	res.on("end", () => {
+        	try {
+            	let json = JSON.parse(body);
+
+                json.forEach(element => { 
+                  if(ds100list[element["DS100"]]){
+                  	ds100list[element["DS100"]]["RailwayMapId"] = element["id"]
+                  }
+                });
+                
+
+                fs.writeFile("data/db/ds100.json", JSON.stringify(ds100list), () => {});
+ 				fs.writeFile("data/db/ds100reverse.json", JSON.stringify(ds100reverseList), () => {});
+
+        	} catch (error) {
+            	console.error(error.message);
+        	};
+    	});
+
+	}).on("error", (error) => {
+    	console.error(error.message);
+	});
+});
diff --git a/package.json b/package.json
@@ -0,0 +1,5 @@
+{
+  "dependencies": {
+    "db-stations": "^4.0.0"
+  }
+}
diff --git a/test.nim b/test.nim
@@ -0,0 +1,19 @@
+import os, json
+
+proc tuwas() =
+  let daten = parseJson(readFile("./data/db/ds100.json"))
+
+  if daten.hasKey(paramStr(1)):
+    let id = daten[paramStr(1)].getStr
+    let stationsDaten = parseJson(readFile("./data/db/stations/" & id & ".json"))
+
+    echo stationsDaten["name"]
+    
+  else:
+    echo "hab ich nicht"
+
+  
+
+
+
+tuwas()
diff --git a/yarn.lock b/yarn.lock
@@ -0,0 +1,113 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+core-util-is@~1.0.0:
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
+  integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
+
+db-stations@^4.0.0:
+  version "4.0.0"
+  resolved "https://registry.yarnpkg.com/db-stations/-/db-stations-4.0.0.tgz#e5052fb7aaaa12a4b9aaed915e42987127c09b7d"
+  integrity sha512-5PV8PUfuPYLlB7qHD6E6PAIRtLZtH5eLtTkdviqGP4qor19TOYOeGSBN9w6X9X14+n7mSGyfRfpg/2g2pR3lxw==
+  dependencies:
+    ndjson "^1.5.0"
+    tokenize-db-station-name "^2.2.1"
+
+inherits@~2.0.3:
+  version "2.0.4"
+  resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
+  integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
+
+isarray@~1.0.0:
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
+  integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
+
+json-stringify-safe@^5.0.1:
+  version "5.0.1"
+  resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
+  integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=
+
+minimist@^1.2.0:
+  version "1.2.5"
+  resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
+  integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
+
+ndjson@^1.5.0:
+  version "1.5.0"
+  resolved "https://registry.yarnpkg.com/ndjson/-/ndjson-1.5.0.tgz#ae603b36b134bcec347b452422b0bf98d5832ec8"
+  integrity sha1-rmA7NrE0vOw0e0UkIrC/mNWDLsg=
+  dependencies:
+    json-stringify-safe "^5.0.1"
+    minimist "^1.2.0"
+    split2 "^2.1.0"
+    through2 "^2.0.3"
+
+normalize-for-search@^2.0.1:
+  version "2.1.0"
+  resolved "https://registry.yarnpkg.com/normalize-for-search/-/normalize-for-search-2.1.0.tgz#054ee765de1e36613b7f3dd4aa4cf6f9c32330fe"
+  integrity sha512-SL9xv8eEXXQfj7wo4aq/QjgCLzcKSLYAoVcRyaxJPZJkiIlGX579TiuoLWrFSkG6MZfesJ9fRpYcdpYKwckZUw==
+
+process-nextick-args@~2.0.0:
+  version "2.0.1"
+  resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
+  integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
+
+readable-stream@~2.3.6:
+  version "2.3.7"
+  resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
+  integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
+  dependencies:
+    core-util-is "~1.0.0"
+    inherits "~2.0.3"
+    isarray "~1.0.0"
+    process-nextick-args "~2.0.0"
+    safe-buffer "~5.1.1"
+    string_decoder "~1.1.1"
+    util-deprecate "~1.0.1"
+
+safe-buffer@~5.1.0, safe-buffer@~5.1.1:
+  version "5.1.2"
+  resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
+  integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
+
+split2@^2.1.0:
+  version "2.2.0"
+  resolved "https://registry.yarnpkg.com/split2/-/split2-2.2.0.tgz#186b2575bcf83e85b7d18465756238ee4ee42493"
+  integrity sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==
+  dependencies:
+    through2 "^2.0.2"
+
+string_decoder@~1.1.1:
+  version "1.1.1"
+  resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
+  integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
+  dependencies:
+    safe-buffer "~5.1.0"
+
+through2@^2.0.2, through2@^2.0.3:
+  version "2.0.5"
+  resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd"
+  integrity sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==
+  dependencies:
+    readable-stream "~2.3.6"
+    xtend "~4.0.1"
+
+tokenize-db-station-name@^2.2.1:
+  version "2.2.2"
+  resolved "https://registry.yarnpkg.com/tokenize-db-station-name/-/tokenize-db-station-name-2.2.2.tgz#3ebb79a317c1ca7ad55db96c54e2a4e9144590e7"
+  integrity sha512-Ns2FSWYAkakx7VSiZ3WB18obnj3t03mrcixfyTl8aZPxAANmB4+l1INHLF1Dd5ujufK2+izQZNLc4ooz2Kqppw==
+  dependencies:
+    normalize-for-search "^2.0.1"
+
+util-deprecate@~1.0.1:
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
+  integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
+
+xtend@~4.0.1:
+  version "4.0.2"
+  resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
+  integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==