分类 python 中的文章

企业微信发送音频视频文件

企业微信发送文件 import requests import json import io class WeChatBot: def __init__(self, api_key): self.api_key = api_key self.base_url = f'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={self.api_key}' self.headers = {'Content-Type': 'application/json'} self.upload_url = f'https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key={self.api_key}&type=file' def send_message(self, data): return self._post_request(self.base_url, data) def upload_media(self, content, file_name, content_type): files = {'media': (file_name, content, content_type)} return self._post_request(self.upload_url, files=files, is_json=False) def upload_text_as_media(self, text_content, file_name): file_stream = io.BytesIO(text_content.encode('utf-8')) return self.upload_media(file_stream, file_name, 'application/octet-stream') def upload_audio_as_media(self, audio_file_path): return self._upload_file(audio_file_path, 'audio/mpeg') def upload_video_as_media(self, video_file_path): return self._upload_file(video_file_path, 'video/mp4') def send_media(self, response): if response.get("media_id"): data = { "msgtype": "file", "file": {"media_id": response["media_id"]} } return self.send_message(data) return response def _post_request(self, url, data=None, files=None, is_json=True): try: if is_json: response = requests.post(url, headers=self.headers, data=json.dumps(data)) else: response = requests.post(url, files=files) response.raise_for_status() return response.json() except requests.RequestException as e: print(f"请求时出错: {e}")……

阅读全文

聊天机器人整理

思知机器人 想在博客里添加闲聊功能,想要一个机器人,之前试过图灵机器 机器人项目汇总 (17条消息) 史上最全面聊天机器人总结,图灵、思知、小爱、小微,作者已接入到自己的开源IM项目中使用_xmcy001122的专栏-CSDN博客_思知机器人 聊天机器人gitee资料 Awesome-Chatbot: 聊天机器人资源合集:……

阅读全文

python笔记

python笔记 杨辉三角 只能用奇妙来形容了 :smile: def triangle(): L =[1] while True: b=L.copy() yield b L.append(0) L=[L[i]+L[i-1] for i in range(len(L))] 1012 翻转字符串 >>> def reverseWords(input): ... inputWords = input.split(" ") ... inputWords = inputWords[-1::-1] ... output = ' '.join(inputWords) ... return output ... >>> input = 'I like runnob' >>> rw = reverseWords(input) >>> rw 'runnob like I' 集合的使用 #!/usr/bin/python3 sites = {'Google', 'Taobao', 'Runoob', 'Facebook', 'Zhihu', 'Baidu'} print(sites) # 输出集合,重复的元素被自动去掉 # 成员测试 if 'Runoob' in sites : print('Runoob 在集合中') else : print('Runoob 不在集合中') # se……

阅读全文

爬虫的ip代理池

IP代理池 更新时间: 2024/7/19 github 上的爬虫ip池,使用python 很好用 名称 地址 描述 Python ProxyPool for web spider https://github.com/jhao104/proxy_pool 21K stars An Efficient ProxyPool with Getter, Tester and Server https://github.com/Python3WebSpider/ProxyPool 5.6K stars……

阅读全文