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 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* global module */
  2. /* Magic Mirror
  3. * Node Helper: MMM-COVID19-Ampel
  4. *
  5. * By Daniel Osterkamp
  6. * MIT Licensed.
  7. */
  8. var NodeHelper = require('node_helper')
  9. const fetch = require('node-fetch');
  10. var needle = require('needle');
  11. var incidentURLPrefix = 'https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=&objectIds='
  12. var incidentURLSuffix = '&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=OBJECTID%2CGEN%2CBEZ%2Ccases7_per_100k%2Ccases7_bl_per_100k%2CBL%2Ccases_per_population%2Ccases%2Cdeath_rate%2Clast_update&returnGeometry=false&returnCentroid=false&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=4326&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token='
  13. var spacer = '%2C'
  14. var requestURL = ''
  15. var vaccinationURL = 'https://impfdashboard.de/static/data/germany_vaccinations_timeseries_v2.tsv'
  16. module.exports = NodeHelper.create({
  17. start: function () {
  18. console.log('Starting node helper for: ' + this.name)
  19. },
  20. getIncidents: function (key) {
  21. var self = this
  22. if (key.length === 1) {
  23. requestURL = incidentURLPrefix + key[0] + incidentURLSuffix;
  24. }
  25. if (key.length > 1) {
  26. requestURL = incidentURLPrefix + key[0]
  27. for (let index = 1; index < key.length; index++) {
  28. const element = key[index];
  29. requestURL += spacer + element;
  30. }
  31. requestURL += incidentURLSuffix;
  32. }
  33. fetch(requestURL)
  34. .then(res => res.text())
  35. .then(body => {
  36. var result = JSON.parse(body)
  37. self.sendSocketNotification('INCIDENTS', result.features)
  38. });
  39. //Getting Vaccinations
  40. var options = {
  41. method: 'GET',
  42. url: vaccinationURL,
  43. headers: {
  44. 'Cache-Control' : "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0",
  45. 'Pragma' : "no-cache",
  46. 'Expires' : 0,
  47. 'Surrogate-Control' : "no-store"
  48. }
  49. }
  50. //Seems like the larger file does not get read by request - using needle instead
  51. needle.get(vaccinationURL, { compressed: true }, function(error, response) {
  52. if (!error && response.statusCode == 200) {
  53. var lines = response.body.split("\\r?\\n", -1);
  54. self.sendSocketNotification('VACCINATIONS', lines);
  55. }
  56. });
  57. },
  58. //Subclass socketNotificationReceived received.
  59. socketNotificationReceived: function (notification, payload) {
  60. if (notification === 'GET_INCIDENTS') {
  61. this.getIncidents(payload)
  62. }
  63. }
  64. });