Created
December 29, 2015 08:37
-
-
Save ryukinix/6951f57e02a9e0de0ee4 to your computer and use it in GitHub Desktop.
Lista de animes de www.anbient.net organizados por score
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Bash Script | |
# | |
# Copyright © Manoel Vilela | |
# | |
# | |
from requests import get | |
from bs4 import BeautifulSoup | |
def getNote(url): | |
raw = get(url).text | |
soup = BeautifulSoup(raw, "html.parser") | |
note = 0 | |
content = [] | |
for group in soup.find_all(['span', "class=bignote"]): | |
content.extend([x for x in group.strings]) | |
for index, x in enumerate(content): | |
if 'Minha nota' in x: | |
real_note = content[index + 3] | |
note = float(real_note.strip('\t\n')) | |
break | |
return note | |
def animeUrls(): | |
main_url = 'http://www.anbient.net' | |
list_url = main_url + '/lista' | |
backbone = get(list_url) | |
soup = BeautifulSoup(backbone.text, "html.parser") | |
anime_urls = {} | |
passing = True | |
for link in soup.find_all(['tr', 'href', 'a'], href=True): | |
name = [x.strip() for x in link.strings if x.strip() not in ('', '\n')] | |
url = link['href'] | |
if passing or "Riccardo Benetti" in name: | |
if '.hack//DUSK' in name: | |
passing = False | |
else: | |
continue | |
anime_urls[name.pop()] = main_url + url | |
return anime_urls | |
def main(): | |
print(":: Fetching main list, getting url animes") | |
anime_urls = animeUrls() | |
# max anime name | |
n = len(max(anime_urls, key=lambda x: len(x))) | |
anime_format = '{{: <{width}}}'.format(width=n) | |
print(":: Get score of each anime") | |
anime_score_url = [] | |
print("{} Score\tUrl".format(anime_format.format('Anime'))) | |
for anime, url in sorted(anime_urls.items()): | |
score = getNote(url) | |
anime = anime_format.format(anime) | |
print("{} {: >2}\t{}".format(anime, score, url)) | |
anime_score_url.append((anime, score, url)) | |
print(":: Sorting...") | |
sorted_anime = sorted(anime_score_url, key=lambda x: x[1]) | |
print("{} Score\tUrl".format(anime_format.format('Anime'))) | |
for anime, score, url in sorted_anime: | |
anime = anime_format.format(anime) | |
print("{} {: <2}\t{}".format(anime, score, url)) | |
print(":: Saving list") | |
with open('anbient_list.txt', 'w') as f: | |
content = ["{} Score\tUrl".format(anime_format.format('Anime'))] | |
for anime, score, url in sorted_anime: | |
anime = anime_format.format(anime) | |
content.append("{} {}\t{}".format(anime, score, url)) | |
f.write('\n'.join(content)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment