You are not logged in.
So I have this function in python:
def lastCache(args):
artistlist=client.list('artist')
content = set()
errors = set()
errors2 = set()
fields = ('last-modified', 'date', 'albumartist', 'album')
fh = open(os.getenv('HOME')+'/.config/clerk/last.cache', "w")
for artist in artistlist:
try:
for element in client.find('albumartist', artist):
content.add(os.getenv('seperator').join((element[f] for f in fields)))
for line in sorted(content, key=str.lower, reverse=True):
fh.write(line+"\n")
except KeyError:
errors.add(element['file'])
except TypeError:
errors2.add(element['file'])
for line in sorted(errors, key=str.lower):
print("Missing tags for file: "+line, file=sys.stderr)
for line in sorted(errors2, key=str.lower):
print("Duplicate tags for file: "+line, file=sys.stderr)
fh.close()
Goal: a list of albums in mpd, formatted as "date $seperator artist $seperator album"
What works: a list is created
Issues:
last-modified is needed to sort the list, but should not be in final output.
the list should be without duplicates.
I am a total python newb and this seems to be above my head
Last edited by Rasi (2014-12-19 13:35:25)
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
You could do something along the lines of:
for element in client.find('albumartist', artist):
content.add(element[f] for f in fields)
seen = set()
for element in sorted(content, key=lambda elem: elem[0]):
if element not in seen:
line = element[1:]
fh.write(os.getenv('seperator').join(line), '\n')
seen.add(line)
(Not tested - content could/should be changed to a normal list/deque too)
Offline
...gives no output at all...
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
Thanks sahib vor helping me out on IRC...
this is the solution:
def lastCache(args):
artistlist=client.list('albumartist')
content = set()
errors = set()
errors2 = set()
fields = ('last-modified', 'date', 'albumartist', 'album')
fh = open(os.getenv('HOME')+'/.config/clerk/last.cache', "w")
seen = set()
for artist in artistlist:
try:
for element in client.find('albumartist', artist):
content.add(tuple(element[f] for f in fields))
for element in sorted(content, key=lambda elem: elem[0]):
if element[1:] not in seen:
line = element[1:]
fh.write(os.getenv('seperator').join(line)+"\n")
seen.add(line)
except KeyError:
errors.add(element['file'])
except TypeError:
errors2.add(element['file'])
for line in sorted(errors, key=str.lower):
print("Missing tags for file: "+line, file=sys.stderr)
for line in sorted(errors2, key=str.lower):
print("Duplicate tags for file: "+line, file=sys.stderr)
fh.close()
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline