收藏
回答

企业微信群聊机器人,天气机器人

要求:企业微信群聊机器人改造成天气机器人,每天上午9点定时向企业群发送北京实时天气,本人外行,请大神、好心人把代码写好,我直接替换机器人webhook地址就可以用的。


回答关注问题邀请回答
收藏

6 个回答

  • 禾店科技
    禾店科技
    2021-04-28

    有解决方案了吗?分享一下

    2021-04-28
    有用 1
    回复
  • CKevin
    CKevin
    2023-04-23

    import simplejson as json

    import requests

    import datetime

    import fake_useragent # 这个库可以不用

    from bs4 import BeautifulSoup

    import time


    def get_fake_ua(): #这个函数是用来获取随机UA的,可以不用

        location = '/fake_useragent_0.1.11.json' #这里是我导入的fakeuseragent库文件,可以不用

        ua = fake_useragent.UserAgent(path=location)


        headers = {

            'user-agent': ua.random

        }

        return headers


    def get_week_day(date):

        week_day_dict = {

            0: '星期一',

            1: '星期二',

            2: '星期三',

            3: '星期四',

            4: '星期五',

            5: '星期六',

            6: '星期天',

        }

        day = date.weekday()

        return "今天日期为:" + str(datetime.date.today()) + ' ' + week_day_dict[day]


    def get_weather():

        url = "https://d1.weather.com.cn/sk_2d/101010100.html?_=1618886817920"

        r_url = requests.get(url, headers=get_fake_ua())

        message = json.loads(r_url.text.encode("latin1").decode("utf8").replace("var dataSK = ", ""))

        cityname = message['cityname']

        aqi = int(message['aqi'])

        sd = message['sd']

        wd = message['WD']

        ws = message['WS']

        temp = message['temp']

        weather = message['weather']

        if aqi <= 50:

            airQuality = "优"

        elif aqi <= 100:

            airQuality = "良"

        elif aqi <= 150:

            airQuality = "轻度污染"

        elif aqi <= 200:

            airQuality = "中度污染"

        elif aqi <= 300:

            airQuality = "重度污染"

        else:

            airQuality = "严重污染"

        return cityname + " " + '今日天气:' + weather + ' 温度:' + temp + ' 摄氏度 ' + wd + ws + ' 相对湿度:' + sd + ' 空气质量:' \

               + str(aqi) + "(" + airQuality + ")"


    def get_top_list():

        requests_page = requests.get('http://top.baidu.com/buzz?b=1&c=513&fr=topbuzz_b42_c513')

        soup = BeautifulSoup(requests_page.text, "lxml")

        soup_text = soup.find_all("a", class_='list-title')

        i = 0

        top_list = []

        for text in soup_text:

            i += 1

            top_list.append(text.string.encode("latin1").decode("GBK"))

            if i == 10:

                break

        return top_list


    def get_daily_sentence():

        url = "http://open.iciba.com/dsapi/"

        r = requests.get(url, headers=get_fake_ua())

        r = json.loads(r.text)

        content = r["content"]

        note = r["note"]

        daily_sentence = content + "\n" + note

        return daily_sentence


    def get_sendContent():

        sendContent =  get_week_day(datetime.date.today()) + "\n\n" + get_weather() + "\n\n" + str(get_top_list()).replace(

            "', '", '\n').replace("['", "").replace("']", "") + "\n\n" + get_daily_sentence()

        return sendContent


    def send(content):

        url = # 填写你的webhook链接

        headers = {"Content-Type": "text/plain"}

        data = {

            "msgtype": "text",

            "text": {

                "content": content,

            }

        }

        requests_url = requests.post(url, headers=headers, data=json.dumps(data))

        if requests_url.text == '{"errcode":0,"errmsg":"ok"}':

            return "发送成功"

        else:

            return "发送失败" + requests_url.text


    print(send(get_sendContent()))


    2023-04-23
    有用
    回复
  • 零落仙·千寻
    零落仙·千寻
    2022-12-16

    需要的话可以联系我

    2022-12-16
    有用
    回复 1
    • 牛栏山🐮
      牛栏山🐮
      2023-08-14
      您好,这个可以发我一份吗? WX:lightstar319  QQ:1423731889   邮箱1423731889@qq.com
      2023-08-14
      回复
  • 不忘初心
    不忘初心
    2022-04-10

    这个需要有开发能力,还可以操作外部群等等 Q:2645542961,用程序写个定时器就行了

    2022-04-10
    有用
    回复
  • 扑通
    扑通
    2020-03-03

    2020-03-03
    有用
    回复
  • 养乐哆🍥
    养乐哆🍥
    2020-03-02

    阔以

    2020-03-02
    有用
    回复
登录 后发表内容
问题标签