python - 创建此 python 脚本以添加 100 个成员,但仅添加 3 到 5 并自动停止
问题描述
创建了这个 python 脚本来添加 100 个成员,但只添加 3 到 5,有时只添加 1,之后它会自动停止,不知道是什么问题,但也许我认为问题出在时间戳上
创建了这个 python 脚本来添加 100 个成员,但添加只有 3 到 5,有时只有 1,之后它会自动停止,不知道是什么问题,但也许我认为问题出在时间戳上
from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser, PeerUser
from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError, ChatWriteForbiddenError, UserAlreadyParticipantError
from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.tl.functions.channels import GetFullChannelRequest, JoinChannelRequest
from telethon import types, utils, errors
import configparser
import sys
import csv
from csv import reader
import traceback
import time
import random
from telethon.sessions import StringSession
print(" ")
print(" " )
print(" ")
print(" ")
delta = 1
with open('../phone.csv', 'r') as read_obj:
csv_reader = reader(read_obj)
list_of_rows = list(csv_reader)
row_number = delta
col_number = 1
value = list_of_rows[row_number - 1][col_number - 1]
with open('../api.csv', 'r') as api_obj_id:
csv_reader = reader(api_obj_id)
list_of_rows = list(csv_reader)
row_number = delta
col_number = 1
deltaop = list_of_rows[row_number - 1][col_number - 1]
with open('../api.csv', 'r') as hash_obj:
csv_reader = reader(hash_obj)
list_of_rows = list(csv_reader)
row_number = delta
col_number = 2
deltaxd = list_of_rows[row_number - 1][col_number - 1]
api_id = int(deltaop)
api_hash = str(deltaxd)
pphone = value
config = configparser.ConfigParser()
config.read("../config.ini")
to_group = config['Telegram']['to_channel']
def autos():
channel_username = to_group
phone = utils.parse_phone(pphone)
client = TelegramClient(f"../sessions/{phone}", api_id, api_hash)
client.connect()
if not client.is_user_authorized():
print('some thing has changed')
client.send_code_request(phone)
client.sign_in(phone, input ('Enter the code: '))
input_file = '../data.csv'
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['srno'] = row[0]
user['username'] = row[1]
user['id'] = int(row[2])
#user['access_hash'] = int(row[2])
user['name'] = row[3]
users.append(user)
startfrom = int(input("Start From = "))
endto = int(input("End To = "))
for user in users:
if (int(startfrom) <= int (user['srno'])) and (int(user['srno']) <= int(endto)):
try:
status = 'delta'
if user['username'] == "":
print("no username, moving to next")
continue
client(InviteToChannelRequest(channel_username,[user['username']]))
status = 'DONE'
#print("Waiting for 60-180 Seconds...")
time.sleep(random.randrange(0, 5))
except UserPrivacyRestrictedError:
status = 'PrivacyRestrictedError'
except UserAlreadyParticipantError:
status = 'ALREADY'
except PeerFloodError as g:
status = 'PeerFloodError :('
print('Script Is Stopping Now')
time.sleep(86400)
except ChatWriteForbiddenError as cwfe:
client(JoinChannelRequest(channel_username))
continue
except errors.RPCError as e:
status = e.__class__.__name__
except Exception as d:
status = d
except:
traceback.print_exc()
print("Unexpected Error")
continue
channel_connect = client.get_entity(channel_username)
channel_full_info = client(GetFullChannelRequest(channel=channel_connect))
countt = int(channel_full_info.full_chat.participants_count)
print(f"ADDING {user['name']} TO {channel_username} TOTAL: {countt} - {status}")
elif int(user['srno']) > int(endto):
print("Members Added Successfully!")
stat = input('Done!\nChoose From Below:\n\n1 - Repeat The Script\nOR Just Hit Enter To Quit\n\nEnter: ')
if stat == '1':
autos()
else:
quit()
autos()
解决方案
推荐阅读
- spring-boot - 带有 Oauth2 和 Spring-boot-starter-parent 版本 2+ 的 Spring Boot SSO
- android - 无法自动点击移动应用程序中的按钮
- c# - 如何使 --viewport-size 参数在 Tuesspechkin 中可用?
- html - 带有截断多行文本的 CSS 过渡
- angularjs - Ag-grid单击后如何更新特定的单元格样式
- react-native - 尝试接收不在服务器上的数据时无法读取未定义的属性“0”
- scala - 猫和功能组合物
- ruby - 链接方法后的 Ruby 重新分配(sort_by、reverse 等)
- android - 是否可以在android中使用没有字符串资源文件的库来更改应用程序语言
- mysql - 多 delte 语句中的未知表