import csv HubSpotOwners = { "owner": [] } HubSpotUsers = { "user": [] } iPaperUsers = { "user": [] } # read in data, built data structures def fill_iPaperUsers(email, license, status, lastlogin, flipbooks, limit, session): user = {} user["email"] = email user["LicenseName"] = license user["Status"] = status user["LastLoginDate"] = lastlogin user["Flipbooks"] = flipbooks user["FlipbookLimit"] = limit user["FlipbookSession"] = session add_iPaperUser(user) def add_iPaperUser(user): iPaperUsers["user"].append(user) def fill_hubSpotOwners(ownerId, name): owner = {} owner["OwnerId"] = ownerId owner["name"] = name add_hubSpotOwner(owner) def add_hubspotOwner(owner): HubSpotOwners["owner"].append(owner) def fill_hubSpotUsers(email, ownerId): user = {} user["Email"] = email user["OwnerId"] = ownerId add_hubSpotUser(user) def add_hubSpotUser(user): HubSpotUsers["user"].append(user) def fill_hubSpotUsers(email, ownerId): user = {} user["Email"] = email user["OwnerId"] = ownerId add_hubSpotUser(user) def add_hubSpotUser(user): HubSpotUsers["user"].append(user) ### write hubspot def write_hubspot_csv(): with open("test.csv", "w") as csvfile: filewriter = csv.writer(csvfile, delimiter=";",quotechar="|",quoting=csv.QUOTE_MINIMAL) filewriter.writerow([ 'email', 'OwnerId', 'LicenseName', 'LicenseStatus', 'FlipBooks', 'FlipbookLimit', 'Exceed', 'TotalFlipbookVisitors', 'LastSyncDate', 'LastSeen']) for key, value in iPaperUsers.items(): for i in value: email = i["email"] ownerId='' for key, value in HubSpotUsers.items(): for j in value: if j['Email'] == email: ownerId = j['OwnerId'] licenseName = i['LicenseName'] status = i['Status'] flipbooks = i['Flipbooks'] limit = i['FlipbookLimit'] filewriter.writerow([email,ownerId,licenseName,status,flipbooks,limit, #i['...'], #i['...'], #i['...'], i['LastLoginDate'] ]) def read_iPaper(): with open("iPaperUsers.csv", "r") as fw: reader = csv.reader(fw, delimiter=";") rowNr = 0 for row in reader: if rowNr >= 0: fill_iPaperUsers(row[0],row[1],row[2],row[3],row[4],row[5],row[6]) rowNr += 1 def read_hubSpotOwner(): with open("HubSpotOwners.csv", "r") as fw: reader = csv.reader(fw, delimiter=";") rowNr = 0 for row in reader: if rowNr >= 0: fill_hubSpotOwners(row[0],row[1]) rowNr += 1 def read_hubSpotUser(): with open("HubSpotUsers.csv", "r") as fw: reader = csv.reader(fw, delimiter=";") rowNr = 0 for row in reader: if rowNr >= 0: fill_hubSpotUsers(row[0],row[1]) rowNr += 1 def init(): read_hubSpotUser() read_iPaper() write_hubspot_csv() init()