tg机器人
tg机器人官方api文档
https://core.telegram.org/bots/api#getfile
实例代码
import requests, json, time, os
class my_reboot():
def __init__(self):
self.token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
self.base_file = os.path.split(os.path.realpath(__file__))[0]
self.file_path = os.path.join(self.base_file, "file")
if not os.path.exists(self.file_path):
os.mkdir(self.file_path)
def my_getFile(self, file_id):
url = "https://api.telegram.org/bot{}/getFile?file_id={}".format(self.token, file_id)
ret = requests.get(url=url)
my_dict = json.loads(ret.content.decode())
file_path = my_dict["result"]["file_path"]
file_path_url = "https://api.telegram.org/file/bot{}/{}".format(self.token, file_path)
os.system("wget {}".format(file_path_url))
def my_getUpdates(self):
url = "https://api.telegram.org/bot{}/getUpdates".format(self.token)
ret = requests.get(url=url)
my_dict = json.loads(ret.content.decode())
if len(my_dict["result"])>0:
data_time = my_dict["result"][0]["message"]["date"]
timeArray = time.localtime(data_time)
otherStyleTime = time.strftime("%Y-%m-%d_%H-%M-%S", timeArray)
data = json.dumps(my_dict, sort_keys=True, indent=4, ensure_ascii=False)
if not os.path.exists(os.path.join(self.file_path, otherStyleTime+".json")):
with open(os.path.join(self.file_path, otherStyleTime+".json"), "w", encoding="utf-8") as f:
f.write(data)
print(os.path.split(os.path.realpath(__file__))[0])
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!