-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
178 lines (143 loc) · 7.93 KB
/
main.py
File metadata and controls
178 lines (143 loc) · 7.93 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf8 -*-
import requests
from bs4 import BeautifulSoup
from discord_webhooks import DiscordWebhooks
import json
from PyQt5 import QtWidgets
import sys
from design import Ui_Main
from settings import Ui_Settings
#TODO: Добавить Color Picker
#Creaate App
app = QtWidgets.QApplication(sys.argv)
#init
Dialog = QtWidgets.QDialog()
ui = Ui_Main()
ui.setupUi(Dialog)
Dialog.show()
#Create App Settings
app2 = QtWidgets.QApplication(sys.argv)
Settings = QtWidgets.QDialog()
ui2 = Ui_Settings()
ui2.setupUi(Settings)
# URL = 'http://101kinopoisk.com/films/drama/28748-ekstaz-2018.html'
#Обход защиты от скриптов
HEADERS = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; RMX1941 Build/PPR1.180610.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/269.0.0.50.127;]'
}
def get_html(url):
r = requests.get(url, headers=HEADERS)
return r
def push_content(html, url):
soup = BeautifulSoup(html, 'html.parser')
table = []
for td in soup.find('table').parent.find_all('td'):
table.append(td.getText())
title = soup.find('div', class_='b-post__title').get_text()
description = soup.find('div', class_='b-post__description_text').get_text(strip=True)
image = soup.find('div', class_='b-sidecover').find('img').get('src')
rate_KP = soup.find('span', class_='b-post__info_rates kp').find('span').get_text()
rate_imdb = soup.find('span', class_='b-post__info_rates imdb').find('span').get_text()
with open('settings_file.json', 'r') as j:
json_data = json.load(j)
webhook = DiscordWebhooks(json_data[0]['DiscordWebhook'])
if ui.aboutSend.currentText() == 'Фильм' or ui.aboutSend.currentText() == 'Мультфильм':
webhook.set_content(title=f'{ui.smile1.currentText()} **{title}** {ui.smile2.currentText()}', url=url, color=0x00AAFF)
webhook.add_field(inline=True, name='Слоган', value=table[3])
webhook.add_field(inline=True, name='Режисер', value=table[9])
webhook.add_field(name='Информация о фильме', value=f'*{description}*')
webhook.add_field(name='Смотреть онлайн бесплатно', value=f'{url}')
webhook.set_thumbnail(url=image)
webhook.set_image(url=image)
webhook.set_author(name=json_data[0]['UserName'], url=json_data[0]['UserLink'],
icon_url=json_data[0]['UserImage'])
webhook.add_field(inline=True, name=':map: Страна:', value=table[7])
webhook.add_field(inline=True, name=':flag_ru: Рейтинг Кинопоиск: ', value=f'{rate_KP}')
webhook.add_field(inline=True, name=':flag_us: Рейтинг IMDb: ', value=f'{rate_imdb}')
webhook.set_footer(
text=f'Дата выхода {table[5]} | Длительность фильма {table[19]}\nВозрасное ограничение {table[17]}',
icon_url='https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngpix.com%2Fwp-content%2Fuploads%2F2016%2F07%2FPNGPIX-COM-Popcorn-PNG-Image.png&f=1&nofb=1')
elif ui.aboutSend.currentText() == 'Сериал':
webhook.set_content(title=f'{ui.smile1.currentText()} **{title}** {ui.smile2.currentText()}', url=url,
color=0x00AAFF)
webhook.add_field(inline=True, name='Режисер', value=table[9])
webhook.add_field(name='Информация о фильме', value=f'*{description}*')
webhook.add_field(name='Смотреть онлайн бесплатно', value=f'{url}')
webhook.set_thumbnail(url=image)
webhook.set_image(url=image)
webhook.set_author(name=json_data[0]['UserName'], url=json_data[0]['UserLink'],
icon_url=json_data[0]['UserImage'])
webhook.add_field(inline=True, name=':map: Страна:', value=table[7])
webhook.add_field(inline=True, name=':flag_ru: Рейтинг Кинопоиск: ', value=f'{rate_KP}')
webhook.add_field(inline=True, name=':flag_us: Рейтинг IMDb: ', value=f'{rate_imdb}')
webhook.set_footer(
text=f'Дата выхода {table[5]} | Длительность фильма {table[17]}\nВозрасное ограничение {table[15]}',
icon_url='https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngpix.com%2Fwp-content%2Fuploads%2F2016%2F07%2FPNGPIX-COM-Popcorn-PNG-Image.png&f=1&nofb=1')
elif ui.aboutSend.currentText() == 'Аниме':
webhook.set_content(title=f'{ui.smile1.currentText()} **{title}** {ui.smile2.currentText()}', url=url,
color=0x00AAFF)
webhook.add_field(inline=True, name='Слоган', value=table[5])
webhook.add_field(inline=True, name='Режисер', value=table[11])
webhook.add_field(name='Информация о фильме', value=f'*{description}*')
webhook.add_field(name='Смотреть онлайн бесплатно', value=f'{url}')
webhook.set_thumbnail(url=image)
webhook.set_image(url=image)
webhook.set_author(name=json_data[0]['UserName'], url=json_data[0]['UserLink'],
icon_url=json_data[0]['UserImage'])
webhook.add_field(inline=True, name=':map: Страна:', value=table[9])
webhook.add_field(inline=True, name=':flag_ru: Рейтинг Кинопоиск: ', value=f'{rate_KP}')
webhook.add_field(inline=True, name=':flag_us: Рейтинг IMDb: ', value=f'{rate_imdb}')
webhook.set_footer(
text=f'Дата выхода {table[7]} | Длительность фильма {table[19]}',
icon_url='https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngpix.com%2Fwp-content%2Fuploads%2F2016%2F07%2FPNGPIX-COM-Popcorn-PNG-Image.png&f=1&nofb=1')
# #Отправка в Discord
webhook.send()
def settings():
Settings.show()
try:
with open('settings_file.json', 'r') as j:
json_data = json.load(j)
ui2.lineEdit_UserName.setText(json_data[0]['UserName'])
ui2.lineEdit_UserLink.setText(json_data[0]['UserLink'])
ui2.lineEdit_UserImage.setText(json_data[0]['UserImage'])
ui2.lineEdit_color.setText(json_data[0]['UserColor'])
ui2.lineEdit_UserWebhook.setText(json_data[0]['DiscordWebhook'])
except:
print('Поля не должны быть пустыми!')
ui2.pushButton.clicked.connect(lambda: settings_send())
ui2.pushButton_Cancel.clicked.connect(lambda: Settings.close())
def settings_send():
user = [
{
'UserName': ui2.lineEdit_UserName.text(),
'UserLink': ui2.lineEdit_UserLink.text(),
'UserImage': ui2.lineEdit_UserImage.text(),
'UserColor': ui2.lineEdit_color.text(),
'DiscordWebhook': ui2.lineEdit_UserWebhook.text()
}
]
with open('settings_file.json', 'w') as file:
json.dump(user, file)
Settings.close()
def parser():
url = ui.lineEdit_link.text()
if url == '':
print('Поле с ссылкой пустое! Заполняю контентом по умолчанию')
ui.lineEdit_link.setText('http://getkinopoisk.com/films/horror/549-sinister-2012.html')
else:
try:
html = get_html(url)
try:
push_content(html.text, url)
print('Сообщение успешно отправлено!')
except:
print('Error Discord Send')
except:
print('Ошибка!\nДанный URL заблокирован или введен не верно!')
#code
# print(type(0xAD16F0)) # Открытие века!
ui.pushButton.clicked.connect(lambda: parser())
ui.toolButton.clicked.connect(lambda: settings())
# Main Loop
sys.exit(app.exec_())