From 91419956307da1a00c2decc74ab612e3e6d145db Mon Sep 17 00:00:00 2001 From: Axel Pettersson Date: Sun, 17 Sep 2023 19:58:56 +0200 Subject: [PATCH] Finish first implementation of CLI --- packages/party-data/cli.ts | 7 ++++++- packages/party-data/index.ts | 9 ++++++++- packages/party-data/parties/s.json | 12 ++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/party-data/cli.ts b/packages/party-data/cli.ts index 1e54a6f85..5d5e4b810 100644 --- a/packages/party-data/cli.ts +++ b/packages/party-data/cli.ts @@ -1,5 +1,9 @@ import { select } from "@inquirer/prompts"; -import { readNotCategorizedStandpoints, readSubjects } from "."; +import { + readNotCategorizedStandpoints, + readSubjects, + updateStandpoint, +} from "."; async function categorize() { const subjects = readSubjects(); @@ -19,6 +23,7 @@ ${standpoint.opinions.map((opinion) => `\t${opinion}`).join("\n")}`, choices: subjectChoices, }); standpoint.subject = choice; + updateStandpoint(standpoint.party, standpoint); } } diff --git a/packages/party-data/index.ts b/packages/party-data/index.ts index 72ffb9706..19ce43f7f 100644 --- a/packages/party-data/index.ts +++ b/packages/party-data/index.ts @@ -77,7 +77,14 @@ export function writePartyData( fs.writeFileSync(fileName, JSON.stringify(storedData, null, 2)); } -// export function updateSubject(abbreviation: string, standpoint: Standpoint) {} +export function updateStandpoint(abbreviation: string, standpoint: Standpoint) { + const fileName = partyFileName(abbreviation); + const storedData = JSON.parse( + fs.readFileSync(fileName).toString(), + ) as PartyData; + storedData[standpoint.url] = standpoint; + fs.writeFileSync(fileName, JSON.stringify(storedData, null, 2)); +} function readSubjectData() { return JSON.parse(fs.readFileSync(SUBJECTS_FILE).toString()) as SubjectData; diff --git a/packages/party-data/parties/s.json b/packages/party-data/parties/s.json index 693f23fe0..d9d8c8db4 100644 --- a/packages/party-data/parties/s.json +++ b/packages/party-data/parties/s.json @@ -4,7 +4,8 @@ "title": "Abort", "url": "https://www.socialdemokraterna.se/var-politik/a-till-o/abort", "fetchDate": "2023-09-17T17:52:39.845Z", - "party": "s" + "party": "s", + "subject": "Vård och Omsorg" }, "https://www.socialdemokraterna.se/var-politik/a-till-o/a-kassan": { "opinions": [ @@ -21,7 +22,8 @@ "title": "A-kassan", "url": "https://www.socialdemokraterna.se/var-politik/a-till-o/a-kassan", "fetchDate": "2023-09-17T17:52:39.358Z", - "party": "s" + "party": "s", + "subject": "Trygghetssystem och Välfärd" }, "https://www.socialdemokraterna.se/var-politik/a-till-o/alkohol": { "opinions": [ @@ -37,7 +39,8 @@ "title": "Alkohol", "url": "https://www.socialdemokraterna.se/var-politik/a-till-o/alkohol", "fetchDate": "2023-09-17T17:52:38.147Z", - "party": "s" + "party": "s", + "subject": "Vård och Omsorg" }, "https://www.socialdemokraterna.se/var-politik/a-till-o/antirasism-och-framlingsfientlighet": { "opinions": [ @@ -51,7 +54,8 @@ "title": "Antirasism och främlingsfientlighet", "url": "https://www.socialdemokraterna.se/var-politik/a-till-o/antirasism-och-framlingsfientlighet", "fetchDate": "2023-09-17T17:52:39.028Z", - "party": "s" + "party": "s", + "subject": "Jämställdhet och diskriminering" }, "https://www.socialdemokraterna.se/var-politik/a-till-o/apotek": { "opinions": [