Answer the question
In order to leave comments, you need to log in
How to stop the cycle?
Everyone shalom
There is some code written using the PyQt library ...
class whoLike(QtWidgets.QMainWindow, who_likes.Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.whoLiked)
self.pushButton_2.clicked.connect(self.exitApp)
self.listWidget.itemClicked.connect(self.selectionChanged)
def selectionChanged(self, item):
a = ("{}".format(item.text()))
print(a)
webbrowser.open(a)
def exitApp(self):
self.close()
def whoLiked(self):
self.listWidget.clear()
response = requests.get(
'https://api.vk.com/method/friends.get?access_token=%s&v=%s&order=name' % (access_token, version))
data = response.json()
print(data)
data_fil = data['response']["items"]
len_check = len(data_fil)
print(data_fil)
mass_likes = []
i = 0
check_x = 0
for filter_data in data_fil:
response_posts = requests.get('https://api.vk.com/method/wall.get?access_token=%s&v=%s&owner_id=%s' % (
access_token, version, filter_data))
data_posts = response_posts.json()
check_x += 1
self.label_5.setText(str(check_x) + '/' + str(len_check))
i += 1
if i >= 7:
# Ждем 3 секунды
loop = QEventLoop()
QTimer.singleShot(3000, loop.quit)
loop.exec()
i = 0
else:
try:
post = data_posts['response']['items']
print(post)
for posts in post:
likes_posts = posts['likes']['user_likes']
if likes_posts == 1:
user_id = posts['owner_id']
id_post = posts['id']
url = 'https://vk.com/id%s?w=wall%s_%s' % (user_id, user_id, id_post)
mass_likes.append(url)
self.listWidget.addItem(url)
print(url)
else:
continue
except:
print('User was deleted or banned')
Answer the question
In order to leave comments, you need to log in
You have such a long cycle. what needs to be stopped with a button - redo it. This should not be in an application.
Long-running operations should be done in chunks and asynchronously.
Create a task queue. Each task should be small and atomic.
You have here, apparently, solid architectural noodles in the code.
It is not clear how you run this code, it is not clear what you have around it.
It is only clear that you have made some kind of ornate crutch here and are trying to solve a standard problem with some kind of handicraft dendrofecal method.
I can summarize everything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question