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):