Skip to content

Commit

Permalink
feat: ⚡️ Update profiles when older than 7 days
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Ruck committed Dec 10, 2023
1 parent a9e8646 commit 7429376
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions services/cron-jobs/import-deputy-profiles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ const start = async () => {
},
}).then(async ({ data: deputyList }) => {
for (const deputyListItem of deputyList.deputies) {
const lastUpdate = await DeputyModel.findOne({ webId: deputyListItem.webId }).then(
(deputy) => deputy?.updatedAt as string,
);

// run only if last update is older than 7 day
if (lastUpdate && new Date(lastUpdate).getTime() > Date.now() - 1000 * 60 * 60 * 24 * 7) {
console.log('skip', deputyListItem.URL);
continue;
}
console.log('lastUpdate', lastUpdate);

await scrapeIt<Omit<IDeputy, 'URL' | 'webId' | 'period'>>(encodeURI(deputyListItem.URL), {
imgURL: {
selector: '.bt-bild-standard > img',
Expand Down

0 comments on commit 7429376

Please sign in to comment.