def start_info(): #获取setting中信息 city_name = friend_dict.get('city_name') wechat_name = friend_dict['wechat_name'] #时间转化为时间戳 start_date = time.mktime( time.strptime(friend_dict.get('start_date'), '%Y-%m-%d')) sweet_words = friend_dict.get('sweet_words') #获取一句话留言 dictum_msg = getword() mess = getWeather(city_name, start_date) #组成完整的一段话 today_mess = f'{mess}{dictum_msg}\n{sweet_words}\n' print(f'给 {wechat_name} 发送的内容是:\n{today_mess}') #调用接口向指定好友发送 wechat = Wechat() if wechat.isonline(auto_login=True): name_uuid = wechat.getfriend().get("name_uuid") itchat.send(today_mess, name_uuid) time.sleep(5) print('sucess')
def handle_msg_all(self, msg): print('..', sys._getframe().f_code.co_name) print('msg=', msg) username = msg['user']['name'] print(username) info = msg['content']['data'] if msg['msg_type_id'] == 4: # 普通信息 res_json = getTulingResp(info) print(type(res_json)) res = json.loads(res_json) print(res) text = res['text'] print(text) uid = Wechat.get_user_id(self, username) Wechat.send_msg_by_uid(self, text, uid) elif msg['msg_type_id'] == 37: # 添加好友请求 print(info) Wechat.apply_useradd_requests(self, info)
def handle_client(request): """handle wechat event and client message""" wechat = Wechat() args = request.args # check request signature if not wechat.check_signature(args.get('signature'), args.get('timestamp'), args.get('nonce')): return '' try: wechat.parse_data(request.data) except ParseError: log.error('Parse post data error, data: %s'%str(request.data)) return '' log.debug('Request: %s'%str(request.data)) message = wechat.get_message() response = '' # normal message if isinstance(message, TextMessage): response = wechat.response_text(content=turing_robot(message.content, message.source)) elif isinstance(message, VoiceMessage): response = wechat.response_text(content=u'语音信息') elif isinstance(message, ImageMessage): response = wechat.response_text(content=u'图片信息') elif isinstance(message, VideoMessage): response = wechat.response_text(content=u'视频信息') elif isinstance(message, ShortVideoMessage): response = wechat.response_text(content=u'小视频信息') elif isinstance(message, LinkMessage): response = wechat.response_text(content=u'链接信息') elif isinstance(message, LocationMessage): response = wechat.response_text(content=u'地理位置信息') # event message elif isinstance(message, EventMessage): # 事件信息 if message.type == 'subscribe': # 关注事件(包括普通关注事件和扫描二维码造成的关注事件) if message.key and message.ticket: # 如果 key 和 ticket 均不为空,则是扫描二维码造成的关注事件 response = wechat.response_text(content=u'用户尚未关注时的二维码扫描关注事件') else: response = wechat.response_text(content=u'普通关注事件') elif message.type == 'unsubscribe': response = wechat.response_text(content=u'取消关注事件') elif message.type == 'scan': response = wechat.response_text(content=u'用户已关注时的二维码扫描事件') elif message.type == 'location': response = wechat.response_text(content=u'上报地理位置事件') elif message.type == 'click': response = wechat.response_text(content=u'自定义菜单点击事件') elif message.type == 'view': response = wechat.response_text(content=u'自定义菜单跳转链接事件') elif message.type == 'templatesendjobfinish': response = wechat.response_text(content=u'模板消息事件') if isinstance(response, unicode): response = response.encode('utf-8') log.debug('Response: %s'%response) return make_response(response)
from flask_redis import FlaskRedis from flask_sqlalchemy import SQLAlchemy from wechat import Wechat __all__ = ['wechat', 'redis', 'db'] wechat = Wechat() db = SQLAlchemy() redis = FlaskRedis()
# encoding: utf-8 import os from request import Request from wechat import Wechat 请求文章地址 request = Request() url = request.do_request() wechat = Wechat() wechat.request_message(url)
timeout = [] if task is None or len(task) == 0: pass else: children = zookeeper.getChildren("") if children is None or len(children) == 0: pass else: for child in children: if isIP(child): checkUpdate(timeout, zookeeper, globalTime, child) if child in task: checkUpdate(timeout, zookeeper, book[child]['actionTime'], child) book[child]['checkTime'] = checkTime logging.info("current book: %s", book) book.close() if timeout is not None and len(timeout) > 0: receiver = "*****@*****.**" subject = "db2zk APP response TIMEOUT Warning" mail = Mail(receiver, subject, timeout) mail = mail.send() url="http://127.0.0.1:8080/msg" tos="10086" content="[P0][TEST][db2zk APP response TIMEOUT warning, please check the email!]" wechat=Wechat(url, tos, content) wechat.send() zookeeper.close()
from wechat import Wechat from alarm import Alarm #从Lambda环境变量获取 企业ID 和 AgentID corpId = os.environ['CORPID'] agentId = os.environ['AGENTID'] corpSecretArn = os.environ['CORPSECRET_ARN'] #从Secrets Manager获取 应用Secret secret_manager_client = boto3.client('secretsmanager') get_secret_value_response = secret_manager_client.get_secret_value( SecretId=corpSecretArn) corpSecret = get_secret_value_response['SecretString'] #初始化,并连接企业微信接口获取 Access Token wechat = Wechat(corpId, corpSecret) def lambda_handler(event, context): print(event) msg = msg_format(event) print(msg) wxAlarm = Alarm( toUser= "******", #成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送 toParty="", #部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 toTag="", #标签ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 agentId=agentId, description=msg, )
def __init__(self): Wechat.__init__(self) self.start_sched = datetime.datetime(2017, 11, 30, 23, 3, 00) self.sched_cnt = [] self.sched_content = [] self.sched_list = []
def create_menu(menu_data): wechat = Wechat() wechat.create_menu(menu_data)