Skip to content

Commit b2af779

Browse files
committed
More reversions for upstream, new param 4 date.
1 parent 6027141 commit b2af779

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

main.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const communities = [
8686
// exclude will remove posts from the feed based on the contents of another feed - It is processed second.
8787
// pinCategories will pin posts in the feed that match the category name and are within the specified number of days
8888
// content is the name of the field in the feed that contains the post content. Defaults to 'content' if not specified
89+
// datefield is the name of the field in the feed that contains the post date. Defaults to 'pubDate' if not specified
8990
//
9091
// const feeds = [
9192
// {
@@ -120,6 +121,7 @@ const feeds = [
120121
{
121122
name: 'godot',
122123
url: 'https://godotengine.org/rss.xml',
124+
datefield: 'pubDate',
123125
pinCategories: [
124126
{ name: 'Release', days: 7 },
125127
{ name: 'Pre-release', days: 7 },
@@ -129,10 +131,12 @@ const feeds = [
129131
name: 'unreal',
130132
url: 'https://www.unrealengine.com/en-US/rss',
131133
content: 'summary',
134+
datefield: 'published',
132135
},
133136
{
134137
name: 'unity',
135138
url: 'https://blogs.unity3d.com/feed/',
139+
datefield: 'pubDate',
136140
}
137141
]
138142

@@ -204,23 +208,22 @@ const bot = new LemmyBot.LemmyBot({
204208
},
205209
schedule: [
206210
{
207-
cronExpression: '0 */30 * * * *',
208-
timezone: 'America/Phoenix',
209-
runAtStart: true,
211+
cronExpression: '0 */5 * * * *',
212+
timezone: 'America/Toronto',
210213
doTask: async ({getCommunityId, createPost}) => {
211214
console.log(`${chalk.green('STARTED:')} RSS Feed Fetcher.`);
212215
for (const feed of feeds) {
213216
const rss = await parser.parseURL(feed.url);
214217

215218
const cutoffDate = new Date();
216-
console.log(`${chalk.green('CURRENT DATE:')} ${cutoffDate}`);
219+
console.log(`${chalk.white('CURRENT DATE:')} ${cutoffDate}`);
217220
cutoffDate.setMonth(cutoffDate.getMonth() - 6); // set to 6 months ago
218-
console.log(`${chalk.green('CUTOFF DATE:')} ${cutoffDate}`);
221+
console.log(`${chalk.white('CUTOFF DATE:')} ${cutoffDate}`);
219222

220223
let joinedItems = [];
221224
// gather all items from feeds to be joined
222225
if (feed.joinfeeds) {
223-
console.log(`${chalk.green('FETCHING:')} joining feeds for ${feed.name}`);
226+
console.log(`${chalk.white('FETCHING:')} joining feeds for ${feed.name}`);
224227
for (const joinFeedName of feed.joinfeeds) {
225228
const joinFeed = feeds.find(f => f.name === joinFeedName);
226229

@@ -237,7 +240,7 @@ const bot = new LemmyBot.LemmyBot({
237240

238241
// exclude feeds
239242
if (feed.exclude) {
240-
console.log(`${chalk.green('FETCHING:')} exclusion feeds for ${feed.name}`);
243+
console.log(`${chalk.white('FETCHING:')} exclusion feeds for ${feed.name}`);
241244
for (const excludeFeedName of feed.exclude) {
242245
const excludeFeed = feeds.find(f => f.name === excludeFeedName);
243246

@@ -255,12 +258,12 @@ const bot = new LemmyBot.LemmyBot({
255258

256259
for (const item of commonItems) {
257260
let pin_days = 0;
258-
const itemDate = new Date(item['dc:date'].trim());
259-
console.log(`${chalk.green('ITEM DATE:')} ${itemDate}`);
261+
const itemDate = new Date(item[feed.datefield].trim());
262+
console.log(`${chalk.white('ITEM DATE:')} ${itemDate}`);
260263
//if item is newer than 6 months old, continue
261264
if (itemDate > cutoffDate) {
262265
console.log(`${chalk.green('RECENT:')} true`);
263-
console.log(`${chalk.green('LINK:')} ${item.link}`);
266+
console.log(`${chalk.white('LINK:')} ${item.link}`);
264267
// if has categories then see if it's a pin
265268
if (feed.pinCategories && item.categories) {
266269
for (const category of item.categories) {
@@ -275,30 +278,26 @@ const bot = new LemmyBot.LemmyBot({
275278
if (err) {
276279
if (err.message.includes('UNIQUE constraint failed')) {
277280
// do nothing
278-
console.log(`${chalk.green('PRESENT:')} ${item.link} already present`);
281+
console.log(`${chalk.yellow('PRESENT:')} ${item.link} already present`);
279282
return;
280283
} else {
281-
console.log(`${chalk.green('ERROR:')} ${err.message}`);
282284
return console.error(err.message);
283285
}
284286
}
285287
console.log(`${chalk.green('INSERTED:')} ${item.link} into database.`);
286288

287289
for (const community of communities) {
288290
if (community.feeds.includes(feed.name)) {
289-
290-
// Process the item only if its link is not in the excludeItems list
291-
if (!excludeItems.includes(item.link)) {
292-
console.log(`${chalk.green('CREATING:')} post for link ${item.link} in ${community.slug }`);
293-
const communityId = await getCommunityId({ name: community.slug, instance: community.instance });
294-
await createPost({
295-
name: item.title,
296-
body: ((feed.content && feed.content === 'summary') ? item.summary : item.content),
297-
url: item.link || undefined,
298-
community_id: communityId,
299-
});
300-
await sleep(sleepDuration);
301-
}
291+
console.log(`${chalk.green('CREATING:')} post for link ${item.link} in ${community.slug }`);
292+
const communityId = await getCommunityId({ name: community.slug, instance: community.instance });
293+
await createPost({
294+
name: item.title,
295+
body: ((feed.content && feed.content === 'summary') ? item.summary : item.content),
296+
url: item.link || undefined,
297+
community_id: communityId,
298+
});
299+
await sleep(sleepDuration);
300+
302301
}
303302
}
304303
console.log(`${chalk.green('ADDED:')} ${item.link} for ${pin_days} days`);
@@ -311,8 +310,8 @@ const bot = new LemmyBot.LemmyBot({
311310
}
312311
},
313312
{
314-
cronExpression: '0 */45 * * * *',
315-
timezone: 'America/Phoenix',
313+
cronExpression: '0 */5 * * * *',
314+
timezone: 'America/Toronto',
316315
doTask: async ({ featurePost }) => {
317316
const now = addMinutes(new Date(), 30);
318317
const day = now.getDay();

0 commit comments

Comments
 (0)