1
+ require ( 'dotenv' ) . config ( )
2
+ let fetch = require ( 'node-fetch' )
3
+ let fs = require ( 'fs' )
4
+ let slugify = require ( 'slugify' )
5
+
6
+ let appId = process . env . AIRTABLE_APP_ID
7
+ let appKey = process . env . AIRTABLE_APP_KEY
8
+ let speakerViewId = process . env . AIRTABLE_SPEAKER_VIEW
9
+ let baseUrl = `https://api.airtable.com/v0/${ appId } `
10
+
11
+ async function fetchTopics ( ) {
12
+ let fields = [ 'Name' ]
13
+ let json = await fetch ( `${ baseUrl } /Topics?view=Grid%20view${ fields . map ( ( f ) => '&fields%5B%5D=' + encodeURIComponent ( f ) ) . join ( '' ) } ` , { headers : { 'Authorization' : `Bearer ${ appKey } ` } } )
14
+ let results = await json . json ( )
15
+ return results . records . map ( ( r ) => ( { id : r . id , name : r . fields . Name } ) )
16
+ }
17
+
18
+ async function fetchSpeakers ( { topics } ) {
19
+ let fields = [ 'Name' , 'Location' , 'Talk Title' , 'Abstract' , 'Reveal' , 'Pixelated' , 'Topic(s)' , 'Pronouns' , 'Twitter' , 'Website' , 'Company' ]
20
+ let json = await fetch ( `${ baseUrl } /Speakers?view=${ speakerViewId } ${ fields . map ( ( f ) => '&fields%5B%5D=' + encodeURIComponent ( f ) ) . join ( '' ) } ` , { headers : { 'Authorization' : `Bearer ${ appKey } ` } } )
21
+ let results = await json . json ( )
22
+ let members = results . records . map ( ( r ) => { return {
23
+ table : 'speakers' ,
24
+ key : slugify ( r . fields [ 'Name' ] , { lower : true } ) ,
25
+ name : r . fields [ 'Name' ] ,
26
+ location : r . fields [ 'Location' ] ,
27
+ title : r . fields [ 'Talk Title' ] ,
28
+ abstract : r . fields [ 'Abstract' ] ,
29
+ reveal : r . fields [ 'Reveal' ] ,
30
+ pixelated : r . fields [ 'Pixelated' ] ,
31
+ topics : r . fields [ 'Topic(s)' ]
32
+ . map ( ( id ) => topics . find ( ( t ) => t . id === id ) ) // grab the skill objects that match the ids
33
+ . map ( ( t ) => t . name ) , // grab the Name
34
+ pronouns : r . fields [ 'Pronouns' ] ,
35
+ twitter : r . fields [ 'Twitter' ] ,
36
+ website : r . fields [ 'Website' ] ,
37
+ company : r . fields [ 'Company' ]
38
+ } } )
39
+ return members
40
+ }
41
+
42
+ async function init ( ) {
43
+ // get speakers from Airtable
44
+ let topics = await fetchTopics ( )
45
+ let speakers = await fetchSpeakers ( { topics } )
46
+ console . log ( `Writing ${ speakers . length } speakers to data/staging/speakers.json` )
47
+ // write these bits to JSON
48
+ fs . writeFileSync ( './data/staging/speakers.json' , JSON . stringify ( speakers ) )
49
+ }
50
+
51
+ init ( )
0 commit comments