吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2823|回复: 18
收起左侧

[Python 转载] 【修改版】华为云函数实现每日天气推送

[复制链接]
15098017803 发表于 2022-11-13 13:27
本帖最后由 15098017803 于 2022-11-13 13:40 编辑

原帖子地址:https://www.52pojie.cn/thread-1423918-1-1.html
原帖作者:@医生
和风天气https://www.qweather.com/qmsg酱https://qmsg.zendee.cn/
华为函数工作流:https://console.huaweicloud.com/functiongraph/
城市代码查询入口:https://where.heweather.com/index.html

以前抄过大佬的作业,昨天想起来这个,打算再抄一次,发现腾讯云函数需要小钱钱了,价格还不便宜,算了算了,于是换到了华为云(阿里云似乎也要收费?)。
把代码直接复制过去,发现从头到尾,全部运行不了报错,不会代码,零零散散百度了几个小时,算是能用了(本人关于代码的经验只有大学期间的vb2级)
发现def函数报错,不知道怎么处理(主要时间花在了这儿,搞不懂),删了,总之没报错
和风天气api更改了,重新修正
1、创建函数-创建空白函数-事件函数-命名-选择python3.6
步骤1.png
2、删除index.py所有内容,讲以下代码复制进去
[Python] 纯文本查看 复制代码
# -*- coding:utf-8 -*-
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
#  requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def handler(event, context):
    yburl = 'https://api.qweather.com/v7/grid-weather/3d?' #格点天气3天
    value = {
        'location': '【你的地点】',  #广州
        'key': '【你的key】',
        'lang': 'zh'
    }
    ybreq = requests.get(yburl, params=value)
    ybjs = ybreq.json()
    ybur2 = 'https://api.qweather.com/v7/weather/3d?' #城市天气3天
    value = {
        'location': '【你的地点】',
        'key': '【你的key】',
        'lang': 'zh'
    }
    ybreq2 = requests.get(ybur2, params=value)
    ybjs2 = ybreq2.json()
    # 返回api参数:
    # print(ybjs)
    for i in range(2):
        yb = ybjs['daily']
        yb2 = ybjs2['daily']
        d1 = yb[i]['fxDate'] + '\n气温: ' + yb[i]['tempMin'] + '—' + yb[i]['tempMax'] + '℃'+ '    降雨量:' +yb[i]['precip']   + '   \n日间:' + yb[i]['textDay']   + '  ' + yb[i]['windDirDay']  + ' ' + yb[i]['windScaleDay'] + '级' + '  日出:' + yb2[i]['sunrise'] + ' 日落:' + yb2[i]['sunset'] + '   \n夜间:' + yb[i]['textNight'] + ' ' + ' ' + yb[i]['windDirNight']  + ' ' + yb[i]['windScaleNight'] + '级' + '  月升:' + yb2[i]['moonrise'] + ' 月落:' + yb2[i]['moonset'] + '   ' +yb2[i]['moonPhase']  
        # output(d1)
    # qq推送
    qqtalk = 'https://qmsg.zendee.cn/send/【你的qsmgkey】?msg=' + d1 +'&qq=【你的qq】'
    requests.get(qqtalk)

步骤2.png
3、选择部署——测试(选择空白测试) qq收到了如下消息
测试.png
4、创建触发器——定时触发器——cron表达式 【0 0 22 * * ?】 每晚10点




关于api,我同时使用了两个
格点天气:https://dev.qweather.com/docs/api/grid-weather/grid-weather-daily-forecast/
城市天气:https://dev.qweather.com/docs/api/weather/weather-daily-forecast/
原因是格点天气更加准确(大概),但是缺少了日出日落时间,所以额外加了个城市天气的api

api我是用的是收费版,但是由于是个人使用,预估一个月一毛钱都用不了


之前一直以为推送无法换行,发现\n   可以用于qq的换行,太棒了


