def sync(): # all entries by file collected # so we don't open the same file for every entry entries = {} for idx in range(len(SCROBBLES)): if not SCROBBLES[idx][2]: t = get_scrobble_dict(SCROBBLES[idx]) artistlist = list(t["artists"]) artistlist.sort( ) #we want the order of artists to be deterministic so when we update files with new rules a diff can see what has actually been changed artistss = "␟".join(artistlist) timestamp = datetime.date.fromtimestamp(t["time"]) entry = [str(t["time"]), artistss, t["title"]] monthcode = str(timestamp.year) + "_" + str(timestamp.month) entries.setdefault(monthcode, []).append( entry) #i feckin love the setdefault function SCROBBLES[idx] = (SCROBBLES[idx][0], SCROBBLES[idx][1], True) for e in entries: tsv.add_entries("scrobbles/" + e + ".tsv", entries[e], comments=False) #addEntries("scrobbles/" + e + ".tsv",entries[e],escape=False) combineChecksums("scrobbles/" + e + ".tsv", cla.checksums) global lastsync lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) log("Database saved to disk.")
def sync(): # all entries by file collected # so we don't open the same file for every entry #log("Syncing",module="debug") entries = {} for idx in range(len(SCROBBLES)): if not SCROBBLES[idx].saved: t = get_scrobble_dict(SCROBBLES[idx]) artistlist = list(t["artists"]) artistlist.sort( ) #we want the order of artists to be deterministic so when we update files with new rules a diff can see what has actually been changed artistss = "␟".join(artistlist) timestamp = datetime.date.fromtimestamp(t["time"]) album = t["album"] or "-" duration = t["duration"] or "-" entry = [str(t["time"]), artistss, t["title"], album, duration] monthcode = str(timestamp.year) + "_" + str(timestamp.month) entries.setdefault(monthcode, []).append( entry) #i feckin love the setdefault function SCROBBLES[idx] = Scrobble(*SCROBBLES[idx][:-1], True) # save copy with last tuple entry set to true #log("Sorted into months",module="debug") for e in entries: tsv.add_entries(datadir("scrobbles/" + e + ".tsv"), entries[e], comments=False) #addEntries("scrobbles/" + e + ".tsv",entries[e],escape=False) utilities.combineChecksums(datadir("scrobbles/" + e + ".tsv"), cla.checksums) #log("Written files",module="debug") global lastsync lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())