Add diff script
authorEthan Nelson <git@ethan-nelson.com>
Fri, 15 Dec 2017 19:30:34 +0000 (13:30 -0600)
committerEthan Nelson <git@ethan-nelson.com>
Fri, 15 Dec 2017 19:31:29 +0000 (13:31 -0600)
gen_diffs.py [new file with mode: 0644]

diff --git a/gen_diffs.py b/gen_diffs.py
new file mode 100644 (file)
index 0000000..58e16f6
--- /dev/null
@@ -0,0 +1,73 @@
+import json
+import glob
+
+files = glob.glob('_data/*.json')
+
+for f in files:
+    file1 = json.load(open(f,'r'))
+    tracks1 = sorted([x['track']['name'] for x in file1['items']])
+    for g in files:
+        file2 = json.load(open(g,'r'))
+        tracks2 = sorted([x['track']['name'] for x in file2['items']])
+
+        col1 = []
+        col2 = []
+        c = 0
+        d = 0
+        for x in range(len(tracks1)):
+            if (d >= len(tracks1)):
+                col1.append('')
+                col2.append(tracks2[c])
+            elif (c >= len(tracks2)):
+                col1.append(tracks1[d])
+                col2.append('')
+            elif tracks1[d] == tracks2[c]:
+                col1.append(tracks1[d])
+                col2.append(tracks2[c])
+            else:
+                if tracks1[d] == tracks2[c+1]:
+                    col1.append('')
+                    col2.append(tracks2[c])
+                    d -= 1
+                elif tracks1[d+1] == tracks2[c]:
+                    col1.append(tracks1[d])
+                    col2.append('')
+                    c -= 1
+            c += 1
+            d += 1
+
+        gone = []
+        added = []
+
+        for x in tracks1:
+            if x not in tracks2:
+                gone.append(x)
+        for x in tracks2:
+            if x not in tracks1:
+                added.append(x)
+
+        outer = open('diff/'+f[-15:-5]+'_'+g[-15:-5]+'.md','w')
+        outer.write('---\n')
+        outer.write('layout: default\n')
+        outer.write('---\n\n')
+        outer.write('[<- Back home](/)\n\n')
+        outer.write('## Diff for '+f[-15:-5]+' and '+g[-15:-5]+'\n\n')
+        outer.write('Removed | Added\n')
+        outer.write('-----|-----\n')
+        if len(gone) > len(added):
+            for x in range((len(gone) - len(added))):
+                added.append('') 
+        elif len(added) > len(gone):
+            for x in range((len(added) - len(gone))):
+                gone.append('')
+        for x in range(len(gone)):
+            outer.write(gone[x].encode('utf-8')+' | '+added[x].encode('utf-8')+'\n')
+        if f == g:
+            outer.write('    |    \n')
+        """
+        outer.write(f[-15:-5]+'|'+g[-15:-5]+'\n')
+        outer.write('-----|-----\n')
+        for x in range(len(col1)):
+            outer.write(col1[x].encode('utf-8')+'|'+col2[x].encode('utf-8')+'\n')
+        """
+        outer.close()