In my daily work, I collect all kinds of information generated from the Internet and life to Bear, and then use Bear's cloud synchronization to keep the information on my various terminals consistent. When I used Youdao Cloud Notes in the past, there was a function that I liked very much. When I saw an article that I wanted to collect, I could send it directly to Youdao Cloud Notes in the upper right corner.
The need I am facing now is whether when I see an article I like, I can directly synchronize the article to Bear
on each of my terminals by clicking on the upper right corner分享一下
. The final effect is as follows:
To achieve the above requirements, I probably thought about the following solutions:
Prepare a WeChat account (directly called a trumpet here) to receive articles to be collected in Bear
Write a service to monitor the messages of the trumpet. For example, when receiving a tweet type message, the content will be extracted.
The monitoring service sends the extracted content to Bear (this requires the service to run on Mac OS)
So before proceeding, you need the following:
Basic Python basics (writing small scripts in Python is really convenient)
A Mac OS with Bear installed
git clone https://github.com/howie6879/w2b
cd w2b
# 推荐使用pipenv 你也可以使用自己中意的环境构建方式
pipenv install --python=/Users/howie6879/anaconda3/envs/python36/bin/python3.6 --skip-lock
# 运行前需要填好配置文件
pipenv run python w2b/run.py
First, please determine the following constants as mentioned in using WeChat to synchronize articles to Bear:
S_ACCOUNT_ID: WeChat sends account ID, which can be viewed under Account/userinfo.data
R_ACCOUNT_ID: WeChat receiving account ID, same as above
RAW_KEY: Decryption Key, which is the 64-bit string introduced above
DB_PATH_TEM: defines the message DB path, for example: "/Users/howie6879/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/{0}/Message /"
The corresponding is the configuration in w2b/config.py
:
import os
from w2b . utils . tools import gen_md5
class Config :
# 微信发送账户ID
S_ACCOUNT_ID = os . environ . get ( "S_ACCOUNT_ID" , "" )
# 微信接收账户ID
R_ACCOUNT_ID = os . environ . get ( "R_ACCOUNT_ID" , "" )
# 解密Key
RAW_KEY = os . environ . get ( "RAW_KEY" , "" )
# 消息DB路径
DB_PATH_TEM = "/Users/howie6879/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/{0}/Message/"
# 微信接收账户所有消息DB文件夹
MSG_DB_DIR = DB_PATH_TEM . format ( gen_md5 ( R_ACCOUNT_ID ))
# 与目标微信账户的聊天表
MSG_TABLE_NAME = f"Chat_ { gen_md5 ( S_ACCOUNT_ID ) } "
# 笔记Tag
BEAR_TAG = "资源/微信"
# 多久扫描一次,单位是S
INTERVAL = 10
Welcome to raise Issue
, I hope it can help you~