-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadOldContacts.js
More file actions
60 lines (55 loc) · 1.71 KB
/
Copy pathuploadOldContacts.js
File metadata and controls
60 lines (55 loc) · 1.71 KB
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
const keys = require('./private/api-keys.json')
const admin = require("firebase-admin");
const fetch = require('node-fetch');
const fs = require('fs')
const moment = require('moment')
const endPoint = 'https://api.sendgrid.com/v3/contactdb/recipients'
let requestBody = []
let emails = []
function Person(input) {
this.email = input.email
this.name = input.name
this.referrer = 'hyphen-hacks_2018'
this.interests = `${input.role}, returning`
this.years_involved = '2018'
this.role = input.role
}
admin.initializeApp({
credential: admin.credential.cert(keys.firebaseOld),
databaseURL: "https://hyphenhacks-dc851.firebaseio.com"
});
const db = admin.database();
const ref = db.ref('/attendeeDB/people')
ref.once('value', (snap) => {
const data = snap.val()
fs.writeFile('./private/oldDB.json', JSON.stringify(data), (e) => {
console.log(e)
});
for (let property in data) {
if (data.hasOwnProperty(property)) {
const person = data[property]
const cleanedPerson = new Person(person)
if (emails.indexOf(cleanedPerson.email) > 0) {
console.log('email dup', cleanedPerson.email)
} else {
requestBody.push(cleanedPerson)
}
emails.push(cleanedPerson.email)
//console.log(cleanedPerson)
}
}
})
console.log('Cleaned:', requestBody.length, 'people');
// fs.writeFile('./private/emailsUpload.json', JSON.stringify(requestBody), (e)=> {console.log(e)});
/*
fetch(endPoint, {
method: 'post',
headers: {
Authorization: 'Bearer ' + keys.sendGrid
},
body: JSON.stringify(requestBody)
}).then(e => e.json()).then(e => {
console.log(e)
fs.writeFile('./private/emailsError.json', JSON.stringify(e), err => {console.log(err)})
})
})*/