From f763b8744625d29371094bc430191c94c2612141 Mon Sep 17 00:00:00 2001 From: jacobhartmann Date: Thu, 19 Jul 2018 22:45:38 +0200 Subject: [PATCH] donish --- sync.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/sync.py b/sync.py index 0acfd46..cbac440 100644 --- a/sync.py +++ b/sync.py @@ -98,9 +98,9 @@ def write_hubspot_csv(): else: exceed = 'false' - # It doesn't really make sense to write last sync, without also saving the date of this sync - # because if we then sync again next month, then we get the second to last sync, since we - # didn't store today's sync. + # It doesn't really make sense to write last sync, without also saving the date of this sync + # because if we then sync again next month, then we get the second to last sync, since we + # didn't store today's sync. lastSyncDate = getLastSyncDate(oldSyncData, email) totalFlipbookVisitors = i['FlipbookSession'] @@ -110,15 +110,59 @@ def write_hubspot_csv(): filewriter.writerow([email,ownerId,licenseName,status,flipbooks,limit,exceed, totalFlipbookVisitors, lastSyncDate, lastSeen]) +### write intercom +def write_intercom(): + with open("newestIntercomSyncro.csv", "w") as csvfile: + + filewriter = csv.writer(csvfile, delimiter=";",quotechar="|",quoting=csv.QUOTE_MINIMAL) + filewriter.writerow([ + 'email', + 'lastWebVisit' + 'LicenseName', + 'LicenseStatus', + 'HubSpotOwner' + 'FlipBooksUsed', + 'FlipbookLimit', + 'FlipbookAvailable', + 'LastSyncDate' + ]) + + intercomUsers = list(IntercomUsers.items())[0][1] + + for key, value in iPaperUsers.items(): + for i in value: + + email = i["email"] + ownerId=getOwnerIdForeignKey(hubSpotUsers, email) + + licenseName = i['LicenseName'] + + # not gonna get around to this, but the idea is to get the foreign id in hubspot users, and then get the matching consultant name in hubspotowners + HubSpotOwner = '...' + + status = i['Status'] + used = i['Flipbooks'] + limit = i['FlipbookLimit'] + available = limit - used + lastWebVisit = getLastWebVisit(intercomUsers, email) + + lastSyncDate = getLastSyncDate(oldSyncData, email) + + #lastWebVisit + + filewriter.writerow([email,licenseName,HubSpotOwner,status, used, limit, available, lastSyncDate, lastWebVisit]) + + + + + + def getLastSyncDate(users, email): for v in users: - print('somthinw') if v['Email'] == email: if not v['LastSync']: - print('hello') return datetime.date.today().strftime("%d-%m-%Y %H:%M:%S") else: - print('nay') return v['LastSync'] def getLastSeen (users, email, date):