-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
202 lines (177 loc) · 8.07 KB
/
main.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from InstagramAPI import InstagramAPI
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(454, 286)
MainWindow.setStyleSheet("")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setStyleSheet("background-color: rgb(46, 52, 54);")
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 20, 181, 221))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label.setObjectName("label")
pixmap = QtGui.QPixmap("images/icon.png")
self.label.setPixmap(pixmap)
self.label.setStyleSheet("margin-left: 55;")
self.verticalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(10)
self.lineEdit.setFont(font)
self.lineEdit.setStyleSheet(
"background-color: rgb(186, 189, 182);\n"
"color: black;\n"
"text-align: center;"
)
self.lineEdit.setText("")
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout.addWidget(self.lineEdit)
self.lineEdit_2 = QtWidgets.QLineEdit(self.verticalLayoutWidget)
# self.setEchoMode(QLineEdit.Password) для маскировки пароля
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit_2.setStyleSheet(
"background-color: rgb(186, 189, 182);\n"
"color: rgb(0, 0, 0);\n"
"text-align: center;"
)
self.lineEdit_2.setInputMask("")
self.lineEdit_2.setText("")
self.lineEdit_2.setObjectName("lineEdit_2")
self.verticalLayout.addWidget(self.lineEdit_2)
self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton.setStyleSheet(
"background-color: rgba(126, 52, 161, 0.9);\n"
"color: rgb(46, 52, 54);\n"
"font-weight: bold;"
)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
self.plainTextEdit.setObjectName("plainTextEdit")
self.plainTextEdit.setGeometry(QtCore.QRect(220, 20, 211, 221))
self.plainTextEdit.setReadOnly(True)
self.plainTextEdit.setStyleSheet("background-color: rgb(186, 189, 182);\n")
self.messageBox = QtWidgets.QMessageBox()
pixmap = QtGui.QPixmap("images/okay.jpg")
self.messageBox.setIconPixmap(pixmap)
self.messageBox.setWindowTitle("Информация")
self.messageBox.setStyleSheet(
"background-color: rgb(255,255,255);\n"
"color: rgb(46, 52, 54);\n"
"font-weight: bold;\n"
"text-align: center;"
)
self.messageBox.setText("Вы вошли в аккаунт")
self.okButton = self.messageBox.addButton(
"Окей", QtWidgets.QMessageBox.AcceptRole
)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Insta Unfollower"))
self.lineEdit.setPlaceholderText(_translate("MainWindow", "логин"))
self.lineEdit_2.setPlaceholderText(_translate("MainWindow", "пароль"))
self.pushButton.setText(_translate("MainWindow", "Войти"))
self.plainTextEdit.setPlaceholderText(
_translate("MainWindow", " Результат")
)
class Main(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.buttonClicked)
def send_info(self):
""" Вывод результатов в textEdit через setPlainText"""
followers = self.get_total_followers(self.api, self.user_id)
followings = self.get_total_followings(self.api, self.user_id)
self.non_follow = self.non_followers(followers, followings)
self.total_non_followed = len(self.non_follow)
results = [
"=======================",
f"Кол-во подписчиков: {len(followers)}",
f"Кол-во подписок: {len(followings)}",
f"Кол-во неподписаных: {self.total_non_followed}",
"=======================\n",
]
return "\n".join(results)
def unfollow(self):
text = "Вы отписались от всех"
if self.total_non_followed == 0:
return text
else:
for i in range(self.total_non_followed):
if i >= self.total_non_followed:
break
user = list(self.non_follow.keys())[len(self.non_follow) - 1]
self.api.unfollow(self.non_follow[user])
self.non_follow.pop(user)
return text
def buttonClicked(self):
self.login = self.ui.lineEdit.text()
self.password = self.ui.lineEdit_2.text()
self.api = InstagramAPI(self.login, self.password)
self.sing_in = self.api.login()
try:
self.user_id = self.api.username_id
except AttributeError:
self.ui.plainTextEdit.insertPlainText(
"\u274E" + "Вход не выполнен, повторите попытку"
)
info = str(self.send_info())
unfollow = str(self.unfollow())
if self.sing_in is True:
self.ui.messageBox.exec()
if self.ui.messageBox.clickedButton() == self.ui.okButton:
self.ui.plainTextEdit.clear()
self.ui.plainTextEdit.insertPlainText(info)
self.ui.plainTextEdit.insertPlainText("\u2611" + unfollow)
else:
self.ui.plainTextEdit.insertPlainText(
"\u274E" + "Вход не выполнен, повторите попытку"
)
exit()
def get_total_followers(self, api, user_id):
followers = list()
next_max_id = True
while next_max_id:
if next_max_id is True:
next_max_id = ""
_ = self.api.getUserFollowers(self.user_id, next_max_id)
followers.extend(self.api.LastJson.get("users", []))
next_max_id = self.api.LastJson.get("next_max_id", "")
return followers
def get_total_followings(self, api, user_id):
followings = list()
next_max_id = True
while next_max_id:
if next_max_id is True:
next_max_id = ""
_ = self.api.getUserFollowings(self.user_id, next_max_id)
followings.extend(self.api.LastJson.get("users", []))
next_max_id = self.api.LastJson.get("next_max_id", "")
return followings
def non_followers(self, followers, followings):
non_followers = dict()
dict_followers = dict()
for follower in followers:
dict_followers[follower["username"]] = follower["pk"]
for followed_user in followings:
if followed_user["username"] not in dict_followers:
non_followers[followed_user["username"]] = followed_user["pk"]
return non_followers
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = Main()
window.show()
sys.exit(app.exec())