当前位置:网站首页>[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
边栏推荐
- [WesternCTF2018]shrine writeup
- 8.8.4-PointersOnC-20220215
- 【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
- Learning note 24 - multi sensor post fusion technology
- Datawhale 社区黑板报(第1期)
- Learning notes 25 - multi sensor front fusion technology
- Edge extraction edges based on Halcon learning_ image. Hdev routine
- Design and control of multi rotor aircraft (VII) -- sensor calibration and measurement model
- How to compress video size while adding watermark with one click?
- What skills does an excellent software tester need to master?
猜你喜欢

Learning notes 25 - multi sensor front fusion technology

Evolution of Himalayan self-developed gateway architecture

Entrepreneurship is a little risky. Read the data and do a business analysis

Edge extraction edges based on Halcon learning_ image. Hdev routine

Zak's latest "neural information transmission", with slides and videos

6-2漏洞利用-ftp不可避免的问题

Docker安装Oracle_11g

Liteos learning - first knowledge of development environment
![[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card](/img/99/53b0ae47bada8b0d4db30d0517fe3d.jpg)
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card

Data visualization in medical and healthcare applications
随机推荐
How can programmers better plan their career development?
SSO single sign on implementation.
What skills does an excellent software tester need to master?
Global and Chinese markets for maritime services 2022-2028: Research Report on technology, participants, trends, market size and share
ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
Day 13 of hcip (relevant contents of BGP agreement)
Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
About asp Net core uses a small detail of datetime date type parameter
Design and control of multi rotor aircraft (VII) -- sensor calibration and measurement model
Exclusive delivery of secret script move disassembly (the first time)
The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!
No converter found for return value of type: class
Global and Chinese market of collaborative applications 2022-2028: Research Report on technology, participants, trends, market size and share
首场“移动云杯”空宣会,期待与开发者一起共创算网新世界!
Datawhale community blackboard newspaper (issue 1)
Global and Chinese market of wireless charging magnetic discs 2022-2028: Research Report on technology, participants, trends, market size and share
Summary of Aix storage management
[JS download files through url]
[eight sorts ①] insert sort (direct insert sort, Hill sort)
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)