Advertisement
Guest User

Anime Planet XML List Exporter

a guest
Apr 21st, 2013
338
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 3.91 KB | None | 1 0
  1. #!/usr/bin/python
  2. # 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
  3. # This script has been modified to include all MAL attributes to be edited by user.
  4. # Update on Import will overwrite current list.
  5. # Additional info and packages:
  6. # Python 2.7 - http://python.org/download/
  7. # BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/#Download
  8.  
  9. from bs4 import BeautifulSoup,NavigableString
  10. import urllib2,sys,re,codecs
  11.  
  12. print 'This script will export your anime-planet.com anime list and saves it to anime-planet.xml'
  13. username = raw_input('Enter your username:')
  14. baseURL = 'http://www.anime-planet.com/users/'+username+'/anime'
  15. html = urllib2.urlopen(baseURL).read()
  16. html = BeautifulSoup(html)
  17. pageNumber = int (html.find('li','next').findPrevious('li').next.contents[0])
  18. delimiter = '\t'
  19.  
  20. f = codecs.open(''+username+'.xml', 'w', 'utf-8')
  21. f.write ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
  22. f.write ('<myanimelist>\n\n')
  23.  
  24. f.write ('\t<myinfo>\n');
  25. f.write ('\t\t<user_id></user_id>\n');
  26. f.write ('\t\t<user_name>'+username+'</user_name>\n');
  27. f.write ('\t\t<user_export_type>1</user_export_type>\n');
  28. f.write ('\t\t<user_total_anime></user_total_anime>\n');
  29. f.write ('\t\t<user_total_watching>0</user_total_watching>\n');
  30. f.write ('\t\t<user_total_completed>0</user_total_completed>\n');
  31. f.write ('\t\t<user_total_onhold>0</user_total_onhold>\n');
  32. f.write ('\t\t<user_total_dropped>0</user_total_dropped>\n');
  33. f.write ('\t\t<user_total_plantowatch>0</user_total_plantowatch>\n');
  34. f.write ('\t</myinfo>\n\n');
  35.  
  36. print 'Exporting rough variant of myanimelist format...'
  37. for i in range(1,pageNumber+1):
  38.         baseURL = 'http://www.anime-planet.com/users/'+username+'/anime?page='+str(i)
  39.         html = urllib2.urlopen(baseURL).read()
  40.         html = BeautifulSoup(html)
  41.         for animeItem in html.findAll('tr')[1:]:
  42.                 animeItem = BeautifulSoup(animeItem.renderContents())
  43.  
  44.                
  45.                 f.write ('\t<anime>\n');
  46.                 f.write ('\t\t<series_animedb_id></series_animedb_id>\n');
  47.                 f.write ('\t\t<series_title><![CDATA['+ animeItem.a.text +']]></series_title>\n');
  48.                 f.write ('\t\t<series_type>' + animeItem.find('td','tableType').text + '</series_type>\n');
  49.                 f.write ('\t\t<series_episodes>0</series_episodes>\n');
  50.                 f.write ('\t\t<my_id>0</my_id>\n');
  51.                 f.write ('\t\t<my_watched_episodes>'+ animeItem.find('td','tableEps').text.replace('&nbsp;','1') +'</my_watched_episodes>\n');
  52.                 f.write ('\t\t<my_start_date>0000-00-00</my_start_date>\n');
  53.                 f.write ('\t\t<my_finish_date>0000-00-00</my_finish_date>\n');
  54.                 f.write ('\t\t<my_fansub_group><![CDATA[0]]></my_fansub_group>\n');
  55.                 f.write ('\t\t<my_rated></my_rated>\n');
  56.                 f.write ('\t\t<my_score>' + str(int(float(animeItem.img['name'])*2)) + '</my_score>\n');
  57.                 f.write ('\t\t<my_dvd></my_dvd>\n');
  58.                 f.write ('\t\t<my_storage></my_storage>\n');
  59.                 f.write ('\t\t<my_status>' + animeItem.find('td','tableStatus').text.replace('status box','') +'</my_status>\n');
  60.                 f.write ('\t\t<my_comments><![CDATA[]]></my_comments>\n');
  61.                 f.write ('\t\t<my_times_watched>01</my_times_watched>\n');
  62.                 f.write ('\t\t<my_rewatch_value></my_rewatch_value>\n');
  63.                 f.write ('\t\t<my_downloaded_eps>0</my_downloaded_eps>\n');
  64.                 f.write ('\t\t<my_tags><![CDATA[]]></my_tags>\n');
  65.                 f.write ('\t\t<my_rewatching>0</my_rewatching>\n');
  66.                 f.write ('\t\t<my_rewatching_ep>0</my_rewatching_ep>\n');
  67.                 f.write ('\t\t<update_on_import>1</update_on_import>\n');
  68.                 f.write ('\t</anime>\n\n');
  69.  
  70. f.write ('</myanimelist>\n')
  71. print 'Done, see '+username+'.xml'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement