IPB

Welcome Guest ( Log In | Register )

Python Grabber scripts
2E7AH
post May 28 2009, 15:27
Post #1





Group: Validating
Posts: 2424
Joined: 21-May 08
Member No.: 53675



Some users reported errors using the scripts I posted here
The errors are result of incorrectly saving the copied scripts, probably indentation errors, so I'm posting those scripts as ready made files here:

[attachment=5122:Discogs.zip]
Go to the top of the page
+Quote Post
 
Start new topic
Replies
tore
post Mar 15 2010, 20:11
Post #2





Group: Members
Posts: 41
Joined: 6-February 10
Member No.: 77932



I've now tried playing around with your last.fm script to see if I can tailor it to fetch other sorts of last.fm info. However, my lack of knowledge with Python is a hindrance! I've changed the script slightly so that it fetches similar artists.

Here's an example of the information the script can get : http://ws.audioscrobbler.com/2.0/?method=a...ac220b7b2e0a026

I've set a limit to 3 artists. However, I have a hard time getting all three artists - I can only fetch one, just like you only wanted the top tag. So my question is, what do I have to do with this piece of code so that I can fetch all three similar artists?

CODE
child = doc.getElementsByTagName("artist")[0]
toptag = child.getElementsByTagName("name")[0]
lyric = toptag.childNodes[0].data.encode('utf_8').capitalize()


I see changing the value between the brackets in the "("artist")[0]" snippet changes the information retrieved to the next artist. However, I can't figure out how to get them all in one go!
Go to the top of the page
+Quote Post
2E7AH
post Mar 15 2010, 20:28
Post #3





Group: Validating
Posts: 2424
Joined: 21-May 08
Member No.: 53675



look at the other last.fm script, i.e.

CODE
toptags = child.getElementsByTagName("tag")
tags=[]
for i in toptags:
    tags.append(str(i.getElementsByTagName("name")[0].toxml()).replace('<name>','').replace('</name>','').capitalize( ))
lyric=str(tags).strip('[]').replace(',', ';').replace('\'','')


try something like that smile.gif
Go to the top of the page
+Quote Post
tore
post Mar 15 2010, 20:38
Post #4





Group: Members
Posts: 41
Joined: 6-February 10
Member No.: 77932



QUOTE (2E7AH @ Mar 15 2010, 20:28) *
look at the other last.fm script, i.e.

CODE
toptags = child.getElementsByTagName("tag")
tags=[]
for i in toptags:
    tags.append(str(i.getElementsByTagName("name")[0].toxml()).replace('<name>','').replace('</name>','').capitalize( ))
lyric=str(tags).strip('[]').replace(',', ';').replace('\'','')


try something like that smile.gif


Thanks for the suggestion smile.gif I now get a syntax error in some of the code you posted. To make it a little easier, here's a larger snippet with your suggestion pasted in :

CODE
artist = handle.Format("[%artist%]")
title = handle.Format("3")

try:
string=urllib.urlopen('http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=' + artist.lower().replace(' ','+') + '&limit=' + title.lower().replace(' ','+') + '&api_key=' + api_key).read()
doc = minidom.parseString(string)
toptags = child.getElementsByTagName("tag")
tags=[]
for i in toptags:
tags.append(str(i.getElementsByTagName("name")[0].toxml()).replace('<name>','').replace('</name>','').capitalize( ))
lyric=str(tags).strip('[]').replace(',', ';').replace('\'','')
result.append(lyric)
except Exception, e:
traceback.print_exc(file=sys.stdout)
result.append('')
continue

return result

if __name__ == "__main__":
LyricProviderInstance = LastFm_TopTag()

Go to the top of the page
+Quote Post
2E7AH
post Mar 15 2010, 20:48
Post #5





Group: Validating
Posts: 2424
Joined: 21-May 08
Member No.: 53675



I just pasted that part from that other last.fm script, it wasn't intended for literal use, but as example
Look at your XML response: there isn't "tag" node anywhere, so use what you need, and play a little wink.gif

[edit] to help you a bit:

