-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from MichiganDaily/staging
Staging
- Loading branch information
Showing
10 changed files
with
248 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
{ | ||
"fetch": [ | ||
{ | ||
"type": "doc", | ||
"id": "", | ||
"output": "", | ||
"auth": "~/.daily-google-services.json" | ||
}, | ||
{ | ||
"type": "sheet", | ||
"id": "", | ||
"sheetId": "0", | ||
"output": "", | ||
"auth": "~/.daily-google-services.json" | ||
}, | ||
{ | ||
"type": "json", | ||
"id": "", | ||
"output": "", | ||
"auth": "~/.daily-google-services.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import { existsSync, mkdirSync, writeFileSync } from "node:fs"; | ||
|
||
import { program } from "commander"; | ||
import { drive } from "@googleapis/drive"; | ||
|
||
import { load_config, success, get_auth } from "./_utils.js"; | ||
|
||
export const fetchJson = async ({ id, output, auth }) => { | ||
const scopes = ["https://www.googleapis.com/auth/drive"]; | ||
const authObject = get_auth(auth, scopes); | ||
|
||
const gdrive = drive({ version: "v3", auth: authObject }); | ||
|
||
const { data } = await gdrive.files.get({ fileId: id, alt: "media" }); | ||
|
||
const dir = output.substring(0, output.lastIndexOf("/")); | ||
!existsSync(dir.length > 0 ? dir : ".") && | ||
mkdirSync(dir, { recursive: true }); | ||
writeFileSync(output, JSON.stringify(data)); | ||
success(`Wrote output to ${output}`); | ||
}; | ||
|
||
const main = async (opts) => { | ||
const { config } = await load_config(opts.config); | ||
const files = config.fetch.filter( | ||
(d) => d.type === "json" && d.id.length && d.output.length | ||
); | ||
files.forEach(fetchJson); | ||
}; | ||
|
||
const self = fileURLToPath(import.meta.url); | ||
if (process.argv[1] === self) { | ||
program | ||
.version("1.3.0") | ||
.option("-c, --config <path>", "path to config file") | ||
.parse(); | ||
|
||
main(program.opts()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from "commander/esm.mjs"; | ||
import { program } from "commander"; | ||
|
||
program | ||
.version("1.3.0") | ||
.name("sink") | ||
.description("Utility scripts") | ||
.command("gdoc", "fetch ArchieML Google Doc into JSON file") | ||
.command("gsheet", "fetch Google Sheet into CSV file") | ||
.command("json", "fetch JSON files from Google Drive") | ||
.command("fetch", "fetch all Google Docs and Sheets"); | ||
|
||
program.parse(process.argv); |
Oops, something went wrong.