Skip to content

Commit

Permalink
Merge pull request #104 from mimotej/fix-thesis-scraping
Browse files Browse the repository at this point in the history
fix: Fix scraping issues caused by recent change of dspace site
  • Loading branch information
mimotej authored Feb 14, 2024
2 parents c0e359c + 2dadb5b commit 9a44b5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/commands/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/assignRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
Expand Down
9 changes: 6 additions & 3 deletions src/utils/scrapeThesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
}

0 comments on commit 9a44b5b

Please sign in to comment.