qmsg的机器人我用的自己的一个小号挂载在服务器上的,他们的公共机器人似乎全部宕机了,
qmsg自己有教程(https://qmsg.zendee.cn/pvt
我额外参照了这位大佬的博客:https://blog.panghai.top/posts/7b50/
同时大佬的机器人后台运行的代码似乎有问题,我用的是
nohup /www/wwwroot/QmsgClient2.1_20220916_1/run.sh
nohup 是相关命令
/www/wwwroot/QmsgClient2.1_20220916_1/ 是我的文件夹
run.sh 是官方建议的启动程序(大佬直接启动QmsgClient2.1.jar,我启动就卡住
> Qmsg.log 2>&1 & 不懂,照抄

免费评分

参与人数 1热心值 +1 收起 理由
lovemybird + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

18809876635 发表于 2023-5-7 22:04
大佬你好,看见你最后部署qmsg酱,我使用服务器最后出现下面代码这种情况是什么原因,感谢大佬指导,我完全按照您帖子里的提到的博客步骤部署的
[Java] 纯文本查看 复制代码
13:55:35,106 |-INFO in ch.qos.logback.classic.LoggerContext[logback] - Could NOT find resource [logback-test.xml]
13:55:35,106 |-INFO in ch.qos.logback.classic.LoggerContext[logback] - Could NOT find resource [logback.groovy]
13:55:35,106 |-INFO in ch.qos.logback.classic.LoggerContext[logback] - Found resource [logback.xml] at [jar:file:/root/QmsgClient2.1.jar!/logback.xml]
13:55:35,130 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@7cdbc5d3 - URL [jar:file:/root/QmsgClient2.1.jar!/logback.xml] is not of type file
13:55:35,194 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
13:55:35,196 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [logback]
13:55:35,197 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
13:55:35,200 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
13:55:35,214 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:55:35,260 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
13:55:35,263 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [DEBUG_FILE]
13:55:35,266 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:55:35,295 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@984213526 - No compression will be used
13:55:35,296 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@984213526 - Will use the pattern ./logs/debug/log-debug-%d{yyyy-MM-dd}.%i.log for the active file
13:55:35,298 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@17d99928 - The date pattern is 'yyyy-MM-dd' from file name pattern './logs/debug/log-debug-%d{yyyy-MM-dd}.%i.log'.
13:55:35,298 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@17d99928 - Roll-over at midnight.
13:55:35,306 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@17d99928 - Setting initial period to Sun May 07 13:41:44 UTC 2023
13:55:35,306 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@17d99928 - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
13:55:35,306 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@17d99928 - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
13:55:35,317 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[DEBUG_FILE] - Active log file name: ./logs/log_debug.log
13:55:35,317 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[DEBUG_FILE] - File property is set to [./logs/log_debug.log]
13:55:35,317 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
13:55:35,317 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [INFO_FILE]
13:55:35,317 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:55:35,322 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@942986815 - No compression will be used
13:55:35,322 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@942986815 - Will use the pattern ./logs/info/log-info-%d{yyyy-MM-dd}.%i.log for the active file
13:55:35,324 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1ae369b7 - The date pattern is 'yyyy-MM-dd' from file name pattern './logs/info/log-info-%d{yyyy-MM-dd}.%i.log'.
13:55:35,324 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1ae369b7 - Roll-over at midnight.
13:55:35,325 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1ae369b7 - Setting initial period to Sun May 07 13:53:47 UTC 2023
13:55:35,326 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1ae369b7 - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
13:55:35,326 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1ae369b7 - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
13:55:35,329 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[INFO_FILE] - Active log file name: ./logs/log_info.log
13:55:35,329 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[INFO_FILE] - File property is set to [./logs/log_info.log]
13:55:35,329 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
13:55:35,329 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [WARN_FILE]
13:55:35,330 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:55:35,338 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1879034789 - No compression will be used
13:55:35,338 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1879034789 - Will use the pattern ./logs/warn/log-warn-%d{yyyy-MM-dd}.%i.log for the active file
13:55:35,339 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34340fab - The date pattern is 'yyyy-MM-dd' from file name pattern './logs/warn/log-warn-%d{yyyy-MM-dd}.%i.log'.
13:55:35,339 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34340fab - Roll-over at midnight.
13:55:35,339 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34340fab - Setting initial period to Sun May 07 13:41:45 UTC 2023
13:55:35,339 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34340fab - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
13:55:35,339 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34340fab - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
13:55:35,342 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[WARN_FILE] - Active log file name: ./logs/log_warn.log
13:55:35,342 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[WARN_FILE] - File property is set to [./logs/log_warn.log]
13:55:35,342 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
13:55:35,342 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ERROR_FILE]
13:55:35,343 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:55:35,348 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@716157500 - No compression will be used
13:55:35,348 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@716157500 - Will use the pattern ./logs/error/log-error-%d{yyyy-MM-dd}.%i.log for the active file
13:55:35,348 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b80d80f - The date pattern is 'yyyy-MM-dd' from file name pattern './logs/error/log-error-%d{yyyy-MM-dd}.%i.log'.
13:55:35,348 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b80d80f - Roll-over at midnight.
13:55:35,349 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b80d80f - Setting initial period to Sun May 07 13:41:45 UTC 2023
13:55:35,349 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b80d80f - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
13:55:35,349 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b80d80f - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
13:55:35,349 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ERROR_FILE] - Active log file name: ./logs/log_error.log
13:55:35,349 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ERROR_FILE] - File property is set to [./logs/log_error.log]
13:55:35,350 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ch.qos.logback.classic] to OFF
13:55:35,350 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
13:55:35,350 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
13:55:35,351 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [DEBUG_FILE] to Logger[ROOT]
13:55:35,351 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
13:55:35,351 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [INFO_FILE] to Logger[ROOT]
13:55:35,351 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [WARN_FILE] to Logger[ROOT]
13:55:35,351 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ERROR_FILE] to Logger[ROOT]
13:55:35,351 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
13:55:35,356 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@3ab39c39 - Registering current configuration as safe fallback point

