You'd have to do the formatting yourself. Instead of a dictionary, build a string:
d['Links'] = ', '.join(['{}: {}'.format(*item) for item in links.items()])
d['Sources'] = ', '.join(['{}: {}'.format(*item) for item in sources.items()])
This produces link1: count1, link2: count2
results.
As a sidenote, you don't need to use an OrderedDict
object here, just give the DictWriter
a sequence of keys in the order you want them written instead. I'd also open the CSV file just once outside the loop:
d = {
'Title': website,
'Date': date,
'Visitors': visitors,
'Links': ', '.join(['{}: {}'.format(*item) for item in links.items()]),
'Sources': ', '.join(['{}: {}'.format(*item) for item in sources.items()],
}
path = os.path.expanduser('~/Desktop/Traffic Report.csv')
with open(path, 'a') as f:
fields = ('Title', 'Date', 'Visitors', 'Links', 'Sources')
writer = csv.DictWriter(f, fields, delimiter=',')
writer.writerow(d)