Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

query_stations.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. const createClient = require("hafas-client");
  3. const readline = require("readline");
  4. const arrayUnique = require("array-unique");
  5. let profileName = "";
  6. let profile = "";
  7. const productMap = {
  8. bus: "Bus",
  9. ferry: "Fähre",
  10. national: "Fernverkehr",
  11. nationalExpress: "Fernverkehr",
  12. regional: "Regionalverkehr",
  13. suburban: "S-Bahn",
  14. subway: "U-Bahn",
  15. taxi: "Taxi",
  16. tram: "Tram"
  17. };
  18. if (process.argv.length == 3) {
  19. profileName = process.argv[2];
  20. console.log("Using hafas-client profile: " + profileName);
  21. } else {
  22. console.log("Using default hafas-client profile: 'db'");
  23. profileName = "db";
  24. }
  25. try {
  26. profile = require("hafas-client/p/" + profileName);
  27. }
  28. catch(err) {
  29. console.error("\n" + err.message + "\n Did you choose the right profile name? \n");
  30. }
  31. if (profile !== "") {
  32. const client = createClient(profile, 'MMM-PublicTransportHafas');
  33. const rl = readline.createInterface({
  34. input: process.stdin,
  35. output: process.stdout
  36. });
  37. rl.question("Geben Sie eine Adresse oder einen Stationsnamen ein: ", (answer) => {
  38. rl.close();
  39. const opt = {
  40. results: 10,
  41. stations: true,
  42. adresses: false,
  43. poi: false
  44. };
  45. client.locations(answer, opt).then((response) => {
  46. console.log("\nGefundene Haltestellen für \"" + answer + "\":\n");
  47. response.forEach((element) => {
  48. printStationInfo(element);
  49. });
  50. process.exit(0);
  51. }).catch(console.error);
  52. });
  53. }
  54. function printStationInfo(element) {
  55. let id = element.id;
  56. let name = element.name;
  57. let products = element.products;
  58. if (id && name) {
  59. console.log("> Haltestelle: \"" + name + "\"\n ID: " + id + "\n " + refineProducts(products) + "\n");
  60. }
  61. }
  62. function refineProducts(products) {
  63. let result = "Verkehrsmittel: ";
  64. if (!products) {
  65. return result + "keine";
  66. }
  67. let availableProducts = Object.keys(products).filter(key => products[key]);
  68. let availableProductsReadable = arrayUnique(availableProducts.map(product => productMap[product]));
  69. return result + availableProductsReadable.join(", ");
  70. }