当前位置:网站首页>[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
边栏推荐
- [eight sorts ②] select sort (select sort, heap sort)
- Exclusive delivery of secret script move disassembly (the first time)
- We should make clear the branch prediction
- Basic usage of shell script
- cookie、session、tooken
- Global and Chinese markets for food allergens and intolerance tests 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of safety detection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- [IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
- cookie、session、tooken
- CTF daily question day45 sensor
猜你喜欢

Day 13 of hcip (relevant contents of BGP agreement)

Exclusive delivery of secret script move disassembly (the first time)
![[dynamic planning] interval dp:p3205 Chorus](/img/25/3dc7132e1aaa5c0eca87382692fc12.jpg)
[dynamic planning] interval dp:p3205 Chorus

How can I batch produce the same title for the video?

About asp Net core uses a small detail of datetime date type parameter

I'll teach you to visit Amazon RDS for a year and build a MySQL cloud database (only 10 minutes, really fragrant)

We should make clear the branch prediction

Data visualization in medical and healthcare applications

6-3 vulnerability exploitation SSH environment construction

DTL dephossite | prediction method of dephosphorylation sites based on Transfer Learning
随机推荐
学习笔记24--多传感器后融合技术
PLC Analog input analog conversion FB s_ ITR (Mitsubishi FX3U)
Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production
How does schedulerx help users solve the problem of distributed task scheduling?
Global and Chinese market of wireless charging magnetic discs 2022-2028: Research Report on technology, participants, trends, market size and share
Docker安装Oracle_11g
Viewing and modifying volume group attributes of Aix storage management (II)
Global and Chinese markets for context and location-based services 2022-2028: Research Report on technology, participants, trends, market size and share
[image enhancement] vascular image enhancement based on frangi filter with matlab code
Luogu p1775 stone merger (weakened version)
2022年6月国产数据库大事记
Mitsubishi PLC FX3U pulse axis jog function block (mc_jog)
【八大排序②】选择排序(选择排序,堆排序)
Bilstm CRF code implementation
Study note 2 -- definition and value of high-precision map
学习笔记2--高精度地图定义及价值
Basic usage of shell script
cookie、session、tooken
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production