コード例 #1
0
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')
コード例 #2
0
ファイル: main.py プロジェクト: jianglin521/EverydayWechat
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('发送成功!')
コード例 #3
0
def send_alarm_msg():
    """ 发送定时提醒 """
    print('\n启动定时自动提醒...')
    conf = get_yaml()
    for gf in conf.get('girlfriend_infos'):
        dictum = get_dictum_info(gf.get('dictum_channel'))
        weather = get_weather_info(gf.get('city_name'))
        diff_time = get_diff_time(gf.get('start_date'))
        sweet_words = gf.get('sweet_words')
        horoscope = get_xzw_info(gf.get("birthday"))
        joke = get_joke_info(gf.get('is_joke', False))
        # 如果渠道是一个·ONE 就发图片
        # send_image_path = get_one_image(gf.get('dictum_channel'))
        send_image_path = get_one_image(1)  #强制发one图片

        send_msg = '\n'.join(x for x in [
            weather, "\r", dictum, "\r", diff_time, sweet_words, "\r",
            horoscope
        ] if x)
        print(send_msg)

        if not send_msg or not is_online(): continue
        # 给微信好友发信息
        wechat_name = gf.get('wechat_name')
        if wechat_name:
            if wechat_name.lower() in FILEHELPER_MARK:
                if send_image_path:
                    itchat.send_image(send_image_path, toUserName=FILEHELPER)
                itchat.send(send_msg, toUserName=FILEHELPER)
                if joke:
                    itchat.send(joke, toUserName=FILEHELPER)
                print('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    wechat_name, send_msg))
            else:
                wechat_users = itchat.search_friends(name=wechat_name)
                if not wechat_users: continue
                if send_image_path:
                    wechat_users[0].send_image(send_image_path)
                wechat_users[0].send(send_msg)
                if joke:
                    wechat_users[0].send(joke)
                print('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    wechat_name, send_msg))

        # 给群聊里发信息
        group_name = gf.get('group_name')
        if group_name:
            group = get_group(group_name)
            if group:
                if send_image_path:
                    group.send_image(send_image_path)
                group.send(send_msg)
                if joke:
                    group.send(joke)
                print('定时给群聊『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    group_name, send_msg))

    print('自动提醒消息发送完成...\n')
コード例 #4
0
def send_xiaohua_message(key):
    """ 发送定时消息 """
    print('\n启动定时消息提醒...')
    conf = config.get('alarm_info').get('alarm_dict')
    gf = conf.get(key)

    dictum = get_dictum_info(5)

    if not dictum or not is_online(): return

    b_insert = find_qinghua(dictum)
    while (b_insert):
        dictum = get_dictum_info(5)
        b_insert = find_qinghua(dictum)

    insert_qinghua(dictum)

    uuid_list = gf.get('uuid_list')
    for uuid in uuid_list:
        time.sleep(1)
        itchat.send(dictum, toUserName=uuid)
    print('\n定时内容:\n{}\n发送成功...\n\n'.format(dictum))
    print('自动提醒消息发送完成...\n')
コード例 #5
0
def send_alarm_msg():
    """ 发送定时提醒 """
    print('\n启动定时自动提醒...')
    conf = get_yaml()
    for gf in conf.get('girlfriend_infos'):
        dictum = get_dictum_info(gf.get('dictum_channel'))
        weather = get_weather_info(gf.get('city_name'))
        horoscope = get_xzw_info(gf.get("birthday"))

        send_msg = '\n'.join(x for x in [weather, dictum, horoscope] if x)

        if not send_msg or not is_online(): continue
        # 给微信好友发信息
        wechat_name = gf.get('wechat_name')
        if wechat_name:
            if wechat_name.lower() in FILEHELPER_MARK:
                itchat.send(send_msg, toUserName=FILEHELPER)
                print('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    wechat_name, send_msg))
            else:
                wechat_users = itchat.search_friends(name=wechat_name)
                if not wechat_users: continue
                wechat_users[0].send(send_msg)
                print('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    wechat_name, send_msg))

        # 给群聊里发信息
        group_name = gf.get('group_name')
        if group_name:
            group = get_group(group_name)
            if group:
                group.send(send_msg)
                print('定时给群聊『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    group_name, send_msg))

    print('自动提醒消息发送完成...\n')