Skip to content

Commit

Permalink
Merge pull request #79 from leben-in-deutschland/feature/inform-user-…
Browse files Browse the repository at this point in the history
…about-new-questions

Add ID to stop api calls for translation
  • Loading branch information
manishtiwari25 authored Feb 25, 2025
2 parents 7125fd6 + 52f9ea8 commit 165f59b
Show file tree
Hide file tree
Showing 10 changed files with 8,641 additions and 7,830 deletions.
13 changes: 11 additions & 2 deletions src/app/web/data/prüfstellen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,15 @@
"telefon": "040-3199160-16",
"email": "olga.debus@kom-bildung.de"
},
{
"regierungsbezirk": "Kreisfreie Stadt",
"plz": 22767,
"ort": "Hamburg",
"einrichtung": "Akademikerbund Hamburg e.V.",
"straße": "Große Bergstrße 6a",
"telefon": "040-63737260",
"email": "altona@abh-kurse.de"
},
{
"regierungsbezirk": "Kreisfreie Stadt",
"plz": 22767,
Expand Down Expand Up @@ -2919,8 +2928,8 @@
"ort": "Wolfenbüttel",
"einrichtung": "KVHS Wolfenbüttel",
"straße": "Harzstr.2-5",
"telefon": "05331/84 157 oder ab Jan.09 05331/84 158",
"email": "d.eicke@lkwf.de"
"telefon": "05331-84-898 oder84-153",
"email": "biz-infopoint@lk-wf.de"
},
{
"regierungsbezirk": "Verden",
Expand Down
8,204 changes: 4,295 additions & 3,909 deletions src/app/web/data/question.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"keywords": [],
"author": "",
"license": "ISC"
}
}
1 change: 1 addition & 0 deletions src/app/web/types/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const categories = ["Rights & Freedoms",

export interface Question {
num: string;
id: string;
question: string;
a: string;
b: string;
Expand Down
13 changes: 11 additions & 2 deletions src/scrap/data/prüfstellen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,15 @@
"telefon": "040-3199160-16",
"email": "olga.debus@kom-bildung.de"
},
{
"regierungsbezirk": "Kreisfreie Stadt",
"plz": 22767,
"ort": "Hamburg",
"einrichtung": "Akademikerbund Hamburg e.V.",
"straße": "Große Bergstrße 6a",
"telefon": "040-63737260",
"email": "altona@abh-kurse.de"
},
{
"regierungsbezirk": "Kreisfreie Stadt",
"plz": 22767,
Expand Down Expand Up @@ -2919,8 +2928,8 @@
"ort": "Wolfenbüttel",
"einrichtung": "KVHS Wolfenbüttel",
"straße": "Harzstr.2-5",
"telefon": "05331/84 157 oder ab Jan.09 05331/84 158",
"email": "d.eicke@lkwf.de"
"telefon": "05331-84-898 oder84-153",
"email": "biz-infopoint@lk-wf.de"
},
{
"regierungsbezirk": "Verden",
Expand Down
8,204 changes: 4,295 additions & 3,909 deletions src/scrap/data/question.json

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions src/scrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as fs from 'fs';
import * as path from 'path';
import * as XLSX from 'xlsx';
import { Prüfstellen } from './types/prüfstellen';
import { createHash } from 'crypto';
import existingQuestionJson from './data/question.json';

const BASE_URL = 'https://www.einbuergerungstest-online.de';
const BASE_URL_BAMF = "https://www.bamf.de"
Expand Down Expand Up @@ -48,7 +50,8 @@ const scrap = async (url: string, state: string) => {
image: '-',
translation: {},
category: null,
context: ''
context: '',
id: ''
};
question.question = pageData(element).find("strong.font-semibold").text().trim();
if (pageData(element).find("img").length > 0) {
Expand Down Expand Up @@ -153,9 +156,15 @@ const translate = async (question: Question) => {
}
};

const generateId = (question: Question) => {
const text = question.question + question.a + question.b + question.c + question.d;
const crypt = createHash('sha256').update(text).digest('hex')
return crypt;
};

async function scrapeData() {
try {

const oldQuestion = JSON.parse(JSON.stringify(existingQuestionJson)) as Question[]
let questions = await scrapAll();
let stateQuestion = await scrapStates();
const allQuestion = [...questions, ...stateQuestion];
Expand All @@ -164,9 +173,17 @@ async function scrapeData() {
if (!allQuestion[i].question) {
continue;
}
allQuestion[i].category = await findCategory(allQuestion[i]);
allQuestion[i].context = await getContext(allQuestion[i]);
allQuestion[i] = await translate(allQuestion[i]);
allQuestion[i].id = generateId(allQuestion[i]);
const existing = oldQuestion.findIndex((q) => q && q.id === allQuestion[i].id);
if (existing !== -1) {
allQuestion[i].translation = oldQuestion[existing].translation;
allQuestion[i].category = oldQuestion[existing].category;
allQuestion[i].context = oldQuestion[existing].context;
} else {
allQuestion[i].category = await findCategory(allQuestion[i]);
allQuestion[i].context = await getContext(allQuestion[i]);
allQuestion[i] = await translate(allQuestion[i]);
}
}
const dir = './data';
const filePath = path.join(dir, 'question.json');
Expand Down
4 changes: 3 additions & 1 deletion src/scrap/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"sourceMap": true
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
}
}
1 change: 1 addition & 0 deletions src/scrap/types/question.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Question {
num: string;
id: string;
question: string;
a: string;
b: string;
Expand Down

0 comments on commit 165f59b

Please sign in to comment.