python - Auto completing song titles and parsing a string -
i string via python, using request shoutcast server:
best show ever http://www.myradio.foo/xml/logos/showlogo.jpg avicii hey brother
and i'd dict containing this:
mystring[showtitle] = 'best show ever' mystring[image] = 'http://www.myradio.foo/xml/logos/showlogo.jpg' mystring[song] = 'avicii hey brother'
the string ascii, , written after , before link.
how can parse that? guess need use regex, heard aren't fast.
also, title needs bit of tweaking, prettier.
avicii hey brother
becomes
avicii - hey brother
what raccomend that? thought searching title on itunes , first result data, i'm not sure how (all links itunes api redirect me apple sdk, not use).
i wrong dict()
here updated solution converts dict.
response = '''best show ever http://www.myradio.foo/xml/logos/showlogo.jpg avicii hey brother''' ## parsing using named group m = re.match("(?p<showtitle>.*?)\s+(?p<image>https?://\s+)\s+(?p<song>.+)", response); mystring = m.groupdict() print mystring['song']
you can not convert song name on format always. cause don't know 1 song name, or 1 album name. if fixed first word album name, can one:
print re.sub("^(\s+)\s", "\\1 - ", mystring['song'])
Comments
Post a Comment