Skip to content

Commit f622e65

Browse files
committed
Refactoring and cleaning the code, updating unittests
1 parent 9d7e73f commit f622e65

File tree

14 files changed

+472
-1978
lines changed

14 files changed

+472
-1978
lines changed

core_class/core_class.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
5+
# Основной класс, реализующий парсинг процесс всего проекта
6+
class Parsing:
7+
headers = {
8+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'}
9+
10+
def __init__(self, link, html_class_parsing, name):
11+
self.link = link
12+
self.html_class_parsing = html_class_parsing
13+
self.name = name
14+
15+
def get_data(self):
16+
# Парсим всю страницу
17+
full_page = requests.get(self.link, headers=self.headers)
18+
19+
# Разбираем через BeautifulSoup
20+
soup = BeautifulSoup(full_page.content, 'html.parser')
21+
22+
# Получаем нужное для нас значение и возвращаем его
23+
convert = soup.findAll("span", self.html_class_parsing)
24+
return f'{self.name}{convert[0].text}'

cryptocurrencies/crypto.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,49 @@
11
import requests
22
from bs4 import BeautifulSoup
3+
from WarrenBuffetBot.core_class.core_class import Parsing
34

45

5-
class Cryptocurrencies:
6-
headers = {
7-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'}
8-
9-
def __init__(self, link_to_cryptocurrency, html_class_parsing, name_cryptocurrency):
10-
self.link_to_cryptocurrency = link_to_cryptocurrency
11-
self.html_class_parsing = html_class_parsing
12-
self.name_cryptocurrency = name_cryptocurrency
13-
14-
def get_cryptocurrency_value(self):
6+
class Cryptocurrencies(Parsing):
7+
def get_data(self):
158
# Парсим всю страницу
16-
full_page = requests.get(self.link_to_cryptocurrency, headers=self.headers)
9+
full_page = requests.get(self.link, headers=self.headers)
1710

1811
# Разбираем через BeautifulSoup
1912
soup = BeautifulSoup(full_page.content, 'html.parser')
2013

2114
# Получаем нужное для нас значение и возвращаем его
2215
convert = soup.findAll("span", self.html_class_parsing)
23-
return f'{self.name_cryptocurrency}{convert[0].text}'
16+
return f'{self.name}{convert[0].text}'
2417

2518
bitcoin = Cryptocurrencies('https://ru.investing.com/crypto/bitcoin', html_class_parsing={'class': 'pid-1057391-last'},
26-
name_cryptocurrency='Bitcoin ➡ ')
19+
name='Bitcoin ➡ ')
2720
ethereum = Cryptocurrencies('https://ru.investing.com/crypto/ethereum/eth-usd', html_class_parsing={'class': 'text-2xl'},
28-
name_cryptocurrency='Ethereum ➡ ')
21+
name='Ethereum ➡ ')
2922
litecoin = Cryptocurrencies('https://ru.investing.com/crypto/litecoin', html_class_parsing={'class': 'pid-1061445-last'},
30-
name_cryptocurrency='Litecoin ➡ ')
23+
name='Litecoin ➡ ')
3124
cardano = Cryptocurrencies('https://ru.investing.com/crypto/cardano/ada-usd', html_class_parsing={'class': 'text-2xl'},
32-
name_cryptocurrency='Cardano ➡ ')
25+
name='Cardano ➡ ')
3326
xrp = Cryptocurrencies('https://ru.investing.com/crypto/xrp/xrp-usd', html_class_parsing={'class': 'text-2xl'},
34-
name_cryptocurrency='XRP ➡ ')
27+
name='XRP ➡ ')
3528
doge = Cryptocurrencies('https://ru.investing.com/crypto/dogecoin/doge-usd', html_class_parsing={'class': 'text-2xl'},
36-
name_cryptocurrency='DOGE ➡ ')
29+
name='DOGE ➡ ')
3730
bnb = Cryptocurrencies('https://ru.investing.com/crypto/binance-coin', html_class_parsing={'class': 'pid-1061448-last'},
38-
name_cryptocurrency='BNB ➡ ')
31+
name='BNB ➡ ')
3932
tether = Cryptocurrencies('https://ru.investing.com/crypto/tether', html_class_parsing={'class': 'pid-1061453-last'},
40-
name_cryptocurrency='Tether ➡ ')
33+
name='Tether ➡ ')
4134
solana = Cryptocurrencies('https://ru.investing.com/crypto/solana', html_class_parsing={'class': 'pid-1177183-last'},
42-
name_cryptocurrency='Solana ➡ ')
35+
name='Solana ➡ ')
4336
luna = Cryptocurrencies('https://ru.investing.com/crypto/terra-luna', html_class_parsing={'class': 'pid-1177187-last'},
44-
name_cryptocurrency='Luna ➡ ')
37+
name='Luna ➡ ')
4538
uniswap = Cryptocurrencies('https://ru.investing.com/crypto/uniswap', html_class_parsing={'class': 'pid-1177189-last'},
46-
name_cryptocurrency='UniSwap ➡ ')
39+
name='UniSwap ➡ ')
4740
polkadot = Cryptocurrencies('https://ru.investing.com/crypto/polkadot-new', html_class_parsing={'class': 'pid-1177185-last'},
48-
name_cryptocurrency='Polkadot ➡ ')
41+
name='Polkadot ➡ ')
4942
avalanche = Cryptocurrencies('https://ru.investing.com/crypto/avalanche', html_class_parsing={'class': 'pid-1177190-last'},
50-
name_cryptocurrency='Avalanche ➡ ')
43+
name='Avalanche ➡ ')
5144
chainlink = Cryptocurrencies('https://ru.investing.com/crypto/chainlink', html_class_parsing={'class': 'pid-1061794-last'},
52-
name_cryptocurrency='Chainlink ➡ ')
45+
name='Chainlink ➡ ')
5346
tron = Cryptocurrencies('https://ru.investing.com/crypto/tron', html_class_parsing={'class': 'pid-1061450-last'},
54-
name_cryptocurrency='Tron ➡ ')
47+
name='Tron ➡ ')
5548
shiba = Cryptocurrencies('https://ru.investing.com/crypto/shiba-inu', html_class_parsing={'class': 'pid-1177506-last'},
56-
name_cryptocurrency='SHIBA ➡ ')
49+
name='SHIBA ➡ ')

finviz_api.py

Whitespace-only changes.

0 commit comments

Comments
 (0)