Skip to content

Commit

Permalink
feat: 노션 api 스크립트 적용 (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
saseungmin authored Nov 12, 2024
1 parent d529d66 commit 1541776
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
Binary file not shown.
Binary file not shown.
6 changes: 5 additions & 1 deletion apps/admin/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ module.exports = {
},
},
],
rules: {},
rules: {
'import/no-extraneous-dependencies': ['error', {
devDependencies: ['**/*.test.js', 'scripts/**/*'],
}],
},
};
1 change: 1 addition & 0 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"devDependencies": {
"@dnd-academy/eslint-config": "*",
"@next/eslint-plugin-next": "14.2.15",
"@notionhq/client": "2.2.15",
"@testing-library/dom": "10.3.1",
"@testing-library/jest-dom": "6.4.6",
"@testing-library/react": "16.0.0",
Expand Down
46 changes: 46 additions & 0 deletions apps/admin/scripts/notion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Client } = require('@notionhq/client');

const notion = new Client({
auth: process.env.NOTION_API_KEY,
});

async function getNotionData() {
try {
const databaseId = process.env.NOTION_DATABASE_ID;

const response = await notion.databases.query({
database_id: databaseId,
filter: {
// property: 'Status',
// status: {
// equals: 'Published'
// }
},
});

const pages = response.results.map((page: any) => ({
id: page.id,
title: page.properties.Title?.title[0]?.plain_text || '',
tags: page.properties.Tags?.multi_select.map((tag: any) => tag.name) || [],
date: page.properties.Date?.date?.start || '',
}));

// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
const fs = require('fs');
fs.writeFileSync(
'notion-data.json',
JSON.stringify(pages, null, 2),
'utf-8',
);

return pages;
} catch (error) {
console.error('Error fetching Notion data:', error);
throw error;
}
}

getNotionData()
.then(() => console.log('Data successfully fetched and saved'))
.catch((error) => console.error('Failed to fetch data:', error));
3 changes: 2 additions & 1 deletion apps/admin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"../../jest.setup.ts"
"../../jest.setup.ts",
"scripts/**/*.ts",
],
}
23 changes: 22 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,16 @@ __metadata:
languageName: node
linkType: hard

"@notionhq/client@npm:2.2.15":
version: 2.2.15
resolution: "@notionhq/client@npm:2.2.15"
dependencies:
"@types/node-fetch": "npm:^2.5.10"
node-fetch: "npm:^2.6.1"
checksum: 10/18e8812f1630d7f6a93e058695101853b2db980b2003ca6b1e451c93bca330b8d1c1a7fe2c9769ac5a07ab36bdfe33d9458a244ecc3c171331153872384f0cae
languageName: node
linkType: hard

"@npmcli/agent@npm:^2.0.0":
version: 2.2.2
resolution: "@npmcli/agent@npm:2.2.2"
Expand Down Expand Up @@ -5182,6 +5192,16 @@ __metadata:
languageName: node
linkType: hard

"@types/node-fetch@npm:^2.5.10":
version: 2.6.12
resolution: "@types/node-fetch@npm:2.6.12"
dependencies:
"@types/node": "npm:*"
form-data: "npm:^4.0.0"
checksum: 10/8107c479da83a3114fcbfa882eba95ee5175cccb5e4dd53f737a96f2559ae6262f662176b8457c1656de09ec393cc7b20a266c077e4bfb21e929976e1cf4d0f9
languageName: node
linkType: hard

"@types/node@npm:*, @types/node@npm:^22.0.0":
version: 22.7.2
resolution: "@types/node@npm:22.7.2"
Expand Down Expand Up @@ -6161,6 +6181,7 @@ __metadata:
"@dnd-academy/eslint-config": "npm:*"
"@dnd-academy/ui": "npm:*"
"@next/eslint-plugin-next": "npm:14.2.15"
"@notionhq/client": "npm:2.2.15"
"@tanstack/react-query": "npm:5.52.0"
"@testing-library/dom": "npm:10.3.1"
"@testing-library/jest-dom": "npm:6.4.6"
Expand Down Expand Up @@ -14333,7 +14354,7 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:^2.6.7, node-fetch@npm:^2.6.9":
"node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7, node-fetch@npm:^2.6.9":
version: 2.7.0
resolution: "node-fetch@npm:2.7.0"
dependencies:
Expand Down

0 comments on commit 1541776

Please sign in to comment.