2018-12-20 01:17:38 +03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from cleanup import CleanerAgent
|
2019-03-10 22:05:38 +03:00
|
|
|
from utilities import log
|
|
|
|
import difflib
|
2018-12-20 01:17:38 +03:00
|
|
|
|
|
|
|
wendigo = CleanerAgent()
|
|
|
|
|
|
|
|
exp = r"([0-9]*)(\t+)([^\t]+?)(\t+)([^\t]+)(\t*)([^\t]*)\n"
|
|
|
|
|
|
|
|
for fn in os.listdir("scrobbles/"):
|
|
|
|
if fn.endswith(".tsv"):
|
|
|
|
f = open("scrobbles/" + fn)
|
|
|
|
fnew = open("scrobbles/" + fn + "_new","w")
|
|
|
|
for l in f:
|
|
|
|
|
|
|
|
a,t = re.sub(exp,r"\3",l), re.sub(exp,r"\5",l)
|
|
|
|
r1,r2,r3 = re.sub(exp,r"\1\2",l),re.sub(exp,r"\4",l),re.sub(exp,r"\6\7",l)
|
|
|
|
|
|
|
|
a = a.replace("␟",";")
|
|
|
|
|
|
|
|
(al,t) = wendigo.fullclean(a,t)
|
|
|
|
a = "␟".join(al)
|
|
|
|
fnew.write(r1 + a + r2 + t + r3 + "\n")
|
2019-03-10 22:05:38 +03:00
|
|
|
|
2018-12-20 01:17:38 +03:00
|
|
|
#print("Artists: " + a)
|
|
|
|
#print("Title: " + t)
|
|
|
|
#print("1: " + r1)
|
|
|
|
#print("2: " + r2)
|
|
|
|
#print("3: " + r3)
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
fnew.close()
|
|
|
|
|
2019-03-10 22:05:38 +03:00
|
|
|
#os.system("diff " + "scrobbles/" + fn + "_new" + " " + "scrobbles/" + fn)
|
|
|
|
with open("scrobbles/" + fn + "_new","r") as newfile:
|
|
|
|
with open("scrobbles/" + fn,"r") as oldfile:
|
|
|
|
diff = difflib.unified_diff(oldfile.read().split("\n"),newfile.read().split("\n"),lineterm="")
|
|
|
|
diff = list(diff)[2:]
|
|
|
|
log("Diff for scrobbles/" + fn + "".join("\n\t" + d for d in diff),module="fixer")
|
2018-12-21 21:13:24 +03:00
|
|
|
|
2018-12-20 01:17:38 +03:00
|
|
|
os.rename("scrobbles/" + fn + "_new","scrobbles/" + fn)
|
2018-12-20 20:46:55 +03:00
|
|
|
|
|
|
|
checkfile = open("scrobbles/" + fn + ".rulestate","w")
|
|
|
|
checkfile.write(wendigo.checksums)
|
|
|
|
checkfile.close()
|