where is your "child" variable that you are calling with "toptags" and pasting to look for "tag" node (which doesn't exist BTW in XML response as said)?
why "doc" isn't called?
name those variables meaningful to you

you can explicitly set title, no need for "handle.Format" if you don't need info for some tag to be provided

This post has been edited by 2E7AH: Mar 15 2010, 21:08
Go to the top of the page
+Quote Post

Posts in this topic
- 2E7AH   Python Grabber scripts   May 28 2009, 15:27
- - auldyin   QUOTE (2E7AH @ May 28 2009, 15:27) Some u...   May 28 2009, 18:19
- - 2E7AH   Search format: artist-title. LRC (time-stamped) l...   Jun 22 2009, 23:24
- - 2E7AH   Mistype error corrected and some specific parsing,...   Jun 24 2009, 12:46
- - 2E7AH   Mistype error corrected and some specific parsing,...   Jun 24 2009, 15:15
- - 2E7AH   corrected code page for accented chars etc.   Jun 24 2009, 19:56
- - 2E7AH   RE: Python Grabber scripts   Jun 24 2009, 21:33
- - elenhil   Same error as before: CODEfoo_grabber_python...   Jun 26 2009, 12:40
- - 2E7AH   That can only happen if you don't have artist ...   Jun 26 2009, 15:17
|- - elenhil   QUOTE (2E7AH @ Jun 26 2009, 18:17) That c...   Jun 26 2009, 21:45
- - 2E7AH   Updated AMG review: fasterif fetching multiple rel...   Jun 26 2009, 16:57
|- - tberman333   QUOTE (2E7AH @ Jun 26 2009, 10:57) Update...   Sep 22 2009, 02:46
- - tere   maybe there is a way to make a plugin also www.lol...   Jun 29 2009, 06:24
- - 2E7AH   QUOTE (tere @ Jun 29 2009, 07:24) maybe t...   Jun 29 2009, 23:53
- - 2E7AH   Search format: artist-title. We are the leading ly...   Jun 30 2009, 16:36
- - q-stankovic   Hello 2E7AH! I tried to download some of y...   Sep 22 2009, 17:31
- - 2E7AH   Some strange interest in scripts today I'll up...   Sep 23 2009, 20:05
- - q-stankovic   QUOTE (2E7AH @ Sep 23 2009, 21:05) Sorry ...   Sep 25 2009, 17:18
- - 2E7AH   hm... I don't know what you mean with database...   Sep 25 2009, 17:37
- - 2E7AH   Also maybe isn't so good idea making lyrics gr...   Sep 25 2009, 18:56
- - q-stankovic   QUOTE (2E7AH @ Sep 25 2009, 18:37) I...   Sep 26 2009, 15:07
- - 2E7AH   Here are updated AMG scripts: - AMG_Genre.py -...   Oct 11 2009, 07:04
- - 2E7AH   Updated AMG review script: - changed %artist% to...   Oct 16 2009, 14:40
- - Benji99   Hey 2E7AH, Any chance you could make a script for...   Oct 29 2009, 02:32
- - 2E7AH   Aren't you from Canada? It looks easy to find...   Oct 29 2009, 02:58
|- - Benji99   QUOTE (2E7AH @ Oct 28 2009, 21:58) Aren...   Oct 29 2009, 03:13
- - 2E7AH   I'll try this one, it should be OK (although d...   Oct 29 2009, 03:19
|- - Benji99   QUOTE (2E7AH @ Oct 28 2009, 22:19) I...   Oct 29 2009, 03:36
- - 2E7AH   Benji99, here is the script: I've tested it ...   Oct 31 2009, 06:12
|- - Benji99   QUOTE (2E7AH @ Oct 31 2009, 00:12) Benji9...   Nov 11 2009, 07:29
|- - 2E7AH   QUOTE (Benji99 @ Nov 11 2009, 08:29) 1st ...   Nov 11 2009, 08:05
|- - Benji99   QUOTE (2E7AH @ Nov 11 2009, 02:05) Is tha...   Nov 21 2009, 04:31
- - 2E7AH   Once again AMG scripts Now GENRE, STYLE, MOOD an...   Nov 10 2009, 09:31
- - 2E7AH   Download this AMG release script: Problem with pr...   Nov 10 2009, 11:08
|- - tberman333   Thank you! This is great! QUOTE (2E7AH ...   Nov 10 2009, 15:17
- - 2E7AH   Enjoy I didn't forgot about composer/performe...   Nov 10 2009, 16:22
|- - tberman333   QUOTE (2E7AH @ Nov 10 2009, 10:22) Enjoy ...   Nov 10 2009, 18:10
|- - Benji99   QUOTE (2E7AH @ Nov 10 2009, 11:22) Enjoy ...   Mar 27 2010, 23:15
- - T.P Wang   @2E7AH: I think replace the u'\uff5e...   Nov 21 2009, 03:09
- - garbanzo.bean   2E7AH, i'm trying to use your AMG script, but ...   Jan 8 2010, 15:54
|- - tberman333   QUOTE (garbanzo.bean @ Jan 8 2010, 09:54)...   Jan 8 2010, 16:46
- - tore   I have a quick question regarding the python disco...   Mar 15 2010, 12:29
|- - 2E7AH   QUOTE (tore @ Mar 15 2010, 12:29) Would i...   Mar 15 2010, 13:15
- - tore   By the way, I did find this little piece of inform...   Mar 15 2010, 15:05
- - tore   I've now tried playing around with your last.f...   Mar 15 2010, 20:11
|- - 2E7AH   look at the other last.fm script, i.e. CODEtoptag...   Mar 15 2010, 20:28
|- - tore   QUOTE (2E7AH @ Mar 15 2010, 20:28) look a...   Mar 15 2010, 20:38
|- - 2E7AH   I just pasted that part from that other last.fm sc...   Mar 15 2010, 20:48
|- - tore   QUOTE (2E7AH @ Mar 15 2010, 20:48) I just...   Mar 15 2010, 21:38
- - 2E7AH   hey, why ride motorcycle when I have my bike le...   Mar 15 2010, 21:51
|- - tore   QUOTE (2E7AH @ Mar 15 2010, 21:51) hey, w...   Mar 15 2010, 22:34
|- - 2E7AH   QUOTE (tore @ Mar 15 2010, 22:34) I made ...   Mar 15 2010, 23:00
|- - tore   QUOTE (2E7AH @ Mar 15 2010, 23:00) QUOTE ...   Mar 15 2010, 23:14
|- - tore   For an example of what information could be pulled...   Mar 16 2010, 00:26
- - tore   To anyone having a problem with the discogs 5000 r...   Mar 19 2010, 15:05
|- - 2E7AH   I didn't bothered with 5000 limit on Discogs, ...   Mar 19 2010, 18:52
- - tore   Here's a modification of what I described abov...   Mar 20 2010, 02:03
- - xtr   Is it possible to use these scripts with a foo_run...   Mar 21 2010, 23:05
- - 2E7AH   If you have python, I guess you know something abo...   Mar 21 2010, 23:21
- - 2E7AH   Are you really counting on that Script is there,...   Mar 29 2010, 00:10
- - Benji99   I was thinking of writing a small program (evaluat...   Mar 31 2010, 21:13
- - 2E7AH   I'm just working on the script, and it's a...   Apr 1 2010, 03:15
|- - Benji99   QUOTE (2E7AH @ Mar 31 2010, 22:15) I...   Apr 4 2010, 22:15
- - Hitchhiker427   Does anyone still have 2E7AH's scripts for Lyr...   Aug 6 2010, 00:55
- - grimes   Found a Lyrics-site with API: ChartLyrics Here is...   Aug 7 2010, 21:03
|- - Hitchhiker427   QUOTE (grimes @ Aug 7 2010, 15:03) Found ...   Aug 9 2010, 20:14
- - Beta4Me   For all that are interested...I am coding in PHP a...   Oct 6 2010, 13:06
|- - tberman333   QUOTE (Beta4Me @ Oct 6 2010, 08:06) For a...   Oct 23 2010, 23:05
|- - Beta4Me   QUOTE (tberman333 @ Oct 24 2010, 08:05) Q...   Oct 24 2010, 06:38
- - lo-fi   yep. amg scripts not working here either   Oct 24 2010, 00:41
|- - Decalicatan_Decalicatan   QUOTE (lo-fi @ Oct 24 2010, 01:41) y...   Oct 24 2010, 09:41
- - Wooops   Since most of the script links seem to be broken -...   Oct 25 2010, 05:54
- - Beta4Me   How did the original python grabber scripts work? ...   Oct 26 2010, 02:47
- - mrinferno   AMG redesigned their site and search methods mid-O...   Oct 26 2010, 02:53
|- - Beta4Me   QUOTE (mrinferno @ Oct 26 2010, 12:53) AM...   Oct 26 2010, 03:59
|- - tberman333   QUOTE (Beta4Me @ Oct 25 2010, 22:59) QUOT...   Oct 26 2010, 21:16
|- - Beta4Me   QUOTE (tberman333 @ Oct 27 2010, 07:16) Q...   Oct 26 2010, 23:25
|- - tberman333   QUOTE (Beta4Me @ Oct 26 2010, 18:25) Than...   Oct 27 2010, 01:37
- - Decalicatan_Decalicatan   I have uploaded one of the 2E7AH amg scripts (from...   Oct 26 2010, 11:10
|- - Beta4Me   QUOTE (Decalicatan_Decalicatan @ Oct 26 2010,...   Oct 26 2010, 11:15
|- - Schuft   QUOTE (Decalicatan_Decalicatan @ Oct 26 2010,...   Feb 13 2011, 09:41
|- - klonuo   QUOTE (Schuft @ Feb 13 2011, 10:41) Is th...   Feb 13 2011, 16:53
- - Schuft   Ok - you're right - phyton installation was mi...   Feb 16 2011, 18:37
- - MDMA   Would it be possible to use this component to fetc...   Feb 8 2012, 16:21
- - Fractal_Mortality   Does anyone know where i could find updated script...   Feb 3 2013, 20:30


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 21st April 2014 - 05:47