Giter Site home page Giter Site logo

shirok1 / e5-api-renew-scf Goto Github PK

View Code? Open in Web Editor NEW
37.0 2.0 17.0 9 KB

本项目已进入半废弃状态(因为我自己的开发者订阅在2020年12月掉了)所以这里可能只能提供基础技术指导——[腾讯云函数专用]通过重复调用MS Graph API来试图续订Office 365开发者试用

Python 100.00%
tencent-scf tencent-cloud serverless office-365

e5-api-renew-scf's Introduction

E5 Renew SCF

如题,原版刷API脚本的修改版,单次执行,专门用于腾讯云的无服务器云函数。

配置

参数获取请参见office e5刷API脚本分享以及教程E5刷API脚本分享以及教程(后面这个有图)。

入口函数为index.exe

需要预先配置以下环境变量:

Region:该云函数所在服务器地域,地域代码参见地域列表

refresh_tokenrclone所获取的同名参数,点击这里下载rclone

ms_id:Azure AD上的应用程序(客户端) ID

ms_secret:Azure AD上的客户端密码(不是用户密码)

SecretIdSecretKey:先到腾讯云API密钥管理创建,用于刷新环境变量中的refresh_token

如果你有新的API要加入,只要请求的header格式一致,可以直接加入api_list列表(那两个messageRules是原本就有两条的,我暂且蒙在鼓里)。

另外,云函数不会自己运行,请自行设置触发器。

如果你想使用子账号,请注意给予的权限中要包括以下Action:

Action名称 描述
GetFunction 获取函数详情
UpdateFunctionConfiguration 更新函数配置
SetTrigger(仅设置随机时间需要,下同) 设置函数触发器
UpdateTrigger 更新触发器配置
DeleteTrigger 删除函数触发器

随机时间

原本的设想是直接删除旧的触发器,然后添加一个随机时间的触发器,没想到居然不行。

[TencentCloudSDKException] code:FailedOperation.CreateTrigger message:创建触发器失败 (当前函数状态无法进行此操作)

明明连修改环境变量都可以……没办法,不能在一个函数内实现随机时间了。(除非你想靠sleep(random())卡时间,但这样会浪费不少计费时间)

如果你不嫌麻烦的话,确实可以通过两个函数互相调用来实现随机时间。

A+B类型

通过用两个具有完整功能的函数互相设置定时触发器来实现。

环境变量:

TrigUpdateTypeAB

注意:云函数提供了包括环境变量在内的复制功能。使用复制功能前不要在环境变量中填写refresh_token

AnotherFunctionName:另一个函数的FunctionName

AnotherRegion:(可选)另一个函数的Region,默认相同

AnotherNamespace:(可选)另一个函数的Namespace,默认相同

random_time_lowerlimitrandom_time_toplimit:(可选)随机时间的下限、上限,默认150、300(秒)

TriggerName:(可选)触发器的名称,每次更新都会先删除这个名字的触发器再添加一个同名的,默认值为RandomTimer

无论使用哪种类型,建议只设置一个api触发器,因为程序在初次运行后,就能自动递归触发下一次。

响应

目前还想不到能响应什么有用的东西,毕竟大部分时间都是无值守运行。

所有print()的输出请到云函数的运行日志查看。

消耗

测试挂了一天,设置的触发器每5分钟触发一次,共使用资源约120GBs,出流量0.01GB,完全不会超出免费额度;另外,每次触发平均耗时4s,内存消耗基本都在20MB左右。

TODO

  • 自行递归添加下一个触发器(以实现真正随机时间而不是靠sleep(random())卡时间实现)

  • 搞懂为什么不能在定义全局变量的时候用环境变量赋值

目前自行定义的环境变量和一些会有变动的环境只能在入口函数中获取,是因为是在调用入口函数的时候注入的。——腾讯云工作人员回复(为什么不写在文档里?)

  • 把那些手打的params用字典转json代替(对于那种连多打一个逗号都要报错的解析器表示强烈cnm

  • 欢迎issue。

e5-api-renew-scf's People

Contributors

shirok1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

e5-api-renew-scf's Issues

腾讯云测试报错

{"errorCode":-1,"errorMessage":"Traceback (most recent call last):\n File "/var/runtime/python3/bootstrap.py", line 133, in init_handler\n func_handler = get_func_handler(file.rsplit(".", 1)[0], func)\n File "/var/runtime/python3/bootstrap.py", line 159, in get_func_handler\n mod = imp.load_module(mname, *imp.find_module(mname))\n File "/var/lang/python3/lib/python3.6/imp.py", line 234, in load_module\n return load_source(name, filename, file)\n File "/var/lang/python3/lib/python3.6/imp.py", line 172, in load_source\n module = _load(spec)\n File "Ϗrozen; importlib._bootstrap>", line 675, in _load\n File "Ϗrozen; importlib._bootstrap>", line 655, in _load_unlocked\n File "Ϗrozen; importlib._bootstrap_external>", line 674, in exec_module\n File "Ϗrozen; importlib._bootstrap_external>", line 781, in get_code\n File "Ϗrozen; importlib._bootstrap_external>", line 741, in source_to_code\n File "Ϗrozen; importlib._bootstrap>", line 205, in _call_with_frames_removed\n File "/var/user/index.py", line 19\n refresh_token = "eyJ0eXAiOiJKV1QiLCJub25jZSI6InR0MkNZcWU4d3ZZMzRhWGxGRW1lUFFROW4\n ^\nSyntaxError: EOL while scanning string literal","statusCode":443}

onedrive

有个老哥给了一个e5 账号 为什么用不了onedrive,有什么特殊姿势吗

云函数无法执行

image
如图;我在部署时已配置了一下环境变量
image
不知道如何解决。在哪里出了问题?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.