Coverage for xdcc_dl/pack_search/procedures/nibl.py : 21%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2016 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of xdcc-dl.
6xdcc-dl is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11xdcc-dl is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with xdcc-dl. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import requests
21from typing import List
22from bs4 import BeautifulSoup
23from xdcc_dl.entities.XDCCPack import XDCCPack
24from xdcc_dl.entities.IrcServer import IrcServer
25from puffotter.units import byte_string_to_byte_count
28def find_nibl_packs(search_phrase: str) -> List[XDCCPack]:
29 """
30 Searches for XDCC Packs matching the specified search string on nibl.co.uk
32 :param search_phrase: The search phrase to search for
33 :return: The list of found XDCC Packs
34 """
35 query = "+".join(search_phrase.split(" "))
36 url = f"https://nibl.co.uk/search?query={query}"
37 html = requests.get(url).text
39 content = BeautifulSoup(html, "html.parser")
40 rows = content.find_all("tr")
42 if len(rows) == 0:
43 return []
45 header = rows.pop(0)
46 keys = [x.text for x in header.find_all("th")]
47 results = [
48 {
49 keys[i]: column.text.strip()
50 for i, column in enumerate(row.find_all("td"))
51 }
52 for row in rows
53 ]
55 server = IrcServer("irc.rizon.net")
56 packs = []
57 for result in results:
58 pack = XDCCPack(server, result["Bot"], int(result["Pack"]))
59 pack.set_size(byte_string_to_byte_count(result["Size"]))
60 pack.set_filename(result["Filename"])
61 packs.append(pack)
62 return packs