2023-05-07 13:55:35,669 INFO  c.I.Y.d.ConfigManagerDefaultImpl@[main] - ConfigManager Init.
2023-05-07 13:55:35,820 INFO  c.I.Y.d.ConfigManagerDefaultImpl@[main] - ConfigManager Config Mode: dev.
2023-05-07 13:55:35,823 INFO  c.I.Y.d.ConfigManagerDefaultImpl@[main] - ConfigManager Init Success.
2023-05-07 13:55:38,630 INFO  c.I.Y.a.AsLoader@[main] - Init ApplicationService: EhcacheHelpFactory Success!
2023-05-07 13:55:38,631 INFO  c.I.Y.a.AsLoader@[main] - Init ApplicationService: JobManagerImpl Success!
2023-05-07 13:55:38,633 INFO  c.i.y.a.ArtQQBot@[main] - Load By UIF: /root/.yuq/.art/.device/info_2232196592.json
2023-05-07 13:55:38,672 INFO  o.a.c.EcdhCrypt@[main] - setPubKey 0440eaf325b9c66225143aa7f3961c953c3d5a8048c2b73293cdc7dcbab7f35c4c66aa8917a8fd511f9d969d02c8501bcaa3e3b11746f00567e3aea303ac5f2d25 ver:2:
2023-05-07 13:55:38,676 INFO  o.a.c.EcdhCrypt@[main] - initShareKeyByBouncycastle failed, :
initShareKeyByDefault
2023-05-07 13:55:38,676 INFO  o.a.c.EcdhCrypt@[main] - initShareKeyByDefault OK:
[Bot]Begin loginning.
java.lang.NullPointerException
        at com.icecreamqaq.yuq.artqq.protocol.login.WtLogin$Login.decode(WtLogin.kt:79)
        at com.icecreamqaq.yuq.artqq.protocol.login.WtLogin$Login.decode(WtLogin.kt:64)
        at com.icecreamqaq.yuq.artqq.ArtQQBot$YuQHandler.handlePacket(ArtQQBot.kt:1345)
        at org.artqq.ReceiveData.parseMessage(ReceiveData.java:112)
        at org.artqq.ReceiveData$BuiltThread.run(ReceiveData.java:962)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)
Exception in thread "pool-2-thread-1" java.lang.RuntimeException: wait packet: wtlogin.login timeout!
        at org.artqq.ReceiveData$HandlePacket.waitPacket(ReceiveData.java:1043)
        at org.artqq.Wtlogin._Login.sendWtLogin(_Login.java:64)
        at org.artqq.Wtlogin._Login.run(_Login.java:34)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)
 楼主| 15098017803 发表于 2022-11-15 10:02
我今天是大佬 发表于 2022-11-14 09:55
腾讯云函数真的贼贵, 我之前就print一下, 试用忘记关了. 一个月就扣了10几块钱

话说华为云收费吗

腾讯云函数今年开始,基础套餐一个月要扣12元吧好像,华为云不收费,前10w次?还是100w次?
勤快的懒虫 发表于 2022-11-13 15:49
518pj 发表于 2022-11-13 18:29
学习了,谢谢大佬
Sp1ral 发表于 2022-11-13 18:30
学到了学到了
wg198300 发表于 2022-11-13 18:43
华为免费吗?
tongyan 发表于 2022-11-13 19:06
感谢分享
qfxldhw 发表于 2022-11-13 21:19

学习了,谢谢大佬
头像被屏蔽
xiadongming 发表于 2022-11-13 22:24
提示: 作者被禁止或删除 内容自动屏蔽
AlwaysJms 发表于 2022-11-14 09:01
学习一下,感谢感谢
丶MaGuoGuo 发表于 2022-11-14 09:40
感谢感谢 非常有用的知识
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 21:44

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表