def send_alarm_msg(key): """ 发送定时提醒 """ print('\n启动定时自动提醒...') conf = config.get('alarm_info').get('alarm_dict') gf = conf.get(key) # print(gf) is_tomorrow = gf.get('is_tomorrow', False) calendar_info = get_calendar_info(gf.get('calendar'), is_tomorrow) weather = get_weather_info(gf.get('city_name'), is_tomorrow) horoscope = get_constellation_info(gf.get("horescope"), is_tomorrow) dictum = get_dictum_info(gf.get('dictum_channel')) diff_time = get_diff_time(gf.get('start_date'), gf.get('start_date_msg')) sweet_words = gf.get('sweet_words') send_msg = '\n'.join( x for x in [calendar_info, weather, horoscope, dictum, diff_time, sweet_words] if x) # print('\n' + send_msg + '\n') if not send_msg or not is_online(): return uuid_list = gf.get('uuid_list') for uuid in uuid_list: time.sleep(1) itchat.send(send_msg, toUserName=uuid) print('\n定时内容:\n{}\n发送成功...\n\n'.format(send_msg)) print('自动提醒消息发送完成...\n')
def send_alarm_msg(): print('\n获取消息...') gf = config.get('alarm_info').get('girlfriend_infos')[0] is_tomorrow = gf.get('is_tomorrow', False) # calendar_info = get_calendar_info(gf.get('calendar'), gf.get('app_token'), is_tomorrow) weather = get_weather_info(gf.get('city_name'), gf.get('app_token'), is_tomorrow) horoscope = get_constellation_info(gf.get("horescope"), is_tomorrow) dictum = get_dictum_info(gf.get('dictum_channel')) diff_time = get_diff_time(gf.get('start_date'), gf.get('start_date_msg')) air_quality = get_air_quality(gf.get('air_quality_city')) sweet_words = gf.get('sweet_words') list_data = [] for x in [weather, air_quality, horoscope, dictum, diff_time, sweet_words]: if x: list_data.append(x) send_msg = ' \n'.join(list_data) # 必须添加两个空格加换行 print('\n' + send_msg + '\n') # pyperclip.copy(send_msg) with open('./result.txt', 'w', encoding='utf-8') as f: f.write(send_msg) form = { 'title': '每日一句', 'desp': send_msg } send_key = os.environ.get('SEND_KEY') # print(send_key) resp = requests.post('https://sctapi.ftqq.com/{}.send'.format(send_key), form) print(resp) if resp.status_code == 200: print('发送成功!')