我Python的telethon写的一个利用Telegram给机场签到的代码(主要部分)

# Reading Configs
config = configparser.ConfigParser()
config.read(GLOBAL_CONFIG_FILE,encoding='utf8')

# Setting configuration values
api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']

api_hash = str(api_hash)

phone = config['Telegram']['phone']
username = config['Telegram']['username']

# Create the client and connect
client = TelegramClient(username, api_id, api_hash)


async def send_msg():
    await client.send_message(GLOBAL_BOT_ID,'/checkin')
    await client.send_read_acknowledge(GLOBAL_BOT_ID) #消息标记为已读

    #得到回复的信息 等几秒时间让它回复再取聊天记录
    sleep(5)    
    async for message in client.iter_messages(GLOBAL_BOT_ID,limit=2):
              message.date = message.date + timedelta(hours=8)
              print(message.date, ':',message.sender_id, ':', message.text)

with client:
    client.loop.run_until_complete(send_msg())



发表评论

您的电子邮箱地址不会被公开。

39 − 31 =