Skip to content

Instantly share code, notes, and snippets.

@gpirrotta
Last active October 16, 2022 05:49
Show Gist options
  • Save gpirrotta/707f02bbe7e36e8e7238071a039fb43e to your computer and use it in GitHub Desktop.
Save gpirrotta/707f02bbe7e36e8e7238071a039fb43e to your computer and use it in GitHub Desktop.
Git Diff Visualcad
import json
import csv
f = open('../data/data_cad.json')
rows = json.load(f)
previous_article = {}
with open('../data/gitdiff.csv', mode='w') as csv_file:
fieldnames = ['data', 'articolo', 'type','no','size_article']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
for row in rows:
source = row['source']
for article in row['articles']:
status = ''
id = article['id']
content = article['paragraphs'][0]['content']
size = article['paragraphs'][0]['content_length']
if id not in previous_article:
previous_article[id] = content
if 'status' in article:
status = article['status']
elif previous_article[id] != content:
status = 'updated' #Updated article
previous_article[id] = content
elif previous_article[id] == content:
status = 'same' #Same article - no updated
if source =='2005-03-07':
status='same'
writer.writerow({'data': source, 'articolo': id, 'type': status, 'no': article['no'],'size_article': size})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment