Update ZP -> Close lead importing to only query for last 30 days

This commit is contained in:
Matt Lott 2016-08-16 05:27:56 -07:00
parent b471b909c5
commit 7cd49b438b

View file

@ -6,6 +6,10 @@ if (process.argv.length !== 4) {
process.exit();
}
// NOTE: last_activity_date_range is the contacted at date, UTC
// TODO: Only looking at contacts created in last 30 days. How do we catch replies for contacts older than 30 days?
const closeIoApiKey = process.argv[2];
const zpAuthToken = process.argv[3];
@ -15,6 +19,9 @@ const async = require('async');
const request = require('request');
const zpPageSize = 100;
let zpMinActivityDate = new Date();
zpMinActivityDate.setUTCDate(zpMinActivityDate.getUTCDate() - 30);
zpMinActivityDate = zpMinActivityDate.toISOString().substring(0, 10);
getZPContacts((err, emailContactMap) => {
if (err) {
@ -39,7 +46,6 @@ function createCloseLead(zpContact, done) {
contacts: [
{
name: zpContact.name,
title: zpContact.title,
emails: [{email: zpContact.email}]
}
],
@ -51,6 +57,9 @@ function createCloseLead(zpContact, done) {
if (zpContact.phone) {
postData.contacts[0].phones = [{phone: zpContact.phone}];
}
if (zpContact.title) {
postData.contacts[0].title = zpContact.title;
}
if (zpContact.district) {
postData.custom['demo_nces_district'] = zpContact.district;
postData.custom['demo_nces_name'] = zpContact.organization;
@ -189,7 +198,7 @@ function getZPContactsPage(contacts, searchQuery, done) {
function createGetZPAutoResponderContactsPage(contacts, page) {
return (done) => {
// console.log(`DEBUG: Fetching autoresponder page ${page} ${zpPageSize}...`);
let searchQuery = `codecombat_special_auth_token=${zpAuthToken}&page=${page}&per_page=${zpPageSize}&contact_email_autoresponder=true`;
let searchQuery = `codecombat_special_auth_token=${zpAuthToken}&page=${page}&per_page=${zpPageSize}&last_activity_date_range[min]=${zpMinActivityDate}&contact_email_autoresponder=true`;
getZPContactsPage(contacts, searchQuery, done);
};
}
@ -197,7 +206,7 @@ function createGetZPAutoResponderContactsPage(contacts, page) {
function createGetZPRepliedContactsPage(contacts, page) {
return (done) => {
// console.log(`DEBUG: Fetching email reply page ${page} ${zpPageSize}...`);
let searchQuery = `codecombat_special_auth_token=${zpAuthToken}&page=${page}&per_page=${zpPageSize}&contact_email_replied=true`;
let searchQuery = `codecombat_special_auth_token=${zpAuthToken}&page=${page}&per_page=${zpPageSize}&last_activity_date_range[min]=${zpMinActivityDate}&contact_email_replied=true`;
getZPContactsPage(contacts, searchQuery, done);
};
}
@ -222,7 +231,7 @@ function getZPContacts(done) {
if (err) return done(err);
const emailContactMap = {};
for (const contact of contacts) {
if (!contact.organization || !contact.name || !contact.title || !contact.email) {
if (!contact.organization || !contact.name || !contact.email) {
console.log(JSON.stringify(contact, null, 2));
return done(`DEBUG: missing data for zp contact:`);
}