Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
feat(sponsore): import sponsors scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MaloPolese committed Nov 22, 2023
1 parent 5c202d5 commit eb2fd82
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/openplanner/getSpeakersSessionsSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getSocialHandle = (social: string | null) => {
return social.split('/').pop()
}

export const getSpeakersSessionsScheduleFromUrl = async (url: string) => {
export const getSpeakersSessionsScheduleSponsorFromUrl = async (url: string) => {
const data = await fetch(url + "?tt=2").then(r => r.json())

return await getSpeakersSessionsSchedule(data)
Expand Down
48 changes: 46 additions & 2 deletions scripts/openplanner/import-speakers-sessions-schedule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
import admin, {firestore as firestoreDep, ServiceAccount} from 'firebase-admin'
import {getSpeakersSessionsScheduleFromUrl} from './getSpeakersSessionsSchedule'
import {getSpeakersSessionsScheduleSponsorFromUrl} from './getSpeakersSessionsSchedule'
import {TeamMember} from './types'

if (!process.env.firebaseServiceAccount) {
Expand Down Expand Up @@ -53,6 +53,48 @@ export const importSessions = async (data: any) => {
const results = await batch.commit()
console.log('Imported data for', results.length, 'sessions')
}

export const importSponsors = async (data: any) => {
const sponsors: { [key: string]: object } = data.sponsors
if (!Object.keys(sponsors).length) {
return Promise.resolve()
}
console.log('Importing', Object.keys(sponsors).length, 'sponsors...')
const batch = firestore.batch()

Object.keys(sponsors).forEach((sponsorId) => {
const sponsor = sponsors[Number(sponsorId)];
if (sponsor) {
batch.set(firestore.collection('partners').doc(sponsorId), {
title: sponsor.name,
order: sponsor.order || 0,
});

sponsor.sponsors.forEach((item, id) => {
batch.set(
firestore
.collection('partners')
.doc(`${sponsorId}`)
.collection('items')
.doc(`${id}`.padStart(3, '0')),
{
height: 60,
logoUrl: item.logoUrl,
name: item.name,
order: item.order || 0,
url: item.website,
}
);
});
} else {
console.warn(`Missing partner ${sponsorId}`);
}
});

const results = await batch.commit()
console.log('Imported data for', results.length, 'speakers')
}

export const importSchedule = async (data: any) => {
const docs: { [key: string]: object } = data.schedule
if (!Object.keys(docs).length) {
Expand Down Expand Up @@ -133,15 +175,17 @@ const cleanupScheduleSessionSpeakers = async () => {
await deleteCollection('schedule')
await deleteCollection('sessions')
await deleteCollection('speakers')
await deleteCollection('partners')
console.log('Cleanup done')
}

getSpeakersSessionsScheduleFromUrl(url)
getSpeakersSessionsScheduleSponsorFromUrl(url)
.then(async (data) => {
await cleanupScheduleSessionSpeakers()
await importSessions(data)
await importSpeakers(data)
await importSchedule(data)
await importSponsors(data)
return data
})
.then(async (data) => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/openplanner/testLocally.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getSpeakersSessionsScheduleFromUrl } from './getSpeakersSessionsSchedule'
import { getSpeakersSessionsScheduleSponsorFromUrl } from './getSpeakersSessionsSchedule'

const main = async () => {
if (!process.env['CONFERENCE_CENTER_FILE']) {
throw new Error('missing CONFERENCE_CENTER_FILE env')
}

await getSpeakersSessionsScheduleFromUrl(process.env["CONFERENCE_CENTER_FILE"]+"?t="+Date.now())
await getSpeakersSessionsScheduleSponsorFromUrl(process.env["CONFERENCE_CENTER_FILE"]+"?t="+Date.now())

console.log("done")
}
Expand Down

0 comments on commit eb2fd82

Please sign in to comment.