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
- #Will also create an anime_list.txt file for all the anime that needs to be added manually. Note that the code will break if there are
- #special characters invovled... So remove the anime from your Anime-Planet list first.
- #Additional info and packages:
- # Python 3.3 - http://python.org/download/
- # BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/#Download
- # In order to successfully import the exported Anime-Planet list to MAL, first export a MAL list, and copy the <myinfo> block just after <myanimelist>
- from bs4 import BeautifulSoup,NavigableString
- import urllib.request, urllib.error, urllib.parse,sys,re,codecs
- import json
- print('This script will export your anime-planet.com anime list and saves it to anime-planet.xml')
- username = input("Enter your username: ")
- baseURL = 'http://www.anime-planet.com/users/'+username+'/anime'
- html = urllib.request.urlopen(baseURL).read()
- html = BeautifulSoup(html)
- pageNumber = int (html.find('li','next').findPrevious('li').next.contents[0])
- delimiter = '\t'
- queryURL = 'http://mal-api.com/anime/search?q='
- f = codecs.open('anime-planet.xml', 'w', 'utf-8')
- f.write ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
- f.write ('<myanimelist>\n')
- g = codecs.open('anime_list.txt', 'w', 'utf-8')
- g.write ('You will have to add these anime manually \n \n')
- print('Exporting rough variant of myanimelist format... \n')
- for i in range(1,pageNumber+1):
- baseURL = 'http://www.anime-planet.com/users/'+username+'/anime?page='+str(i)
- html = urllib.request.urlopen(baseURL).read()
- html = BeautifulSoup(html)
- for animeItem in html.findAll('tr')[1:]:
- animeItem = BeautifulSoup(animeItem.renderContents())
- animeName = '' + animeItem.a.text
- queryName = re.sub('[^A-Za-z0-9]+', '%20', animeName)
- queryTitle = urllib.request.urlopen(queryURL + queryName).read()
- print(queryTitle)
- search=json.loads(queryTitle.decode('utf8'))
- for x in search:
- print(animeName)
- try:
- if animeName.lower()==x["title"].lower():
- animeID=str(x["id"])
- elif animeName.lower()in [y.lower() for y in x["other_titles"]["english"]]:
- animeID=str(x["id"])
- elif animeName.lower() in [j.lower() for j in x["other_titles"]["synonyms"]]:
- animeID=str(x["id"])
- except KeyError as e:
- pass
- f.write ('\t<anime>\n');
- f.write ('\t\t<series_animedb_id>'+ animeID +'</series_animedb_id>\n');
- f.write ('\t\t<series_title><![CDATA['+ animeName +']]></series_title>\n');
- f.write ('\t\t<series_type>' + animeItem.find('td','tableType').text + '</series_type>\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').replace("\t", "").replace("\n", "").replace("\r", "").replace(" ", "") +'</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[]]></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)).replace("\t", "").replace("\n", "").replace("\r", "").replace(" ", "") + '</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','').replace("\t", "").replace("\n", "").replace("\r", "").replace(" ", "") +'</my_status>\n');
- f.write ('\t\t<my_comments><![CDATA[]]></my_comments>\n');
- f.write ('\t\t<my_times_watched>0</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 anime-planet.xml and anime_list.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement