AttributeError: 'PySide.QtCore.Signal' object has no attribute 'connect'
Пишу скрипт с графическим интерфейсом на PySide, Python 3.4. Мне необходимо использовать многопоточность, т. к. нужно, чтобы были открыты окно с интерфейсом и окно браузера. Пытаюсь её использовать, но ничего не получается (когда нажиммаю на Start (функция в самом конце), питон выдаёт ошибку (AttributeError: 'PySide.QtCore.Signal' object has no attribute 'connect')) Код (главный файл):
from PySide import QtCore, QtGui
import sys
from inst1 import Ui_Form
import threading
from time import sleep as delay
from datetime import datetime
from selenium import webdriver
import script1
ui = Ui_Form()
def start_app():
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui.setupUi(Form)
Form.show()
mainthread = threading.Thread(target=start_app)
mainthread.start()
mainthread.join()
def set_status(text):
ui.status_l.setText(text)
# select files
def select_mail_1():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_4.setText(fname[0])
set_status("Ready.")
def select_mail_2():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_6.setText(fname[0])
set_status("Ready.")
def select_imap_1():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_7.setText(fname[0])
set_status("Ready.")
def select_imap_2():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_9.setText(fname[0])
set_status("Ready.")
def select_proxy():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_5.setText(fname[0])
set_status("Ready.")
def select_name():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_8.setText(fname[0])
set_status("Ready.")
def select_name_2():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_10.setText(fname[0])
set_status("Ready.")
def select_drv():
set_status("Selecting file")
fname = QtGui.QFileDialog.getOpenFileName()
ui.lineEdit_11.setText(fname[0])
set_status("Ready.")
ui.select_mail.clicked.connect(select_mail_1)
ui.select_mail_2.clicked.connect(select_mail_2)
ui.select_imap_2.clicked.connect(select_imap_1)
ui.select_imap_3.clicked.connect(select_imap_2)
ui.select_mail_3.clicked.connect(select_proxy)
ui.select_mail_4.clicked.connect(select_name)
ui.select_mail_5.clicked.connect(select_name_2)
ui.select_mail_6.clicked.connect(select_drv)
def logger1(text):
ui.textEdit.setPlainText(ui.textEdit.toPlainText()+'['+str(datetime.now())+'] '+str(text)+'\n')
logger1("Ready.")
driv = 'C:\chromedriver.exe'
def script_s():
script1.counting_f()
while True:
if accounts == script1.needest:
break
logger1(script1.set_proxies(ui.lineEdit_5.text()))
logger1(script1.getting_instagram(driv))
logger1(script1.change_language())
logger1(script1.changing_pass(ui.lineEdit_4.text()))
delay(30)
logger1(script1.conf_changing_pass(ui.lineEdit_7.text(), ui.lineEdit_8.text()))
logger1(script1.change_v_name(ui.lineEdit_10.text()))
logger1(script1.change_name())
logger1(script1.change_email(ui.lineEdit_6.text()))
delay(30)
logger1(script1.confirming_email(ui.lineEdit_7.text()))
logger1(script1.exiting_account())
logger1("Next account number " + str((script1.needest + 1)) + "...")
def start():
global accounts
accounts = sum(1 for _ in open(ui.lineEdit_4.text(), 'r'))
logger1("Started.")
logger1("Getting info from files.")
logger1("There is {} accounts in files.".format(accounts))
thread = threading.Thread(target=script_s)
thread.start()
thread.join()
ui.pushButton.clicked.connect(start)
sys.exit(app.exec_())
Код файла inst1 (не самое важное здесь, но чтобы был весь код, выкладываю):
from PySide import QtCore, QtGui
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowIcon(QtGui.QIcon('icon.ico'))
Form.setWindowModality(QtCore.Qt.ApplicationModal)
Form.setEnabled(True)
Form.resize(600, 325)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
Form.setSizePolicy(sizePolicy)
Form.setMinimumSize(QtCore.QSize(600, 325))
Form.setMaximumSize(QtCore.QSize(600, 325))
Form.setAutoFillBackground(False)
self.mdiArea = QtGui.QMdiArea(Form)
self.mdiArea.setGeometry(QtCore.QRect(0, 310, 611, 161))
self.mdiArea.setObjectName("mdiArea")
self.status_l = QtGui.QLabel(Form)
self.status_l.setGeometry(QtCore.QRect(10, 310, 581, 16))
self.status_l.setObjectName("status_l")
self.tabWidget = QtGui.QTabWidget(Form)
self.tabWidget.setGeometry(QtCore.QRect(0, 0, 601, 311))
self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.tabWidget.setTabsClosable(False)
self.tabWidget.setMovable(False)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtGui.QWidget()
self.tab.setObjectName("tab")
self.groupBox_5 = QtGui.QGroupBox(self.tab)
self.groupBox_5.setGeometry(QtCore.QRect(180, 170, 181, 111))
self.groupBox_5.setCheckable(True)
self.groupBox_5.setChecked(True)
self.groupBox_5.setObjectName("groupBox_5")
self.lineEdit_5 = QtGui.QLineEdit(self.groupBox_5)
self.lineEdit_5.setGeometry(QtCore.QRect(10, 40, 111, 20))
self.lineEdit_5.setObjectName("lineEdit_5")
self.label_5 = QtGui.QLabel(self.groupBox_5)
self.label_5.setGeometry(QtCore.QRect(10, 20, 171, 16))
self.label_5.setObjectName("label_5")
self.label_8 = QtGui.QLabel(self.groupBox_5)
self.label_8.setGeometry(QtCore.QRect(10, 60, 211, 20))
self.label_8.setObjectName("label_8")
self.spinBox = QtGui.QSpinBox(self.groupBox_5)
self.spinBox.setGeometry(QtCore.QRect(10, 80, 42, 22))
self.spinBox.setButtonSymbols(QtGui.QAbstractSpinBox.UpDownArrows)
self.spinBox.setMaximum(999)
self.spinBox.setProperty("value", 1)
self.spinBox.setObjectName("spinBox")
self.label_2 = QtGui.QLabel(self.groupBox_5)
self.label_2.setGeometry(QtCore.QRect(60, 80, 61, 21))
self.label_2.setObjectName("label_2")
self.select_mail_3 = QtGui.QPushButton(self.groupBox_5)
self.select_mail_3.setGeometry(QtCore.QRect(130, 40, 41, 23))
self.select_mail_3.setObjectName("select_mail_3")
self.groupBox_3 = QtGui.QGroupBox(self.tab)
self.groupBox_3.setGeometry(QtCore.QRect(180, 10, 401, 71))
self.groupBox_3.setObjectName("groupBox_3")
self.label_4 = QtGui.QLabel(self.groupBox_3)
self.label_4.setGeometry(QtCore.QRect(10, 20, 171, 16))
self.label_4.setObjectName("label_4")
self.select_mail = QtGui.QPushButton(self.groupBox_3)
self.select_mail.setGeometry(QtCore.QRect(130, 40, 41, 23))
self.select_mail.setObjectName("select_mail")
self.lineEdit_4 = QtGui.QLineEdit(self.groupBox_3)
self.lineEdit_4.setGeometry(QtCore.QRect(10, 40, 111, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.label_7 = QtGui.QLabel(self.groupBox_3)
self.label_7.setGeometry(QtCore.QRect(190, 20, 161, 16))
self.label_7.setObjectName("label_7")
self.lineEdit_7 = QtGui.QLineEdit(self.groupBox_3)
self.lineEdit_7.setGeometry(QtCore.QRect(190, 40, 111, 20))
self.lineEdit_7.setObjectName("lineEdit_7")
self.select_imap_2 = QtGui.QPushButton(self.groupBox_3)
self.select_imap_2.setGeometry(QtCore.QRect(310, 40, 41, 23))
self.select_imap_2.setObjectName("select_imap_2")
self.groupBox_4 = QtGui.QGroupBox(self.tab)
self.groupBox_4.setGeometry(QtCore.QRect(180, 90, 401, 71))
self.groupBox_4.setObjectName("groupBox_4")
self.label_6 = QtGui.QLabel(self.groupBox_4)
self.label_6.setGeometry(QtCore.QRect(10, 20, 171, 16))
self.label_6.setObjectName("label_6")
self.select_mail_2 = QtGui.QPushButton(self.groupBox_4)
self.select_mail_2.setGeometry(QtCore.QRect(130, 40, 41, 23))
self.select_mail_2.setObjectName("select_mail_2")
self.lineEdit_6 = QtGui.QLineEdit(self.groupBox_4)
self.lineEdit_6.setGeometry(QtCore.QRect(10, 40, 111, 20))
self.lineEdit_6.setObjectName("lineEdit_6")
self.label_9 = QtGui.QLabel(self.groupBox_4)
self.label_9.setGeometry(QtCore.QRect(190, 20, 161, 16))
self.label_9.setObjectName("label_9")
self.lineEdit_9 = QtGui.QLineEdit(self.groupBox_4)
self.lineEdit_9.setGeometry(QtCore.QRect(190, 40, 111, 20))
self.lineEdit_9.setObjectName("lineEdit_9")
self.select_imap_3 = QtGui.QPushButton(self.groupBox_4)
self.select_imap_3.setGeometry(QtCore.QRect(310, 40, 41, 23))
self.select_imap_3.setObjectName("select_imap_3")
self.groupBox = QtGui.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(370, 170, 211, 111))
self.groupBox.setObjectName("groupBox")
self.checkBox = QtGui.QCheckBox(self.groupBox)
self.checkBox.setGeometry(QtCore.QRect(10, 20, 201, 17))
self.checkBox.setObjectName("checkBox")
self.dateEdit = QtGui.QDateEdit(self.groupBox)
self.dateEdit.setEnabled(True)
self.dateEdit.setGeometry(QtCore.QRect(10, 40, 110, 22))
self.dateEdit.setWrapping(False)
self.dateEdit.setFrame(True)
self.dateEdit.setEnabled(False)
self.dateEdit.setCalendarPopup(False)
self.dateEdit.setTimeSpec(QtCore.Qt.UTC)
self.dateEdit.setObjectName("dateEdit")
self.checkBox_2 = QtGui.QCheckBox(self.groupBox)
self.checkBox_2.setGeometry(QtCore.QRect(10, 70, 181, 17))
self.checkBox_2.setObjectName("checkBox_2")
self.checkBox_3 = QtGui.QCheckBox(self.groupBox)
self.checkBox_3.setGeometry(QtCore.QRect(10, 90, 181, 17))
self.checkBox_3.setObjectName("checkBox_3")
self.groupBox_2 = QtGui.QGroupBox(self.tab)
self.groupBox_2.setGeometry(QtCore.QRect(10, 170, 161, 51))
self.groupBox_2.setObjectName("groupBox_2")
self.select_mail_4 = QtGui.QPushButton(self.groupBox_2)
self.select_mail_4.setGeometry(QtCore.QRect(110, 20, 41, 23))
self.select_mail_4.setObjectName("select_mail_4")
self.lineEdit_8 = QtGui.QLineEdit(self.groupBox_2)
self.lineEdit_8.setGeometry(QtCore.QRect(10, 20, 91, 20))
self.lineEdit_8.setObjectName("lineEdit_8")
self.groupBox_6 = QtGui.QGroupBox(self.tab)
self.groupBox_6.setGeometry(QtCore.QRect(10, 230, 161, 51))
self.groupBox_6.setObjectName("groupBox_6")
self.select_mail_5 = QtGui.QPushButton(self.groupBox_6)
self.select_mail_5.setGeometry(QtCore.QRect(110, 20, 41, 23))
self.select_mail_5.setObjectName("select_mail_5")
self.lineEdit_10 = QtGui.QLineEdit(self.groupBox_6)
self.lineEdit_10.setGeometry(QtCore.QRect(10, 20, 91, 20))
self.lineEdit_10.setObjectName("lineEdit_10")
self.groupBox_7 = QtGui.QGroupBox(self.tab)
self.groupBox_7.setGeometry(QtCore.QRect(10, 10, 161, 151))
self.groupBox_7.setObjectName("groupBox_7")
self.select_mail_6 = QtGui.QPushButton(self.groupBox_7)
self.select_mail_6.setGeometry(QtCore.QRect(110, 40, 41, 21))
self.select_mail_6.setObjectName("select_mail_6")
self.lineEdit_11 = QtGui.QLineEdit(self.groupBox_7)
self.lineEdit_11.setGeometry(QtCore.QRect(10, 40, 91, 20))
self.lineEdit_11.setObjectName("lineEdit_11")
self.label = QtGui.QLabel(self.groupBox_7)
self.label.setGeometry(QtCore.QRect(10, 22, 46, 16))
self.label.setObjectName("label")
self.label_3 = QtGui.QLabel(self.groupBox_7)
self.label_3.setGeometry(QtCore.QRect(10, 60, 51, 16))
self.label_3.setObjectName("label_3")
self.lineEdit_12 = QtGui.QLineEdit(self.groupBox_7)
self.lineEdit_12.setGeometry(QtCore.QRect(10, 80, 141, 20))
self.lineEdit_12.setObjectName("lineEdit_12")
self.label_10 = QtGui.QLabel(self.groupBox_7)
self.label_10.setGeometry(QtCore.QRect(10, 100, 71, 16))
self.label_10.setObjectName("label_10")
self.lineEdit_13 = QtGui.QLineEdit(self.groupBox_7)
self.lineEdit_13.setGeometry(QtCore.QRect(10, 120, 141, 20))
self.lineEdit_13.setObjectName("lineEdit_13")
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtGui.QWidget()
self.tab_2.setObjectName("tab_2")
self.progressBar = QtGui.QProgressBar(self.tab_2)
self.progressBar.setGeometry(QtCore.QRect(10, 260, 491, 23))
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.pushButton = QtGui.QPushButton(self.tab_2)
self.pushButton.setGeometry(QtCore.QRect(510, 260, 75, 23))
self.pushButton.setObjectName("pushButton")
self.textEdit = QtGui.QTextEdit(self.tab_2)
self.textEdit.setGeometry(QtCore.QRect(0, 0, 591, 251))
self.textEdit.setReadOnly(True)
self.textEdit.setObjectName("textEdit")
self.tabWidget.addTab(self.tab_2, "")
self.retranslateUi(Form)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Instagram soft", None, QtGui.QApplication.UnicodeUTF8))
self.status_l.setText(QtGui.QApplication.translate("Form", "Wait...", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_5.setTitle(QtGui.QApplication.translate("Form", "Прокси", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("Form", "Файл с прокси", None, QtGui.QApplication.UnicodeUTF8))
self.label_8.setText(QtGui.QApplication.translate("Form", "Смена прокси каждые", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Form", "аккаунтов", None, QtGui.QApplication.UnicodeUTF8))
self.select_mail_3.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_3.setTitle(QtGui.QApplication.translate("Form", "Исходные почты", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("Form", "Файл с почтами и паролями", None, QtGui.QApplication.UnicodeUTF8))
self.select_mail.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.label_7.setText(QtGui.QApplication.translate("Form", "Файл с IMAP серверами", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_7.setText(QtGui.QApplication.translate("Form", "imap.txt", None, QtGui.QApplication.UnicodeUTF8))
self.select_imap_2.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_4.setTitle(QtGui.QApplication.translate("Form", "Новые почты", None, QtGui.QApplication.UnicodeUTF8))
self.label_6.setText(QtGui.QApplication.translate("Form", "Файл с почтами и паролями", None, QtGui.QApplication.UnicodeUTF8))
self.select_mail_2.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.label_9.setText(QtGui.QApplication.translate("Form", "Файл с IMAP серверами", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_9.setText(QtGui.QApplication.translate("Form", "imap.txt", None, QtGui.QApplication.UnicodeUTF8))
self.select_imap_3.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("Form", "Прочие настройки", None, QtGui.QApplication.UnicodeUTF8))
self.checkBox.setText(QtGui.QApplication.translate("Form", "Минимальная дата регистрации", None, QtGui.QApplication.UnicodeUTF8))
self.checkBox_2.setText(QtGui.QApplication.translate("Form", "Закрывать страницу", None, QtGui.QApplication.UnicodeUTF8))
self.checkBox_3.setText(QtGui.QApplication.translate("Form", "Очищать BIO, сайт", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_2.setTitle(QtGui.QApplication.translate("Form", "Имя пользователя", None, QtGui.QApplication.UnicodeUTF8))
self.select_mail_4.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_6.setTitle(QtGui.QApplication.translate("Form", "Отображаемое имя", None, QtGui.QApplication.UnicodeUTF8))
self.select_mail_5.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_7.setTitle(QtGui.QApplication.translate("Form", "Системные настройки", None, QtGui.QApplication.UnicodeUTF8))
self.select_mail_6.setText(QtGui.QApplication.translate("Form", "Select", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "Драйвер", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("Form", "Файл лога", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_12.setText(QtGui.QApplication.translate("Form", "log.txt", None, QtGui.QApplication.UnicodeUTF8))
self.label_10.setText(QtGui.QApplication.translate("Form", "Файл вывода", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_13.setText(QtGui.QApplication.translate("Form", "out.txt", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("Form", "1. Конфигурация", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form", "Запустить", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("Form", "2. Выполнение", None, QtGui.QApplication.UnicodeUTF8))
Код файла script1:
from selenium import webdriver
import imap
import time
def counting_f():
global needest
needest = 0
def set_proxies(proxyfile):
global proxies
global service_args
try:
proxies = []
with open(proxyfile, 'r') as f:
for line in f:
line = line.strip()
proxies.append(line.split(":"))
proxy_now_proxy = proxies[needest][0]
proxy_now_port = proxies[needest][1]
service_args = ['--proxy='+proxy_now_proxy+':'+proxy_now_port, '--proxy-type=socks5']
except:
return 'Error when starting proxy. Please, restart program and try again.'
else:
return 'Succesfully started proxy!'
def getting_instagram(driv):
try:
driver = webdriver.Chrome(driv1, service_args=service_args)
driver.get("https://instagram.com")
except:
return 'Error when getting on instagram.com. Please, restart program and try again.'
else:
return 'Succesfully got instagram.com!'
def change_language():
try:
language = driver.find_element_by_xpath("//div[@id='react-root']/section/footer/div/nav/ul/li/span/select")
language.click()
language.send_keys("English\n")
except:
return 'Error when changing language. Please, restart program and try again.'
else:
return 'Successfully changed language!'
def changing_pass(oldmails):
global mails
try:
driver.get('https://instagram.com/accounts/password/reset')
input_email = driver.find_element_by_xpath("//div[@id='react-root']/section/main/div/div/div/div/form/label/input")
mails = []
with open(oldmails, 'r') as f:
for line in f:
line = line.strip()
mails.append(line.split(':'))
input_email.send_keys(mails[needest][0])
submit_button = driver.find_element_by_xpath("//div[@id='react-root']/section/main/div/div/div/div/button")
submit_button.click()
except:
return 'Error when changing password. Please, restart program and try again.'
else:
return 'Succesfully sended mail!'
def conf_changing_pass(imaps, names):
global names_and_passwords1
try:
imap.change_password(mails[needest][0], mails[needest][1], imaps)
driver.get(imap.str1)
password_input = driver.find_element_by_xpath("//input[@id='id_enc_new_password1']")
password_reinput = driver.find_element_by_xpath("//input[@id='id_enc_new_password2']")
password_button = driver.find_element_by_xpath("//body/div/div/div/div/section/form/p/input[@value='Reset Password']")
names_and_passwords1 = []
with open(names, 'r') as f:
for line in f:
line = line.strip()
names_and_passwords1.append(line.split(":"))
password_input.send_keys(names_and_passwords1[needest][1])
password_reinput.send_keys(names_and_passwords1[needest][1])
password_button.click()
except:
return 'Error when confirming change password. Please, restart the program and try again.'
else:
return 'Successfully confirmed change password!'
def change_v_name(v_names):
global v_names1
try:
driver.get('https://instagram.com/accounts/edit')
v_name_input = driver.find_element_by_xpath("//div[@id='react-root']/section/main/div/article/form/div/div/div/input[@id='pepName']")
v_names1 = []
with open(v_names, 'r') as f:
for line in f:
line = line.strip()
v_names1.append(line)
v_name_input.send_keys(v_names1[needest])
except:
return 'Error when changing name. Please, restart the program and try again.'
else:
return 'Succesfully changed name!'
def change_name():
try:
name_input = driver.find_element_by_xpath("//div[@id='react-root']/section/main/div/article/form/div/div/div/input[@id='pepUsername']")
name_input.send_keys(names_and_passwords1[needest])
except:
return 'Error when changing name. Please, restart the program and try again.'
else:
return 'Successfully changed name!'
def change_email(new):
global new_mails1
try:
new_email = driver.find_element_by_xpath("//div[@id='react-root']/section/main/div/article/form/div/div/div/input[@id='pepEmail']")
new_mails1 = []
with open(new, 'r') as f:
for line in f:
line = line.strip()
new_mails1.append(line.split(":"))
new_email.send_keys(new_mails1[needest][0])
button_submit_changes = driver.find_element_by_xpath("//div[@id='react-root']/section/main/div/article/form/div/div/div/button")
button_submit_changes.click()
except:
return 'Error when changing email and submitting changes. Please, restart the program and try again.'
else:
return 'Succesfully changed email and submitted changes!'
def confirming_email(imaps):
try:
imap.confirm_email(new_mails1[needest][0], new_mails1[needest][1], imaps)
driver.get(imap.str1)
time.sleep(5)
except:
return 'Error when confirming email. Please, restart the program and try again.'
else:
return 'Successfully confirmed email!'
def exiting_account():
try:
driver.get('https://instagram.com/' + names_and_passwords1[needest][0])
button_settings = driver.find_element_by_xpath("//div[@id='react-root]/section/main/div/header/section/div/div/button")
button_settings.click()
quit_button = driver.find_element_by_xpath("//body/div/div/div/div/div/button[@text='Выйти']")
quit_button.click()
needest += 1
except:
return 'Error when quiting account.'
else:
return 'Successfully exited from account!'
Код файла imap.py:
import imaplib
import email
def get_body(msg):
if msg.is_multipart():
return get_body(msg.get_payload(0))
else:
return msg.get_payload(None, True)
def confirm_email(username, password, servers):
global str1
mail_domain_id = (username.find("@")) + 1
mail_domain = username[mail_domain_id:]
with open(servers, 'r') as f:
for line in f:
line = line.strip()
domain, imap, port = line.split(":")
if domain == mail_domain:
break
server = imaplib.IMAP4_SSL(imap, port)
server.login(username, password)
server.select("inbox")
pismo = server.uid('search', None, '(HEADER Subject "Confirm your email address for Instagram")')
ids = []
ids = pismo[1][0].decode('utf-8').split()
pismo_id = ids[-1]
result, data = server.uid('fetch', pismo_id, '(RFC822)')
raw = email.message_from_bytes(data[0][1])
str1 = get_body(raw)
str1 = str1.decode('utf-8')
id1 = str1.find("https://instagram.com/accounts/confirm_email/")
str1 = str1[id1:]
id2 = str1.find("?")
id2 -= 1
str1 = str1[:id2]
def change_password(username, password, servers):
global str1
mail_domain_id = (username.find("@")) + 1
mail_domain = username[mail_domain_id:]
with open(servers, 'r') as f:
for line in f:
line = line.strip()
domain, imap, port = line.split(":")
if domain == mail_domain:
break
server = imaplib.IMAP4_SSL(imap, port)
server.login(username, password)
server.select()
pismo = server.uid('search', None, '(HEADER Subject "Reset Your Password")')
ids = []
ids = pismo[1][0].decode('utf-8').split()
print(ids)
pismo_id = ids[-1]
result, data = server.uid('fetch', pismo_id, '(RFC822)')
raw = email.message_from_bytes(data[0][1])
str1 = get_body(raw)
str1 = str1.decode('utf-8')
id1 = str1.find("https://instagram.com/accounts/password/reset/confirm/")
str1 = str1[id1:]
id2 = (str1.find('"'))
str1 = str1[:id2]