From 2dadb5ba4c7500c5b9c3fc9139a89405fa409193 Mon Sep 17 00:00:00 2001 From: Michal Drla Date: Wed, 14 Feb 2024 18:48:55 +0100 Subject: [PATCH] fix: Fix scraping issues caused by recent change of dspace site Signed-off-by: Michal Drla --- src/commands/verify.ts | 6 +++++- src/utils/assignRole.ts | 7 +++++-- src/utils/scrapeThesis.ts | 9 ++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 0dea187..70fc05c 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -67,9 +67,13 @@ export async function execute(interaction: ChatInputCommandInteraction) { }); } try { + let thesisId = bachelorThesisParsedUrl.pathname.split('/')[3]; + if (thesisId === undefined) { + thesisId = bachelorThesisParsedUrl.pathname.split('/')[2]; + } user = await prisma.users.findMany({ where: { - idThesis: bachelorThesisParsedUrl.pathname.split('/')[3], + idThesis: thesisId, }, }); } catch (err) { diff --git a/src/utils/assignRole.ts b/src/utils/assignRole.ts index 6988c10..f2fbbf8 100644 --- a/src/utils/assignRole.ts +++ b/src/utils/assignRole.ts @@ -52,11 +52,14 @@ export async function assignRole( ); const member = interaction.member as GuildMember; try { + let idThesis = bachelorThesisParsedUrl.pathname.split('/')[3]; + if (idThesis === undefined) { + idThesis = bachelorThesisParsedUrl.pathname.split('/')[2]; + } await prisma.users.create({ data: { discordId: interaction.user.id, - idThesis: - bachelorThesisParsedUrl.pathname.split('/')[3], + idThesis: idThesis, status: 'verified', }, }); diff --git a/src/utils/scrapeThesis.ts b/src/utils/scrapeThesis.ts index 1cfc5eb..552abb3 100644 --- a/src/utils/scrapeThesis.ts +++ b/src/utils/scrapeThesis.ts @@ -15,8 +15,11 @@ export async function scrapeThesis(bachelorThesisPath: string) { } const $ = load(response.data); const authorName = $( - '#aspect_artifactbrowser_ItemViewer_div_item-view > div > div.row > div.col-sm-4 > div:nth-child(2) > div > a' + 'ds-metadata-representation-list.ds-item-page-mixed-author-field:nth-child(4) > ds-metadata-field-wrapper:nth-child(1) > div:nth-child(1) > div:nth-child(2) > ds-metadata-representation-loader:nth-child(1) > ds-plain-text-metadata-list-element:nth-child(1) > div:nth-child(1) > a:nth-child(1)' ).text(); - - return authorName.split(',').reverse().join(' '); + return authorName + .split(',') + .reverse() + .map((name) => name.trim()) + .join(' '); }