云函数+微信公众号到个人微信

先上代码

代码有注释不懂私聊或者评论

# -*- coding: utf8 -*-
import time
import requests
from lxml import etree
from datetime import date

# 这个是微信公众号调用的方法
def wxqy(text):
    url = "https://api.htm.fun/api/Wechat/text/"

    date = {
        "corpid": "企业id",
        "corpsecret": "Secret企业微信能获取",
        "agentid": "应用id",
        "text": text
    }

    re = requests.post(url, date).content.decode()
    print(re)
def heat():
    url = "https://s.weibo.com/top/summary?cate=realtimehot"
    header = {
        "Referer": "https://s.weibo.com/",
        "sec-ch-ua-platform" : "Windows",
        "User-Agent": "自己headers放进去",
        # 必传的参数 cookie
        "Cookie": "自己获取下自己的放进去"
    }
    req = requests.get(url,headers=header).text
    xl = etree.HTML(req)
    content = '//*[@id="pl_top_realtimehot"]/table/tbody'
    req_ifon = xl.xpath(content)
    wb_url = "https://s.weibo.com"
    sum =[]
    
    # 从 2开始  1是置顶
    for j in range(2,15):
        for i in req_ifon:
            time.sleep(0.5)
            # 序列号
            re = i.xpath('./tr[%s]/td[1]/text()' % (j))[0]
            # 去除广告标记
            if re.isdigit():
                number = int(re)
                # 爬取数量 小于 9
                if number < 9:
                    # 序列号
                    re1 = i.xpath('./tr[%s]/td[1]/text()' % (j))[0]
                    # 标题
                    webzgu = i.xpath('./tr[%s]/td[2]/a/text()' % (j))[0]
                    # 热搜数值
                    shu = i.xpath('./tr[%s]/td[2]/span/text()' % (j))[0]
                    # 后面的热或者爆等
                    redu = i.xpath('./tr[%s]/td[3]/i/text()' % (j))
                    # 标题的url
                    re_url = i.xpath('./tr[%s]/td[2]/a/@href' % (j))[0]
                    if not redu:
                        # print(re1, webzgu, shu)
                        sum.append(
                            " " + "%s." % re1 + " " + "<a href=\"%s\">%s</a>" % (wb_url + re_url, webzgu) + " " + "\n")
                    else:
                        # print(re1, webzgu, shu, redu[0])
                        sum.append(
                            " " + "%s." % re1 + " " + "<a href=\"%s\">%s</a>" % (wb_url + re_url, webzgu) + " %s" %
                            redu[0] + "\n")

    print(sum)
    wxqy(("").join(sum))

def tq():
    tq_url = "https://www.tianqi.com/beijing/7/"
    tq_header = {
        "Referer": "https://s.weibo.com/",
        "sec-ch-ua-platform": "Windows",
        "User-Agent": "自己headers放进去",
    }
    tq_re = requests.get(tq_url,headers=tq_header).text
    xl = etree.HTML(tq_re)
    tq_info = xl.xpath('/html/body/div[7]/div[2]/ul[1]')
    for i in tq_info:
        # 最高温度
        high = i.xpath("./li[1]/a/div[4]/span[2]/text()")[0]
        # 最低温度
        low = i.xpath("./li[1]/a/div[4]/span[1]/text()")[0]
        # 天气状况
        status = i.xpath("/html/body/div[7]/div[2]/ul[1]/li[1]/a/div[3]/text()")[0]
        # 明天最高温度
        Minggao = i.xpath("./li[2]/a/div[4]/span[2]/text()")[0]
        if int(high) >= 33:
            net = "今天天气较热,注意防晒!"
        else:
            if int(high) > int(Minggao):
                net = "明天比今天热"
            else:
                net = "今天比明天冷"
        # 日历
        d = date.today()
        time1 = d.isoformat()
        tq_sum = "叮咚~查收天气状况" + "\n" + "【北京天气】" + "\n" + "今天 %s" % time1 + "\n" + "天气:%s" % status + "\n" + "今天最高温度:%s℃" % high + "\n" + "今天最低温度:%s℃" % low + "\n" + "明天最高温度:%s℃。%s" % (Minggao,net)
        # print(tq_sum)
        wxqy(tq_sum)


# 这块是云函数使用的(注:必须传2个变量)
# def shuai(arg2,arg3):
#     heat()
#     # tq()
#     # print("heel")
#     return "Successful execution"
if __name__ == "__main__":
    heat()

云函数部分

使用腾讯云函数之前,我们先做一下准备工作:进入腾讯云注册页面,注册账号,开通云函数服务。

以云函数控制台为例,带领大家一起创建你的第一个模版函数。

登录云函数控制台,点击左侧导航栏「函数服务」,在函数服务页面上方选择地域,单击「新建」,如下图所示:

  1. 先选择你的环境
    在这里插入图片描述
  2. 安装你需要的环境
    在这里插入图片描述

以上就是云函数的环境!!!

具体可参考这位仁兄的
转自 https://blog.csdn.net/weixin_42409476/article/details/106470631

企业微信的

这位仁兄的非常详细(不需要企业认证 个人都可以)
https://www.htm.fun/archives/python-flask-api-server-jiang.html

看看效果吧

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值