This repository has been archived by the owner on Dec 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchItem.py
66 lines (49 loc) · 1.92 KB
/
SearchItem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from bs4 import BeautifulSoup
class SearchItem:
"""Abstract class representing a search item"""
# attributes for the SearchItem
title = ''
link = ''
category = ''
filesize = ''
files = ''
seeders = ''
leechers = ''
def __init__(self, item):
pass
def noHtmlPlease(self, text_to_strip):
return ''.join(BeautifulSoup(text_to_strip).findAll(text=True))
def str_to_int(self, value):
if value == '':
return 0
else:
return int(value)
class IsoHuntItem(SearchItem):
"""Manipulates the results from ISO Hunt to a standard search item"""
def __init__(self, item):
"""item is an array recieved from an ISO Hunt search"""
self.title = self.noHtmlPlease(item['title'])
self.category = item['category']
self.filesize = item['size']
self.files = str(item['files'])
self.seeders = self.str_to_int(item['Seeds'])
self.leechers = self.str_to_int(item['leechers'])
self.link = item['link'].replace('\\', '')
class PirateBayItem(SearchItem):
"""Builds a Search Item from TPB request data"""
def __init__(self, item):
"""item is an array of the torrent data"""
pass
class KickassItem(SearchItem):
"""Builds a search item that is kick ass"""
def __init__(self, item, base_url):
"""item is html string to parse"""
soup = BeautifulSoup(item.encode(), "lxml")
torrentName = soup.find('div', 'torrentname')
self.title = torrentName.find('a', 'normalgrey').text
self.category = 'N/A'
self.filesize = soup.find('td', 'nobr').text
self.files = soup.find('td', 'nobr').next_sibling.next_sibling.string
self.seeders = self.str_to_int(soup.find('td', 'green').text)
self.leechers = self.str_to_int(soup.find('td', 'red').text)
self.link = base_url + torrentName.find('a', 'torType')['href']