123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const request = require('request');
- const cheerio = require('cheerio');
- const New = require('../models/New.js')();
- class AosFatosWatch {
- constructor() {
- this.url = 'https://aosfatos.org/';
- this.websiteSlug = 'aosfatos';
- this.tag = 'diversos';
- }
- get Url() {
- return this.url;
- }
- get Tag() {
- return this.tag;
- }
- get WebsiteSlug() {
- return this.websiteSlug;
- }
- registerLatestNovelty() {
- request(this.url + '/noticias', function (error, response, body) {
- if (!error && response.statusCode == 200) {
-
- const $ = cheerio.load(body);
- const currentDate = new Date();
- const href = this.url + $('#three-cards').find('.card').first().attr('href');
- request(href, function (error2, response2, body2) {
- if (!error2 && response2.statusCode == 200) {
- const $2 = cheerio.load(body2);
- // conteúdo da postagem
- var content = $2('article:not(.social)').html();
- const article = {
- link: href,
- websiteSlug: this.websiteSlug,
- // data da postagem, no site...
- date: $2('article').find('.publish_date').first().text(),
- // imagem da postagem
- thumb: this.url + $('#three-cards').find('.card-image').first().css("background-image").replace("url('", '').replace("')", '').replace(/\"/gi, ""),
- // titulo da postagem
- title: $('#three-cards').find('.card-title > h2').first().text(),
- content: content,
- // tag da categoria
- tag: this.tag,
- }
- New.query
- .findAndCountAll({ where: { link: article.link } })
- .then(result => {
- if (result.count < 1) {
- New.query.create(article);
- console.log('[ADDED] ' + article.title + ' +')
- } else {
- console.log('[CHECKED] ' + article.websiteSlug + ' ✓')
- }
- });
- } else {
- console.log('[ERROR] HOUVE UM ERRO NO LINK DA POSTAGEM x ')
- }
- }.bind(this));
- } else {
- console.log('[ERROR] HOUVE ALGUM ERRO x ')
- }
- }.bind(this));
- }
- }
- module.exports = AosFatosWatch;
|