当前位置:网站首页>[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
边栏推荐
- Learning note 3 -- Key Technologies of high-precision map (Part 1)
- Circular statements in shell programming
- ECS project deployment
- 970 golang realizes the communication between multithreaded server and client
- [JS download files through url]
- The pain of Xiao Sha
- Comprehensive broadcast of global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Data visualization in medical and healthcare applications
- Shell Function
- Mathematics - feelings -20220215
猜你喜欢

6-3 vulnerability exploitation SSH environment construction

PLC Analog input analog conversion FB s_ ITR (Mitsubishi FX3U)
![[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)](/img/a6/a2afdf9e18255c9171f61bf074998b.png)
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)

With the acquisition of Xilinx, AMD is more than "walking on two legs" | Jiazi found

技术大佬准备就绪,话题C位由你决定

【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
![[IVX junior engineer training course 10 papers to get certificates] 09 chat room production](/img/a8/25215e74162b7ab3f29df65681932b.jpg)
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production

Develop a simple login logic based on SSM

gradle
![[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me](/img/b8/31a498c89cf96567640677e859df4e.jpg)
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
随机推荐
What skills does an excellent software tester need to master?
Day 13 of hcip (relevant contents of BGP agreement)
Global and Chinese markets for food allergens and intolerance tests 2022-2028: Research Report on technology, participants, trends, market size and share
[IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
Creating logical volumes and viewing and modifying attributes for AIX storage management
Global and Chinese markets for distributed generation and energy storage in telecommunications networks 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode, 3 repeatless longest subsequence
什么是商业养老保险?商业养老保险安全靠谱吗?
Mathematics - feelings -20220215
Variables and constants of go language foundation
How does schedulerx help users solve the problem of distributed task scheduling?
cookie、session、tooken
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
Leetcode 45 Jumping game II (2022.02.14)
Creation of volume group for AIX storage management (I)
Iclr2022 | spherenet and g-spherenet: autoregressive flow model for 3D molecular graph representation and molecular geometry generation
[WesternCTF2018]shrine writeup
Cat Party (Easy Edition)
Basic usage of shell script