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

Telethon GetLocatedRequest: How do you access the user_id and distance information?

除了上网搜索外,我整个星期都在阅读 Telethon 文档,但我找不到这个问题的答案。

我已经执行了 GetLocatedRequest 并成功接收了数据,但我不知道如何访问 user_id 和距离信息以在脚本的其余部分中使用。是否有特定的对象可以调用以获取此数据?到目前为止,我唯一的解决方法是将输出复制粘贴到 .txt 文件并手动解析,这非常糟糕。

我的代码如下。 point0 是我定位的点,我想在用户变量中获取 user_id 和距离。到目前为止,我已经尝试过 user.peer、user.PeerLocated、user.user_id 之类的方法,但其中 none 行得通。有人 运行 以前参与过这个吗?这是 GetLocatedRequest 输出的内容:

更新(更新=[UpdatePeerLocated(peers=[PeerLocated(peer=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.datetime(2038, 1, 19, 3, 14, 7, tzinfo =datetime.timezone.utc), 距离=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()))

代码returns一个用户列表不只有1个用户。要访问它们,您需要使用列表索引。

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