mykle1 / MMM-EveryNews

Over 30,000 News sources! Up to 10 at once. Simplified addition to your config entry.
MIT License
9 stars 3 forks source link

EveryNews no longer pulling down news updates #5

Open themox opened 2 years ago

themox commented 2 years ago

Hi, this module is no longer working for me. It stopped a couple days ago pulling down requests. It looks like it is making a request but never processing a response. I have tried uninstalling it and reinstalling it and no luck. When I did do that, I get the following error and MM was crashing on load.

[28.05.2022 05:56.47.404] [ERROR] WARNING! Could not load config file. Starting with default configuration. Error found: Error: Cannot find module 'request'
Require stack:
- /home/joseph/MagicMirror/modules/MMM-EveryNews/node_helper.js
- /home/joseph/MagicMirror/js/app.js
- /home/joseph/MagicMirror/js/electron.js
- /home/joseph/MagicMirror/node_modules/electron/dist/resources/default_app.asar/main.js
- 
[28.05.2022 05:56.47.407] [ERROR] App threw an error during load
[28.05.2022 05:56.47.408] [ERROR] Error: Cannot find module 'request'
Require stack:
- /home/joseph/MagicMirror/modules/MMM-EveryNews/node_helper.js
- /home/joseph/MagicMirror/js/app.js
- /home/joseph/MagicMirror/js/electron.js
- /home/joseph/MagicMirror/node_modules/electron/dist/resources/default_app.asar/main.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Function.n._resolveFilename (node:electron/js2c/browser_init:249:1105)
    at Function.Module._resolveFilename (/home/joseph/MagicMirror/node_modules/module-alias/index.js:49:29)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/joseph/MagicMirror/modules/MMM-EveryNews/node_helper.js:8:17)
    at Module._compile (node:internal/modules/cjs/loader:1116:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1169:10)
[28.05.2022 05:56.47.409] [ERROR] Whoops! There was an uncaught exception...
[28.05.2022 05:56.47.411] [ERROR] Error: Cannot find module 'request'
Require stack:
- /home/joseph/MagicMirror/modules/MMM-EveryNews/node_helper.js
- /home/joseph/MagicMirror/js/app.js
- /home/joseph/MagicMirror/js/electron.js
- /home/joseph/MagicMirror/node_modules/electron/dist/resources/default_app.asar/main.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Function.n._resolveFilename (node:electron/js2c/browser_init:249:1105)
    at Function.Module._resolveFilename (/home/joseph/MagicMirror/node_modules/module-alias/index.js:49:29)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/joseph/MagicMirror/modules/MMM-EveryNews/node_helper.js:8:17)
    at Module._compile (node:internal/modules/cjs/loader:1116:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1169:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/joseph/MagicMirror/modules/MMM-EveryNews/node_helper.js',
    '/home/joseph/MagicMirror/js/app.js',
    '/home/joseph/MagicMirror/js/electron.js',
    '/home/joseph/MagicMirror/node_modules/electron/dist/resources/default_app.asar/main.js',
    undefined
  ]
}

So I did some googling and tried to install the missing module (request):

joseph@innsmouth:~/MagicMirror/modules$ npm install request
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

added 30 packages, and audited 813 packages in 3s

87 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

MM now loads normally but EveryNews never gets past the loading message.

themox commented 2 years ago

Looks like NewsAPI changed their requirements in the last few days. Some troubleshooting with toy code based on the nodehelper.js from this module yielded the following error:

{"status":"error","code":"userAgentMissing","message":"Please set your User-Agent header to identify your application. Anonymous requests are not allowed."}

So I modified the code in nodehelper.js like below to add a User-Agent string to the header of the request, which works. Almost doesn't matter what you put in there as long as it is non-null. Recommend a change like below. If I get time later I'll make a pull request for the fix. Probably do something like a configurable UserAgent in the config, with a default being MagicMirror or something like that.

/* Magic Mirror
 * Module: MMM-EveryNews
 *
 * By Mykle1
 *
 */
const NodeHelper = require('node_helper');
const request = require('request');

module.exports = NodeHelper.create({
    start: function() {
        console.log("Starting node_helper for: " + this.name);
    },
    getNatGeo: function(url) {
        request({
               url: 'https://newsapi.org/v2/top-headlines?sources='+this.config.source+'&pageSize=50&sortBy=popularity&apiKey='+this.config.apiKey,
                headers: {'User-Agent':'MagicMirror'},
            method: 'GET'
        }, (error, response, body) => {
            if (!error && response.statusCode == 200) {
                var result = JSON.parse(body).articles;
                this.sendSocketNotification('NATGEO_RESULT', result);
            }
        });
    },

    socketNotificationReceived: function(notification, payload) {
        if (notification === 'GET_NATGEO') {
            this.getNatGeo(payload);
        }
        if (notification === 'CONFIG') {
            this.config = payload;
      //  console.log(this.config);
        }
    }
});
themox commented 2 years ago

This is fixed by pull request #6 . Recommend close upon merge of that with main branch. @mykle1

dustbits commented 1 year ago

I had the same issue the pull fixed it, @mykle1 I don't know you but I'm a big fan of your modules. Thank you for all your work! -Fellow NYorker