Я использовал этот скрипт в этом посте.
Это отличный скрипт Paython, и я могу удалить всех участников канала.
Но когда я попытайтесь добавить участников на мой канал, но не получится, появится сообщение об ошибке:
Traceback (most recent call last):
File "C:\exp\telethon-bot-add-users-to-groups.py", line 183, in
mode = int(input("Enter \n1-List users in a group\n2-Add users from CSV to Group (CSV must be passed as a parameter to the script\n3-Show CSV\n\nYour option: "))
ValueError: invalid literal for int() with base 10: '2 "k1.csv"'
Я использовал этот скрипт в этом посте. Это отличный скрипт Paython, и я могу удалить всех участников канала. Но когда я попытайтесь добавить участников на мой канал, но не получится, появится сообщение об ошибке: [code]Traceback (most recent call last): File "C:\exp\telethon-bot-add-users-to-groups.py", line 183, in mode = int(input("Enter \n1-List users in a group\n2-Add users from CSV to Group (CSV must be passed as a parameter to the script\n3-Show CSV\n\nYour option: ")) ValueError: invalid literal for int() with base 10: '2 "k1.csv"' [/code] Сценарий доступен по адресу https://github.com/gsusI/Telegram-Group-or-Channel-users-to-CSV И я попробовал: 2 kf.csv и 2 'kf.csv' и 2 "kf.csv" Но он продолжает выдавать ошибки Код: [code]from telethon.sync import TelegramClient from telethon.tl.functions.messages import GetDialogsRequest from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError from telethon.tl.functions.channels import InviteToChannelRequest import sys import csv import traceback import time import random import re
api_id = 123 # YOUR API_ID api_hash = '123' # YOUR API_HASH phone = '+123' # YOUR PHONE NUMBER, INCLUDING COUNTRY CODE client = TelegramClient(phone, api_id, api_hash)
client.connect() if not client.is_user_authorized(): client.send_code_request(phone) client.sign_in(phone, input('Enter the code: '))
def add_users_to_group(): input_file = sys.argv[1] users = [] with open(input_file, encoding='UTF-8') as f: rows = csv.reader(f,delimiter=",",lineterminator="\n") next(rows, None) for row in rows: user = {} user['username'] = row[0] try: user['id'] = int(row[1]) user['access_hash'] = int(row[2]) except IndexError: print ('users without id or access_hash') users.append(user)
print('Saving In file...') with open("members-" + re.sub("-+","-",re.sub("[^a-zA-Z]","-",str.lower(target_group.title))) + ".csv","w",encoding='UTF-8') as f: writer = csv.writer(f,delimiter=",",lineterminator="\n") writer.writerow(['username','user id', 'access hash','name','group', 'group id']) for user in all_participants: if user.username: username= user.username else: username= "" if user.first_name: first_name= user.first_name else: first_name= "" if user.last_name: last_name= user.last_name else: last_name= "" name= (first_name + ' ' + last_name).strip() writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id]) print('Members scraped successfully.')
def printCSV(): input_file = sys.argv[1] users = [] with open(input_file, encoding='UTF-8') as f: rows = csv.reader(f,delimiter=",",lineterminator="\n") next(rows, None) for row in rows: user = {} user['username'] = row[0] user['id'] = int(row[1]) user['access_hash'] = int(row[2]) users.append(user) print(row) print(user) sys.exit('FINITO')
# print('Fetching Members...') # all_participants = [] # all_participants = client.get_participants(target_group, aggressive=True) print('What do you want to do:') mode = int(input("Enter \n1-List users in a group\n2-Add users from CSV to Group (CSV must be passed as a parameter to the script\n3-Show CSV\n\nYour option: "))
if mode == 1: list_users_in_group() elif mode == 2: add_users_to_group() elif mode == 3: printCSV() [/code] Я ценю любую помощь и совет Заранее большое спасибо