Skip to content

Instantly share code, notes, and snippets.

@JiapengLi
Last active Apr 20, 2021
Embed
What would you like to do?
使用命令行创建flomo
#!/bin/env python
# -*- coding: UTF-8 -*-
import os, sys, re
import requests
import subprocess
'''
## 使用方法
0. 安装python,安装requests包 (pip install requests)
1. 系统创建环境变量FLOMOAPI,内容可于https://flomoapp.com/mine?source=incoming_webhook 获取
2. 保存此 python 源码文件至本地路径,命名为flomo.py
3. 将存放flomo.py的路径添加至系统PATH路径中
## 利用命令发送 MEMO
执行 flomo.py '文本...'
### 利用编辑器编辑并发送
创建 FLOMOEDITOR 环境变量
- vscode: code --wait
- sublime: subl -w
运行 flomo.py
## 说明
1. 文本中不包含#的,将会增加`#待整理`标签
2. 独立的文本参数分行记录
## 注意
- 命令行输入#,请使用单引号括起来,否则会被当成注释
- 文本中有空格的,请使用单引号括起来,否则会被识别为多行
'''
def flomo_post(flomoapi, headers, content):
print(flomoapi)
r = requests.post(flomoapi, headers=headers, json={'content':f'{content}'})
print("----------------")
print(content)
print("----------------")
print(r)
print(r.__dict__)
print(r._content)
if r.status_code == 200:
print ('MEMO 创建成功')
else:
print ('MEMO 创建失败。内容宝贵,请注意保存!')
headers = {'Content-Type': 'application/json;charset=UTF-8'}
flomoapi = os.getenv('FLOMOAPI')
flomoeditor = os.getenv('FLOMOEDITOR')
if not flomoapi:
print("请先创建 FLOMOAPI 环境变量")
exit()
content=''
if len(sys.argv) <= 1:
if not flomoeditor:
print("请先创建 FLOMOEDITOR 环境变量")
exit()
print('hint: Waiting for your editor to close the file... ')
print('提示: 正在等待编辑器关闭文件... ')
sys.stdout.flush()
# c = subprocess.run(["subl", "-w", "FLOMO_EDITMSG"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# print(c.stdout.decode('utf-8'))
stream = os.popen(flomoeditor + ' ' + "FLOMO_EDITMSG")
output = stream.read()
with open('FLOMO_EDITMSG', "r", encoding='utf-8') as f:
content = f.read()
# print("姿势不对。用法:flomo.py '文本...'")
# exit()
else:
for argv in sys.argv[1:]:
content += argv + '\n'
if '#' not in content:
content = '#待整理\n' + content
flomo_post(flomoapi, headers, content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment