Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#39] Fix poll number and end date parsing #40

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-yaks-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"osrs-web-scraper": patch
---

Fix poll number and end date parsing
10 changes: 7 additions & 3 deletions src/scrapers/polls/sections/pollHeader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from "date-fns";
import { format, parse } from "date-fns";
import { HTMLElement } from "node-html-parser";

import { PollSection } from "./types";
Expand Down Expand Up @@ -28,16 +28,20 @@ const pollHeader: PollSection = {

const content: MediaWikiContent[] = [];

const number = url.split("=")?.[3];
const position = url.lastIndexOf("=");
const number = url.substring(position + 1, url.length);
const startDate = title
.match(/\(([^)]+)\)/g)?.[0]
.replaceAll(/(\()*(\))*/g, "");

const endDate = description.match(/This poll will close on (.*)\./)?.[1];
const endDateFormatted = parse(endDate, "EEEE do MMMM", new Date());

content.push(
new PollNoticeTemplate(
parseInt(number),
format(new Date(startDate), "d MMMM yyyy"),
""
format(endDateFormatted, "d MMMM yyyy")
).build()
);
content.push(new MediaWikiBreak());
Expand Down
Loading