Skip to content

Instantly share code, notes, and snippets.

@jeremiahmarks
Last active April 4, 2016 15:53
Show Gist options
  • Save jeremiahmarks/2a3b235affcf16857d33bbfe6655d87c to your computer and use it in GitHub Desktop.
Save jeremiahmarks/2a3b235affcf16857d33bbfe6655d87c to your computer and use it in GitHub Desktop.
fixes tag id spacing in Contact Export files from Infusionsoft
# -*- coding: utf-8 -*-
# @Author: jeremiah.marks
# @Date: 2016-03-30 10:40:17
# @Last Modified by: Jeremiah Marks
# @Last Modified time: 2016-03-30 11:06:29
import csv
import os
import Tkinter as tk
import tkFileDialog
tk.Tk().withdraw()
def getFilePath():
return tkFileDialog.askopenfilename()
def main():
filepath = getFilePath()
fileelements = os.path.split(filepath)
newfilename = ''.join(fileelements[1].split('.')[:-1])+"_modded."+fileelements[1].split('.')[-1]
oldfile=[]
with open(filepath, 'r') as infile:
thisreader=csv.DictReader(infile)
colnames = list(thisreader.fieldnames)
with open(os.path.join(fileelements[0], newfilename), 'wb') as outfile:
thiswriter = csv.DictWriter(outfile, colnames)
thiswriter.writeheader()
for eachrow in thisreader:
thisrow = dict(eachrow)
thisrow['Tag Ids'] = ', '.join(thisrow['Tag Ids'].split(','))
thiswriter.writerow(thisrow)
if __name__ == '__main__':
main()
@LoriRuffin
Copy link

Hi, I'm trying to use this work around and I'm getting an error message when I add the code to the Anaconda command prompt. What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment