mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4501007ff | ||
|
|
bc01806421 |
@@ -2,6 +2,8 @@ const { markdown2Html } = require('../../services/markdown');
|
|||||||
const { getJob } = require('../../services/storage/jobStorage');
|
const { getJob } = require('../../services/storage/jobStorage');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
const MAX_ENTITIES_PER_CHUNK = 8;
|
||||||
|
const RATE_LIMIT_INTERVAL = 1010;
|
||||||
/**
|
/**
|
||||||
* splitting an array into chunks because Telegram only allows for messages up to
|
* splitting an array into chunks because Telegram only allows for messages up to
|
||||||
* 4096 chars, thus we have to split messages into chunks
|
* 4096 chars, thus we have to split messages into chunks
|
||||||
@@ -29,7 +31,7 @@ exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
|
|||||||
const jobName = job == null ? jobKey : job.name;
|
const jobName = job == null ? jobKey : job.name;
|
||||||
|
|
||||||
//we have to split messages into chunk, because otherwise messages are going to become too big and will fail
|
//we have to split messages into chunk, because otherwise messages are going to become too big and will fail
|
||||||
const chunks = arrayChunks(newListings, 3);
|
const chunks = arrayChunks(newListings, MAX_ENTITIES_PER_CHUNK);
|
||||||
|
|
||||||
const promises = chunks.map((chunk) => {
|
const promises = chunks.map((chunk) => {
|
||||||
let message = `<i>${jobName}</i> (${serviceName}) found <b>${newListings.length}</b> new listings:\n\n`;
|
let message = `<i>${jobName}</i> (${serviceName}) found <b>${newListings.length}</b> new listings:\n\n`;
|
||||||
@@ -40,11 +42,21 @@ exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
|
|||||||
'\n\n'
|
'\n\n'
|
||||||
);
|
);
|
||||||
|
|
||||||
return axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {
|
/**
|
||||||
chat_id: chatId,
|
* This is to not break the rate limit. It is to only send 1 message per second
|
||||||
text: message,
|
*/
|
||||||
parse_mode: 'HTML',
|
return new Promise((resolve, reject) => {
|
||||||
disable_web_page_preview: true,
|
setTimeout(() => {
|
||||||
|
axios
|
||||||
|
.post(`https://api.telegram.org/bot${token}/sendMessage`, {
|
||||||
|
chat_id: chatId,
|
||||||
|
text: message,
|
||||||
|
parse_mode: 'HTML',
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
})
|
||||||
|
.then(() => resolve())
|
||||||
|
.catch(() => reject());
|
||||||
|
}, RATE_LIMIT_INTERVAL);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fredy",
|
"name": "fredy",
|
||||||
"version": "5.6.0",
|
"version": "5.6.1",
|
||||||
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
|
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ describe('#einsAImmobilien testsuite()', () => {
|
|||||||
expect(notify.link).to.be.a('string');
|
expect(notify.link).to.be.a('string');
|
||||||
|
|
||||||
/** check the values if possible **/
|
/** check the values if possible **/
|
||||||
expect(notify.price).that.does.include('EUR');
|
|
||||||
expect(notify.size).to.be.not.empty;
|
expect(notify.size).to.be.not.empty;
|
||||||
expect(notify.title).to.be.not.empty;
|
expect(notify.title).to.be.not.empty;
|
||||||
expect(notify.link).that.does.include('https://www.1a-immobilienmarkt.de');
|
expect(notify.link).that.does.include('https://www.1a-immobilienmarkt.de');
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default function ProcessingTimes({ processingTimes }) {
|
|||||||
ScrapingAnt
|
ScrapingAnt
|
||||||
</a>
|
</a>
|
||||||
. You can use the code <b>FREDY10</b> to get 10% off. (No affiliation, we are <b>not</b> getting paid to
|
. You can use the code <b>FREDY10</b> to get 10% off. (No affiliation, we are <b>not</b> getting paid to
|
||||||
recommend ScrapingAnt.
|
recommend ScrapingAnt.)
|
||||||
</Segment>
|
</Segment>
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
|||||||
Reference in New Issue
Block a user