Skip to content

Commit

Permalink
Merge pull request #77 from TurunWappuradio/fix/generate-showlist-json
Browse files Browse the repository at this point in the history
Fix: ohjelmakartta.jsonin luonti oli kadonnut
  • Loading branch information
niemisami authored Apr 14, 2024
2 parents ab330ea + b7c0c47 commit fcb83e2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/google/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Color, Show, ShowsByDate, showsToGroups } from './showlistHelpers';
import { sheets_v4 } from '@googleapis/sheets';
import { addMilliseconds, formatISO, getHours } from 'date-fns';

Expand All @@ -8,7 +7,9 @@ import {
ensureDirectoryExists,
getImagePath,
saveArrayBufferToFile,
writeFile,
} from '@/utils/fileHelpers';
import { Color, Show, ShowsByDate, showsToGroups } from './showlistHelpers';

const NEXT_URL = '/showlist' as const;
const FILE_URL = `./public${NEXT_URL}` as const;
Expand Down Expand Up @@ -116,6 +117,10 @@ export const parseSheetToShowList = async (
return showList;
};

export const saveShowlistJson = async (data: Record<string, unknown>) => {
await writeFile(`${FILE_URL}/ohjelmakartta.json`, JSON.stringify(data));
};

export const fetchShowlist = async (): Promise<ShowsByDate> => {
const data = await getSheet({
apiKey: process.env.GA_API_KEY,
Expand All @@ -128,7 +133,10 @@ export const fetchShowlist = async (): Promise<ShowsByDate> => {
const shows = data
? await parseSheetToShowList(data, { apiKey: process.env.GA_API_KEY })
: [];
return showsToGroups(shows);

const showsByDate = showsToGroups(shows);
await saveShowlistJson(showsByDate);
return showsByDate;
};

const downloadShowFile = async (
Expand Down

0 comments on commit fcb83e2

Please sign in to comment.