Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # This script will take your anime-planet.com username and scrape a list of your watched anime in XML utf-8 format to anime-planet.xml
- # This script has been modified to include all MAL attributes to be edited by user.
- # Update on Import will overwrite current list.
- # Additional info and packages:
- # Python 2.7 - http://python.org/download/
- # BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/#Download
- from bs4 import BeautifulSoup,NavigableString
- import urllib2,sys,re,codecs
- print 'This script will export your anime-planet.com anime list and saves it to anime-planet.xml'
- username = raw_input('Enter your username:')
- baseURL = 'http://www.anime-planet.com/users/'+username+'/anime'
- html = urllib2.urlopen(baseURL).read()
- html = BeautifulSoup(html)
- pageNumber = int (html.find('li','next').findPrevious('li').next.contents[0])
- delimiter = '\t'
- f = codecs.open(''+username+'.xml', 'w', 'utf-8')
- f.write ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
- f.write ('<myanimelist>\n\n')
- f.write ('\t<myinfo>\n');
- f.write ('\t\t<user_id></user_id>\n');
- f.write ('\t\t<user_name>'+username+'</user_name>\n');
- f.write ('\t\t<user_export_type>1</user_export_type>\n');
- f.write ('\t\t<user_total_anime></user_total_anime>\n');
- f.write ('\t\t<user_total_watching>0</user_total_watching>\n');
- f.write ('\t\t<user_total_completed>0</user_total_completed>\n');
- f.write ('\t\t<user_total_onhold>0</user_total_onhold>\n');
- f.write ('\t\t<user_total_dropped>0</user_total_dropped>\n');
- f.write ('\t\t<user_total_plantowatch>0</user_total_plantowatch>\n');
- f.write ('\t</myinfo>\n\n');
- print 'Exporting rough variant of myanimelist format...'
- for i in range(1,pageNumber+1):
- baseURL = 'http://www.anime-planet.com/users/'+username+'/anime?page='+str(i)
- html = urllib2.urlopen(baseURL).read()
- html = BeautifulSoup(html)
- for animeItem in html.findAll('tr')[1:]:
- animeItem = BeautifulSoup(animeItem.renderContents())
- f.write ('\t<anime>\n');
- f.write ('\t\t<series_animedb_id></series_animedb_id>\n');
- f.write ('\t\t<series_title><![CDATA['+ animeItem.a.text +']]></series_title>\n');
- f.write ('\t\t<series_type>' + animeItem.find('td','tableType').text + '</series_type>\n');
- f.write ('\t\t<series_episodes>0</series_episodes>\n');
- f.write ('\t\t<my_id>0</my_id>\n');
- f.write ('\t\t<my_watched_episodes>'+ animeItem.find('td','tableEps').text.replace(' ','1') +'</my_watched_episodes>\n');
- f.write ('\t\t<my_start_date>0000-00-00</my_start_date>\n');
- f.write ('\t\t<my_finish_date>0000-00-00</my_finish_date>\n');
- f.write ('\t\t<my_fansub_group><![CDATA[0]]></my_fansub_group>\n');
- f.write ('\t\t<my_rated></my_rated>\n');
- f.write ('\t\t<my_score>' + str(int(float(animeItem.img['name'])*2)) + '</my_score>\n');
- f.write ('\t\t<my_dvd></my_dvd>\n');
- f.write ('\t\t<my_storage></my_storage>\n');
- f.write ('\t\t<my_status>' + animeItem.find('td','tableStatus').text.replace('status box','') +'</my_status>\n');
- f.write ('\t\t<my_comments><![CDATA[]]></my_comments>\n');
- f.write ('\t\t<my_times_watched>01</my_times_watched>\n');
- f.write ('\t\t<my_rewatch_value></my_rewatch_value>\n');
- f.write ('\t\t<my_downloaded_eps>0</my_downloaded_eps>\n');
- f.write ('\t\t<my_tags><![CDATA[]]></my_tags>\n');
- f.write ('\t\t<my_rewatching>0</my_rewatching>\n');
- f.write ('\t\t<my_rewatching_ep>0</my_rewatching_ep>\n');
- f.write ('\t\t<update_on_import>1</update_on_import>\n');
- f.write ('\t</anime>\n\n');
- f.write ('</myanimelist>\n')
- print 'Done, see '+username+'.xml'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement