Telethon GetLocatedRequest:如何访问user_id和距离信息?



我整个星期都在看电视文档,除了上网搜索之外,我还是找不到这个问题的答案。

我已经做了一个GetLocatedRequest并成功地收到了数据,但我不知道如何访问user_id和距离信息在我的脚本的其余部分使用。是否需要调用一个特定的对象来获取这些数据?到目前为止,我唯一的工作是将输出复制粘贴到.txt文件中并手动解析,这非常糟糕。

我的代码如下。point0是我定位的点,我想在用户变量中获得user_id和距离。到目前为止,我已经尝试了user。同行、用户。PeerLocated、用户。User_id,但是它们都不工作。有人以前遇到过这个吗?下面是GetLocatedRequest的输出:

更新(更新= [UpdatePeerLocated(同行= [PeerLocated同行= PeerUser (user_id = xxxxxx),到期= datetime。datetime(2038,1,19,3,14,7, tzinfo=datetime.timezone.utc), distance=100), PeerLocated(peer=PeerUser(user_id=xxxxxxx), expires=datetime. utc。Datetime (2038,1,19,3,14,7, tzinfo= Datetime .timezone.utc), distance=100),

from pprint import pprint
import re
import csv
import pandas as pd
import asyncio
import nest_asyncio
import configparser
import time
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
from telethon.tl.functions.messages import GetHistoryRequest
from telethon import functions, types
from telethon import errors
from telethon.tl.types import PeerLocated, PeerUser
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty
from telethon.tl.types import PeerChannel, InputPeerChannel
nest_asyncio.apply()

# Reading Configs
config = configparser.ConfigParser()
config.read("config.ini")
# 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']
client = TelegramClient("tes", api_id, api_hash)
async def loc0():
await client.start()
print('client starting')
await client.get_me()
print('complete')
point0 = await client(functions.contacts.GetLocatedRequest(
geo_point=types.InputGeoPoint(lat=41.1, long=69.0)))
user = point0.PeerLocated
print(user)
print('n point0 n {}'.format(point0.stringify()))

代码返回一个用户列表,而不仅仅是一个用户。要访问它们,你需要使用列表索引。

users = point0.updates[0].peers
for user in users:
print(user.peer.user_id)

最新更新