Skip to content

Commit

Permalink
feat(events): add static host details to ClEvent (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 authored Oct 28, 2024
1 parent 173a6f6 commit 2712898
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 2 deletions.
92 changes: 92 additions & 0 deletions src/data/clubs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[
{
"club": "Studierendenvertretung",
"instagram": "https://www.instagram.com/studverthi/",
"website": "https://studverthi.de"
},
{
"club": "Hochschulband",
"instagram": "https://www.instagram.com/studverthi/",
"website": "https://studverthi.de"
},
{
"club": "Hochschulkino",
"instagram": "https://www.instagram.com/hochschulkino.thi/",
"website": "https://studverthi.de/hochschulkino"
},
{
"club": "think e. V.",
"instagram": "https://www.instagram.com/think.thi/",
"website": "https://think-thi.de/"
},
{
"club": "Neuland Ingolstadt e. V.",
"instagram": "https://www.instagram.com/neuland_ingolstadt/",
"website": "https://neuland-ingolstadt.de/"
},
{
"club": "Our Future e. V.",
"instagram": "https://www.instagram.com/ourfuture_ingolstadt/",
"website": "https://www.ourfuturethi.de/"
},
{
"club": "NEWEXIST e. V.",
"instagram": "https://www.instagram.com/newexist_official/",
"website": "https://newexist.com/"
},
{
"club": "N.I.C.E. e. V.",
"instagram": "https://www.instagram.com/niceingolstadt/",
"website": "https://www.thi.de/studium/studentisches-leben/studentische-vereine-an-der-thi/nice-network-international-culture-exchange/"
},
{
"club": "Eta-nol e. V.",
"instagram": "https://www.instagram.com/eta_nol_in/",
"website": "https://eta-nol.de/"
},
{
"club": "Students' Life e.V.",
"instagram": "https://www.instagram.com/studentslife.thingolstadt/",
"website": "https://students-life.de"
},
{
"club": "consult.IN e.V.",
"instagram": "https://www.instagram.com/consult.in/",
"website": "https://consultin.net/"
},
{
"club": "Schanzer Racing Electric e.V.",
"instagram": "https://www.instagram.com/schanzerracing/",
"website": "https://www.schanzer-racing.de/"
},
{
"club": "UNICEF Hochschulgruppe",
"instagram": "https://www.instagram.com/unicef_hsg_in/",
"website": "https://www.unicef.de/mitmachen/ehrenamtlich-aktiv/-/hochschulgruppe-thi-ingolstadt"
},
{
"club": "Hochschulgaming Ingolstadt",
"instagram": "https://www.instagram.com/hochschulgaming_in/",
"website": "https://hochschulgaming.de/"
},
{
"club": "LEO Club Ingolstadt",
"instagram": "https://www.instagram.com/leoclubingolstadt/",
"website": "https://www.thi.de/studium/studentisches-leben/studentische-vereine-an-der-thi/leo-club-ingolstadt/"
},
{
"club": "Studentischer Börsenclub Ingolstadt e. V.",
"instagram": "https://www.instagram.com/boersenclubingolstadt/",
"website": "https://www.boersenclub-ingolstadt.de/"
},
{
"club": "Studenten Bilden Schüler e.V.",
"instagram": "https://www.instagram.com/studentenbildenschueler/",
"website": "https://studenten-bilden-schueler.de/standorte/ingolstadt"
},
{
"club": "Nightlife Neuburg e.V.",
"instagram": "https://www.instagram.com/nightlifeneuburg/",
"website": "https://www.instagram.com/nightlifeneuburg/"
}
]
2 changes: 2 additions & 0 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DateTimeResolver,
EmailAddressResolver,
LocalEndTimeResolver,
URLResolver,
} from 'graphql-scalars'

import { deleteAppAnnouncement } from './mutations/app-announcements/delete'
Expand Down Expand Up @@ -39,4 +40,5 @@ export const resolvers = {
LocalTime: LocalEndTimeResolver,
DateTime: DateTimeResolver,
EmailAddress: EmailAddressResolver,
URL: URLResolver,
}
25 changes: 24 additions & 1 deletion src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ type ClEvent {
"""
Organizer of the event
"""
organizer: String!
organizer: String! @deprecated(reason: "Use host field instead")
"""
Host of the event
"""
host: Host!
"""
Title of the event in German
"""
Expand All @@ -353,6 +357,24 @@ type ClEvent {
description: String
}

"""
Host of the event, usually a club or student group
"""
type Host {
"""
Name of the event host
"""
name: String!
"""
URL to the event host website
"""
website: URL
"""
Instagram URL of the event host
"""
instagram: URL
}

"""
Charging station data
"""
Expand Down Expand Up @@ -739,3 +761,4 @@ type UpsertResponse {
scalar DateTime
scalar LocalTime
scalar EmailAddress
scalar URL
25 changes: 24 additions & 1 deletion src/scraping/cl-event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* @file Scrapes events from the `Campus Life` Moodle course and serves them at `/api/events`.
*/
import type { ClEvent } from '@/types/clEvents'
import clubsData from '@/data/clubs.json'
import type { ClEvent, ClHost } from '@/types/clEvents'
import * as cheerio from 'cheerio'
import crypto from 'crypto'
import fetchCookie, { type FetchCookieImpl } from 'fetch-cookie'
Expand Down Expand Up @@ -227,6 +228,27 @@ async function getEventDetails(
)
}

function getHostDetails(host: string): ClHost {
const trimmed = host
.trim()
.replace(/( \.)$/g, '')
.replace(/e\. V\./g, 'e.V.')
const club = clubsData.find((club) => club.club === trimmed)
if (club == null) {
return {
name: trimmed,
website: null,
instagram: null,
}
}

return {
name: club.club,
website: club.website,
instagram: club.instagram,
}
}

/**
* Fetches all event details from Moodle.
* @param {string} username
Expand Down Expand Up @@ -255,6 +277,7 @@ export async function getAllEventDetails(
organizer: details.Verein.trim()
.replace(/( \.)$/g, '')
.replace(/e\. V\./g, 'e.V.'),
host: getHostDetails(details.Verein),
title: details.Event,
begin:
details.Start.length > 0
Expand Down
7 changes: 7 additions & 0 deletions src/types/clEvents.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export interface ClEvent {
id: string
organizer: string
host: ClHost
title: string
begin: Date | null
end: Date | null
location: string | null
description: string | null
}

export interface ClHost {
name: string
website: string | null
instagram: string | null
}

0 comments on commit 2712898

Please sign in to comment.