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.

node_helper.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Magic Mirror
  2. * Module: MMM-DynamicWeather
  3. *
  4. * By Scott Lewis - https://github.com/scottcl88/MMM-DynamicWeather
  5. * MIT Licensed.
  6. *
  7. * Extension helper module to call external resources
  8. */
  9. var NodeHelper = require("node_helper");
  10. var request = require("request");
  11. module.exports = NodeHelper.create({
  12. start: function () {},
  13. callApi: function (payload) {
  14. var that = this;
  15. this.url = payload;
  16. var success = false;
  17. console.info("[MMM-DynamicWeather] Getting Weather API data");
  18. request({ url: this.url, method: "GET" }, function (error, response, body) {
  19. var result = JSON.parse(body);
  20. if (error || response.statusCode !== 200) {
  21. console.error("[MMM-DynamicWeather] Failed getting api: ", error, response);
  22. } else {
  23. console.info("[MMM-DynamicWeather] Received successful Weather API data");
  24. success = true;
  25. }
  26. that.sendSocketNotification("API-Received", {
  27. url: that.url,
  28. result: result,
  29. success: success,
  30. });
  31. });
  32. },
  33. callHoliday: function () {
  34. var that = this;
  35. var success = false;
  36. console.info("[MMM-DynamicWeather] Getting Holiday data");
  37. request({ url: "https://www.timeanddate.com/holidays/us/?hol=43122559", method: "GET" }, function (error, response, body) {
  38. if (error || response.statusCode !== 200) {
  39. console.error("[MMM-DynamicWeather] Failed getting holidays: ", error, response);
  40. } else {
  41. console.info("[MMM-DynamicWeather] Received successful Holiday data");
  42. success = true;
  43. }
  44. var result = { holidayBody: body };
  45. that.sendSocketNotification("Holiday-Received", {
  46. url: that.url,
  47. result: result,
  48. success: success,
  49. });
  50. });
  51. },
  52. socketNotificationReceived: function (notification, payload) {
  53. if (notification === "API-Fetch") {
  54. this.callApi(payload);
  55. }
  56. if (notification === "Holiday-Fetch") {
  57. this.callHoliday();
  58. }
  59. },
  60. });