Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib3
- import os
- import time
- from sys import exit
- # diretório atual
- curdir = os.getcwd()
- #lista de animes
- animes = [['Coppelion',
- 'Kill la Kill',
- 'Golden Time',
- 'Yuushibu'],
- ['coppelion.jpg',
- 'killlakill.jpg'
- 'goldentime.jpg']]
- #lista de fansubs
- fansubs = ['HorribleSubs',
- 'Commie',
- 'UTW',
- 'WhyNot',
- 'Vivid',
- 'FFF',
- 'GotWoot',
- 'EveTaku',
- 'Coalgirls']
- # conexão com a página
- url = 'http://www.nyaa.se/?page=rss'
- http = urllib3.PoolManager()
- r = http.request('GET', url)
- # começo e fim da página de HTML
- startTable = "<html><body><FONT FACE='arial'><table border=\"2\">"
- endTable = "</table></FONT></body></html>"
- # retorna o status obtido na conexão
- print("Status obtido: " + str(r.status))
- if (r.status != 200):
- print("O script não será mais executado.")
- os.system("pause")
- exit(0)
- print("Iniciando conversão para UTF-8...")
- # tenta decodificar para UTF8
- try:
- t = r.data.decode("utf8")
- except DECODEERROR as E:
- print("Ocorreu um erro: " + str(E))
- print("O script será parado agora.")
- exit(0)
- print("Conversão completa.")
- #passamos a info para uma variável
- HTML = str(r.data)
- #lista para armazenar os torrents
- itemList = []
- class Item:
- def __init__(self, start, end):
- self.start = start
- self.end = end
- self.data = HTML[start+6:end]
- self.title = self.getTitle()
- self.category = self.getCat()
- self.DL = self.getDownloadLink()
- self.VL = self.getViewLink()
- self.description = self.getDescription()
- self.date = self.getDate()
- def getTitle(self):
- a = self.data.find("<title>")
- b = self.data.find("</title>")
- return str(self.data[a+7:b])
- def getCat(self):
- me = self.data.find("<category>")
- ow = self.data.find("</category>")
- return str(self.data[me+10:ow])
- def getDownloadLink(self):
- a = self.data.find("<link>")
- b = self.data.find("</link>")
- return str(self.data[a+6:b])
- def getViewLink(self):
- a = self.data.find("<guid>")
- b = self.data.find("</guid>")
- return str(self.data[a+6:b])
- def getDescription(self):
- a = self.data.find("<description>")
- b = self.data.find("</description>")
- return str(self.data[a+22:b-3])
- def getDate(self):
- a = self.data.find("<pubDate>")
- b = self.data.find("</pubDate>")
- return str(self.data[a+9:b])
- # separa os itens em objetos e coloca no array itemList
- def encontraItem(n):
- comeco = HTML.find("<item>", n)
- fim = HTML.find("</item>", comeco)
- if comeco == -1 or fim == -1:
- return [-1, -1]
- else:
- thisItem = Item(comeco,fim)
- itemList.append(thisItem)
- print("thisItem: " + str(thisItem.end))
- return [comeco, fim]
- ultimoitem = 0
- contador = 0
- # percorrer a info que pegamos direto do site
- while(1):
- umitem = encontraItem(ultimoitem)
- if umitem[0] > 0 and umitem[1] > 0:
- ultimoitem = umitem[0]+1
- print("Começo: " + str(umitem[0]))
- print("Fim: " + str(umitem[1]))
- contador += 1
- if umitem[0] == -1 or umitem[1] == -1:
- print("Itens encontrados: " + str(contador))
- break
- # separar os animes que queremos
- animeList = []
- contador = 0
- for i in range(len(itemList)):
- for x in range(len(animes[0])):
- if itemList[i].title.find(animes[0][x]) != -1 and itemList[i].category.find("English-translated") != -1:
- print("Title: " + itemList[i].title)
- print("Anime: " + animes[0][x])
- animeList.append(itemList[i])
- contador += 1
- print("Torrens provaveis: " + str(contador))
- # abrimos um arquivo para escrever o HTML
- file = open(curdir + "\page.html","w",encoding="utf8")
- HTML = startTable
- def NewLine(string):
- return "<tr>" + string + "</tr>"
- def NewRow(string):
- return "<td>" + string + "</td>"
- for i in range(len(animeList)):
- HTML += NewLine(NewRow(animeList[i].title) + NewRow(animeList[i].description) + NewRow(animeList[i].DL + NewRow(animeList[i].date)))
- HTML += endTable
- file.write(HTML)
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment