当前位置:网站首页>[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
2022-07-02 01:18:00 【Macaroni candy】
Wechat use Remotely Save S3 compatible Send to Obsidian
Original address :
Wechat use Remotely Save S3 compatible Send to Obsidian
author : Macaroni candy
CC BY-NC-SA 4.0
Use wechat official account to realize , Send to Tencent COS.Obsidian Get message .
Basic requirements
- With public network ip Server with python3 Environmental Science
- The test number of wechat official account
- Tencent cloud COS
remarks : COS and Obsidian plug-in unit Remotely Save Instructions : Obsidian Sync Remotely Save S3 Configuration Guide
Prepare the data
- WeChat official account number APP_ID
- WeChat official account number APP_SECRET
- Tencent cloud secret_id
- Tencent cloud secret_key
- Tencent cloud COS Related information Include region,Bucket name
Server building
- The server installs dependent modules pip3 install werobot and pip3 install cos-python-sdk-v5
- Fill the prepared data into the program # Related information in , If you want to change the server port, you can go to robot.config[“PORT”] = “8008” change
- to open up Linux The server 8008 port ; to open up Tencent cloud security group 8008 port
- Run the program and hang the background , I'm using Pagoda panel python Project manager Run this project
# -*- coding=utf-8
# werobot cos-python-sdk-v5
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import werobot
import time
import requests
# Related information
token = "token" # Customize
APP_ID = "wxxxxxxxxxxxxxxxxx" # WeChat official account number APP_ID
APP_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" # WeChat official account number APP_SECRET
secret_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Tencent cloud secret_id
secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxx" # Tencent cloud secret_key
region = "ap-nanjing" # Tencent cloud COS
cos_token = None # Tencent cloud COS token
scheme = "https" # Tencent cloud COS Access pattern
bucket = "test-0123456789" # Tencent cloud Bucket
# werobot To configure
robot = werobot.WeRoBot(token=token)
robot.config["APP_ID"] = APP_ID
robot.config["APP_SECRET"] = APP_SECRET
# cos To configure
config = CosConfig(
Region=region,
SecretId=secret_id,
SecretKey=secret_key,
Token=cos_token,
Scheme=scheme,
)
client = CosS3Client(config)
# rob_client = robot.client
# rob_client.create_menu({
# "button":[{
# "type": "click",
# "name": " User information ",
# "key": "info"
# }]
# })
# Menu click Input information This menu affects the quick input of information inconvenient
# @robot.key_click("info")
# def music(message):
# return ' You click on the “ User information ” Button '
# Follow the reply
@robot.subscribe
def subscribe(message):
return " This is the test official account of macaroni candy "
# Text message reply put_object append_object
@robot.text
def text_reply(message):
yaml_str = message.content
yaml = (
"---\ncontent: " + yaml_str.replace("\n", "<br>") + "\n---\n"
) # Save the content in yaml Field convenient dataview Use Replace line breaks to prevent errors
btyes = bytes(yaml + message.content, encoding="utf8")
name = time.strftime("%Y%m%d%H%M%S", time.localtime())
response = client.put_object(
Bucket=bucket,
Body=btyes,
Key=" Wechat collection /" + name + ".md",
)
return response["ETag"]
# Picture message
@robot.image
def image_reply(message):
# btyes = bytes("", encoding = "utf8") # Directly use Tencent link to display pictures
file = requests.get(message.img)
name = time.strftime("%Y%m%d%H%M%S", time.localtime())
response1 = client.put_object(
Bucket=bucket,
Body=file.content,
Key=" Wechat collection / The attachment /" + name + ".jpg",
)
conent = "![[ The attachment /" + name + ".jpg]]"
yaml = "---\ncontent: " + conent + "\n---\n"
btyes = bytes(yaml + conent, encoding="utf8")
response2 = client.put_object(
Bucket=bucket,
Body=btyes,
Key=" Wechat collection /" + name + ".md",
)
return response1["ETag"] + response2["ETag"]
@robot.error_page
def make_error_page(url):
return "404"
@robot.handler
def error_message(message):
return " Unsupported message type "
robot.config["HOST"] = "0.0.0.0"
robot.config["PORT"] = "8008"
robot.run()
Basic use
Scan code test number QR code , Then you can see that there is one more person in the user list . Then you can send a message .




Problems and shortcomings
- After all, official account has public attribute , Not for personal service . Maybe you can use to authenticate users id Methods to prevent irrelevant people from paying attention to and sending messages , But the best solution is to use the user system .
- The above program sometimes reports an error , Even collapsed . After all, it's just easy to write .
- When sending pictures , You can get a picture link in the background . But the picture will be compressed .
- Receive pictures to  Save form to yaml It can be dataview Displayed . But the above program chose to save the pictures to the local attachment folder and used ![[]] In the form of .
- About dataview Will not show md In the picture , I tried for a long time , It doesn't solve the problem .dataview No function to display the body was found ,yaml There is still a problem with the display . If someone solves hope email Tell me , Or by Bili, Bili Contact me , I will record in this article .
Related information
Framework documents used
Official account can be set up in Bili Bili website Search for werobot Study
COS and Obsidian plug-in unit Remotely Save Instructions : Obsidian Sync Remotely Save S3 Configuration Guide
边栏推荐
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
- Day 13 of hcip (relevant contents of BGP agreement)
- 8.8.4-PointersOnC-20220215
- Load and domcontentloaded in JS
- [IVX junior engineer training course 10 papers] 06 database and services
- Based on Simulink and FlightGear, the dynamic control of multi rotor UAV in equilibrium is modeled and simulated
- Two TVs
- Basic usage of three JS high-order functions --filter---map---reduce
- Study note 2 -- definition and value of high-precision map
- Iclr2022 | spherenet and g-spherenet: autoregressive flow model for 3D molecular graph representation and molecular geometry generation
猜你喜欢

Docker安装Oracle_11g

Minimize the error

Based on Simulink and FlightGear, the dynamic control of multi rotor UAV in equilibrium is modeled and simulated

Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
![[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface](/img/c9/3fe8693629a8452dcfdb4349ddee0d.png)
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface

ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)

Develop a simple login logic based on SSM

Datawhale 社区黑板报(第1期)

学习笔记24--多传感器后融合技术

技术大佬准备就绪,话题C位由你决定
随机推荐
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
UDS bootloader of s32kxxx bootloader
Day 13 of hcip (relevant contents of BGP agreement)
6-3漏洞利用-SSH环境搭建
PLC Analog input analog conversion FB s_ ITR (Mitsubishi FX3U)
【八大排序①】插入排序(直接插入排序、希尔排序)
MySQL winter vacation self-study 2022 12 (4)
About asp Net core uses a small detail of datetime date type parameter
Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
[dynamic planning] interval dp:p3205 Chorus
Basic usage of three JS high-order functions --filter---map---reduce
cookie、session、tooken
XMIND mind map
[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)
GL Studio 5 安装与体验
Liteos learning - first knowledge of development environment
Principle of finding combinatorial number and template code
969 interlaced string
Daily work and study notes
DTL dephossite | prediction method of dephosphorylation sites based on Transfer Learning