@@ -4,34 +4,38 @@ import { parse } from "csv-parse/sync";
4
4
5
5
/*
6
6
* Report generation options:
7
- * reportTitle (string): The title of this report.
8
- * reportQuestion (string): The overall topic of this report's content
9
- * googleSheetUrl (string): full URL for a Google Sheets spreadsheet. The data
7
+ * title (string): The title of this report.
8
+ * question (string): The overall topic of this report's content
9
+ * googleSheet:
10
+ * - url (string): full URL for a Google Sheets spreadsheet. The data
10
11
* to analyze must be in the first tab of this sheet.
11
- * pieChartColumns (string|null): a list of column names in the spreadsheet to
12
+ * - pieChartColumns (string|null): a list of column names in the spreadsheet to
12
13
* treat as quantitative data, displayed as pie charts at the beginning of
13
14
* the report. Values must match the spreadsheet column names exactly.
14
- * whitelistCSV (string |null): the name of a CSV in the current directory listing
15
- * email addresses to include responses from, if desired.
15
+ * - filterEmails (array of strings |null): list of email addresses to whitelist
16
+ * (we'll loading these from a CSV in this example)
16
17
*
17
18
* Note: in any single column, all cells must have the same data type (string or
18
19
* number format) for the Google Sheets API to fetch them as displayed.
19
20
*
20
21
* Run this script with `node googlesheet-with-config.mjs`.
21
22
*/
23
+
22
24
const CONFIG = {
23
- reportTitle : "Talk to the City [synethic survey]" ,
24
- reportQuestion : "What are your impressions of Talk to the City?" ,
25
- googleSheetUrl : "https://docs.google.com/spreadsheets/d/1pQjnqA4Ul07JCRDr0UMuOP26z3QD0RfigTa6zuOUBmw/edit#gid=0" ,
26
- pieChartColumns : [
27
- "Would you use the tool described in the article? (1 = Very unlikely to use; 5 = Very likely to use)" ,
28
- "How helpful would you expect this tool to be for your work? (1 = Not helpful; 5 = Very helpful)"
29
- ] ,
30
- whitelistCSV : "example-email-whitelist.csv"
25
+ apiKey : process . env . OPENAI_API_KEY ,
26
+ title : "Talk to the City [synthetic survey]" ,
27
+ question : "What are your impressions of Talk to the City?" ,
28
+ googleSheet : {
29
+ url : "https://docs.google.com/spreadsheets/d/1pQjnqA4Ul07JCRDr0UMuOP26z3QD0RfigTa6zuOUBmw/edit#gid=0" ,
30
+ pieChartColumns : [
31
+ "Would you use the tool described in the article? (1 = Very unlikely to use; 5 = Very likely to use)" ,
32
+ "How helpful would you expect this tool to be for your work? (1 = Not helpful; 5 = Very helpful)"
33
+ ] ,
34
+ filterEmails : getWhiteListFromCSV ( "example-email-whitelist.csv" ) ,
35
+ }
31
36
}
32
37
33
-
34
- function unpackCSV ( filename ) {
38
+ function getWhiteListFromCSV ( filename ) {
35
39
const content = fs . readFileSync ( filename ) ;
36
40
let records = parse ( content , {
37
41
columns : false ,
@@ -43,27 +47,12 @@ function unpackCSV(filename) {
43
47
}
44
48
45
49
async function main ( ) {
46
- let whitelist = null ;
47
- if ( CONFIG . whitelistCSV ) {
48
- whitelist = unpackCSV ( CONFIG . whitelistCSV ) ;
49
- console . log ( 'Including only responses from emails in ' + CONFIG . whitelistCSV ) ;
50
- }
51
-
52
50
const res = await fetch ( "http://localhost:8080/generate" , {
53
51
method : "POST" ,
54
52
headers : {
55
53
"Content-Type" : "application/json" ,
56
54
} ,
57
- body : JSON . stringify ( {
58
- apiKey : process . env . OPENAI_API_KEY ,
59
- googleSheet : {
60
- url : CONFIG . googleSheetUrl ,
61
- pieChartColumns : CONFIG . pieChartColumns ,
62
- filterEmails : CONFIG . emailwhitelist
63
- } ,
64
- title : CONFIG . reportTitle ,
65
- question : CONFIG . reportQuestion
66
- } ) ,
55
+ body : JSON . stringify ( CONFIG ) ,
67
56
} ) ;
68
57
const resData = await res . json ( ) ;
69
58
console . log ( "The report will be generated at: " , resData . url ) ;
0 commit comments