def noaddUsers(users, remove=False, reason=None): users = set(users) if not users: return 0 with vk.api.api_lock: if remove: prev_len = len(check_friend.noadd) check_friend.noadd -= users check_friend.writeNoadd() return prev_len - len(check_friend.noadd) else: users -= check_friend.noadd users.discard(vk.admin) if not users: return 0 text_msg = 'Deleting ' + ', '.join( [vk.printableSender({'user_id': i}, False) for i in users]) + (' ({})'.format(reason) if reason else '') html_msg = 'Deleting ' + ', '.join( [vk.printableSender({'user_id': i}, True) for i in users]) + (' ({})'.format(reason) if reason else '') log.info((text_msg, html_msg)) check_friend.appendNoadd(users) vk.deleteFriend(users) return len(users)
def main(a, args): friends = scriptlib.getFriends(a, fields='can_write_private_message') to_del = [] for j in friends: if not j['can_write_private_message']: to_del.append(str(j['id'])) logging.info('Found id{} ({} {})'.format(j['id'], j['first_name'], j['last_name'])) check_friend.appendNoadd(to_del)
def noaddUsers(users, remove=False, reason=None): users = set(users) if not users: return 0 with vk.api.api_lock: if remove: prev_len = len(check_friend.noadd) check_friend.noadd -= users check_friend.writeNoadd() return prev_len - len(check_friend.noadd) else: users -= check_friend.noadd users.discard(vk.admin) if not users: return 0 text_msg = 'Deleting ' + ', '.join([vk.printableSender({'user_id':i}, False) for i in users]) + (' ({})'.format(reason) if reason else '') html_msg = 'Deleting ' + ', '.join([vk.printableSender({'user_id':i}, True) for i in users]) + (' ({})'.format(reason) if reason else '') log.info((text_msg, html_msg)) check_friend.appendNoadd(users) vk.deleteFriend(users) return len(users)
def main(a, args): days = config.get('delfriends.days_till_unfriend', 'i') prepare = 'prepare' in args if prepare: f = open(accounts.getFile('_delfriends.txt'), 'w') else: try: f = set(map(int, open(accounts.getFile('_delfriends.txt')).read().split())) except FileNotFoundError: logging.info('_delfriends.txt not found') return friends = scriptlib.getFriends(a) now = time.time() to_del = [] cnt = 0 def checkHistory(req, resp): nonlocal cnt if resp['count'] == 0 or now - resp['items'][0]['date'] > 3600 * 24 * days: if prepare: f.write(str(req['user_id']) + '\n') else: to_del.append(str(req['user_id'])) logging.info('Found ' + str(req['user_id'])) cnt += 1 for i in friends: if not prepare and i not in f: continue a.messages.getHistory.delayed(count=1, user_id=i).callback(checkHistory) a.sync() if prepare: f.close() else: check_friend.appendNoadd(to_del) logging.info('Total: ' + str(cnt))