Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
acnh
acnh-google-sheet-importer
Commits
e98d4c1c
Commit
e98d4c1c
authored
Apr 28, 2021
by
Iliak
Browse files
update code
parent
d47be471
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
e98d4c1c
...
...
@@ -3,6 +3,8 @@
This repository contains the code used to convert the Animal Crossing: New Horizons community items
google
[
spreadsheet
](
https://docs.google.com/spreadsheets/d/13d_LAJPlxMa_DubPTuirkIV4DERBMXbrWQsmSh8ReK4/edit?usp=sharing
)
into JSON.
https://github.com/acdb-team/google-sheets-to-json
# Setup
-
Visit
[
Google Sheets API Quickstart
](
https://developers.google.com/sheets/api/quickstart/nodejs
)
...
...
index.ts
View file @
e98d4c1c
...
...
@@ -5,6 +5,10 @@ import {google} from 'googleapis';
import
{
OAuth2Client
}
from
'
google-auth-library
'
;
import
{
main
}
from
'
./src
'
;
// View-only "main" link to the spreadsheet: https://docs.google.com/spreadsheets/d/13d_LAJPlxMa_DubPTuirkIV4DERBMXbrWQsmSh8ReK4/edit?usp=sharing
// Editors' copy: https://docs.google.com/spreadsheets/d/1mo7myqHry5r_TKvakvIhHbcEAEQpSiNoNQoIS8sMpvM/edit?usp=sharing
interface
Credentials
{
installed
:
{
token_uri
:
string
;
...
...
src/index.ts
View file @
e98d4c1c
...
...
@@ -14,12 +14,12 @@ const SHEET_ID = '1mo7myqHry5r_TKvakvIhHbcEAEQpSiNoNQoIS8sMpvM';
const
OUTPUT
=
'
out
'
;
const
ITEM_SHEETS
=
[
'
Accessories
'
,
'
Art
'
,
'
Bags
'
,
'
Bottoms
'
,
'
Clothing Other
'
,
'
Dress-Up
'
,
'
Equipment
'
,
'
Fencing
'
,
'
Floors
'
,
'
Fossils
'
,
...
...
@@ -77,21 +77,18 @@ export async function main(auth: OAuth2Client) {
const
workSet
:
Array
<
[
string
,
string
[]]
>
=
[
[
'
items
'
,
ITEM_SHEETS
],
[
'
events
'
,
EVENT_SHEETS
],
[
'
creatures
'
,
CREATURE_SHEETS
],
[
'
recipes
'
,
RECIPE_SHEETS
],
[
'
villagers
'
,
VILLAGERS_SHEETS
],
[
'
construction
'
,
CONSTRUCTION_SHEETS
],
[
'
achievements
'
,
ACHIEVEMENTS_SHEETS
],
[
'
reactions
'
,
REACTIONS_SHEETS
],
[
'
events
'
,
EVENT_SHEETS
],
[
'
npc
'
,
NPC_SHEETS
],
[
'
cards
'
,
CARDS_SHEETS
],
[
'
music
'
,
MUSIC_SHEETS
],
];
const
ids
=
new
Set
();
const
duplicates
=
new
Set
();
for
(
const
[
key
,
sheetNames
]
of
workSet
)
{
console
.
log
(
`Loading
${
key
}
`
);
...
...
@@ -100,43 +97,25 @@ export async function main(auth: OAuth2Client) {
console
.
log
(
`Normalising data`
);
data
=
await
normalizeData
(
data
,
key
);
if
(
validateIds
)
{
for
(
const
item
of
data
)
{
if
(
ids
.
has
(
item
[
'
uniqueEntryId
'
]))
{
duplicates
.
add
(
item
[
'
uniqueEntryId
'
]);
}
ids
.
add
(
item
[
'
uniqueEntryId
'
]);
}
}
else
{
if
(
key
===
'
items
'
)
{
data
=
await
mergeItemVariations
(
data
);
}
if
(
key
===
'
items
'
)
{
data
=
await
mergeItemVariations
(
data
);
}
console
.
log
(
`Writing data to disk`
);
writeJSON
(
`
${
OUTPUT
}
/
${
key
}
.json`
,
data
);
console
.
log
(
`Writing data to disk`
);
writeJSON
(
`
${
OUTPUT
}
/
${
key
}
.json`
,
data
);
console
.
log
(
`Finished
${
key
}
`
);
}
console
.
log
(
`Finished
${
key
}
`
);
}
const
all
=
[];
for
(
const
[
key
]
of
workSet
)
{
// if (key === 'achievements' || key === 'reactions') {
// continue;
// }
const
data
=
readJSON
(
`
${
OUTPUT
}
/
${
key
}
.json`
);
all
.
push
(...
data
);
}
writeJSON
(
`
${
OUTPUT
}
/all.json`
,
all
);
if
(
validateIds
)
{
console
.
log
(
duplicates
);
}
}
export
async
function
loadData
(
...
...
@@ -146,25 +125,30 @@ export async function loadData(
)
{
const
cacheFile
=
`cache/
${
key
}
.json`
;
try
{
const
file
=
fs
.
readFileSync
(
cacheFile
);
return
JSON
.
parse
(
file
.
toString
());
}
catch
(
e
)
{}
// ignored
// try {
// const file = fs.readFileSync(cacheFile);
//
// return JSON.parse(file.toString());
// } catch (e) {
// } // ignored
let
data
:
ItemData
=
[];
for
(
const
sheetName
of
sheetNames
)
{
const
response
=
await
sheets
.
spreadsheets
.
values
.
get
({
spreadsheetId
:
SHEET_ID
,
range
:
sheetName
,
valueRenderOption
:
'
FORMULA
'
,
});
try
{
const
response
=
await
sheets
.
spreadsheets
.
values
.
get
({
spreadsheetId
:
SHEET_ID
,
range
:
sheetName
,
valueRenderOption
:
'
FORMULA
'
,
});
const
[
header
,
...
rows
]
=
response
.
data
.
values
!
;
const
[
header
,
...
rows
]
=
response
.
data
.
values
!
;
for
(
const
row
of
rows
)
{
data
.
push
({
SourceSheet
:
sheetName
,
...
zipObject
(
header
,
row
)});
for
(
const
row
of
rows
)
{
data
.
push
({
SourceSheet
:
sheetName
,
...
zipObject
(
header
,
row
)});
}
}
catch
(
e
)
{
console
.
error
(
e
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment