获取电报机器人的位置

2024-06-10 01:31:37 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的脚本中,我想得到电报机器人所有者的位置,当用户点击按钮时,机器人将所有者的位置以google地图图像的形式发送给用户。 我的剧本是:

import telepot
from telepot.loop import MessageLoop
import time
from gps3 import gps3

bot = telepot.Bot('mytoken')
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    gps_socket = gps3.GPSDSocket()
    data_stream = gps3.DataStream()
    gps_socket.connect()
    gps_socket.watch()
    for new_data in gps_socket:
        if new_data:
            data_stream.unpack(new_data)
            alt = data_stream.TPV['alt']
            lat = data_stream.TPV['lat']
    bot.sendMessage(chat_id ,  alt)



MessageLoop(bot, handle).run_as_thread()
 while 1:
    time.sleep(1)

我在我的笔记本上运行这个脚本,因为我的笔记本没有gps,所以当我用android手机运行它时,它应该可以工作,但我得到了同样的错误


Tags: 用户fromimport脚本newdatastreambot
1条回答
网友
1楼 · 发布于 2024-06-10 01:31:37

我不能完全测试这一点,但如果笔记本电脑上缺少GPS是你唯一的问题,如果你只是在测试时替换一大块代码,会发生什么?公司名称:

import telepot
from telepot.loop import MessageLoop
import time

bot = telepot.Bot('mytoken')
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    lat = 53.540442
    long = 9.996381
    alt = 53.432        
    bot.sendMessage(chat_id ,  alt)

MessageLoop(bot, handle).run_as_thread()
 while 1:
    time.sleep(1)

只要给出它想要的坐标,并试着让脚本的电报部分起作用。也许sendMessage想要的不仅仅是海拔高度。。在

相关问题 更多 >