-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-notion-keys.sh
executable file
·68 lines (61 loc) · 2.34 KB
/
test-notion-keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /bin/bash
set -o pipefail
pushd $(dirname ${0}) > /dev/null
echo "fetches Notion data to the $(dirname ${0}) folder"
NOTION_IDS="NOTION_FINANCIAL_DATABASE_ID \
NOTION_WORKINGHOURS_DATABASE_ID \
NOTION_CREW_DATABASE_ID \
NOTION_ALLOCATIONS_DATABASE_ID"
for id in ${NOTION_IDS}; do
echo "#"
echo "Fetching ${id} data"
curl -s -X POST 'https://api.notion.com/v1/databases/'"$(eval echo \$${id})"'/query' \
-H 'Authorization: Bearer '"$NOTION_KEY"'' \
-H "Notion-Version: 2022-06-28" | jq . > ./${id}.json
head ./${id}.json
case $id in
*_FINANCIAL_*)
echo "Reading finance data"
cat ${id}.json | jq '
.results[].properties.Month.title[0].plain_text,
.results[].properties."external-cost".formula.number,
.results[].properties."real-income".formula.number,
.results[].properties."SEK start".number,
.results[].properties."EUR start".number,
.results[].properties."AB-Cost".number,
.results[].properties."OY-Cost".number
' > ${id}.txt
;;
*_WORKINGHOURS_*)
echo "Reading workinghours data"
cat ${id}.json | jq '
.results[].properties.User.title[0].plain_text,
.results[].properties.Daily.number,
.results[].properties.Delta.number,
.results[].properties.Start.rich_text[0].plain_text,
.results[].properties.Stop.rich_text[0].plain_text
' > ${id}.txt
;;
*_CREW_*)
echo "Reading crew data"
cat ${id}.json | jq '
.results[].properties.Person.people[0].name,
.results[].properties.Role.select.name,
.results[].properties.Currency.select.name,
.results[].properties."Total Cost".number,
.results[].properties."Consulting Hours".number
' > ./${id}.txt
;;
*_ALLOCATIONS_*)
echo "Reading allocations data"
cat ${id}.json | jq -r '
.results[].properties.Assign.people[].name
' > ./${id}.txt
;;
*)
echo -n "Error unknown database id"
exit 1
;;
esac
done
popd > /dev/null