当前位置: 首页 > wzjs >正文

北京市住房及城乡建设网站电脑培训班速成班

北京市住房及城乡建设网站,电脑培训班速成班,重庆招标网官网,做媛网站一、背景 当我们使用Joplin时,上传图片时会自动上传到Joplin服务器并替换链接 但是Joplin的编辑器不好用,我更习惯用Typora来编辑, 然而Typora中上传的图片只能在本地,无法上传到Joplin服务器,在其他客户端也看不到图片…

一、背景

当我们使用Joplin时,上传图片时会自动上传到Joplin服务器并替换链接

但是Joplin的编辑器不好用,我更习惯用Typora来编辑,

然而Typora中上传的图片只能在本地,无法上传到Joplin服务器,在其他客户端也看不到图片

本文编写了一个脚本,通过Typora的上传服务器功能,自动上传图片并替换为Joplin链接

二、准备脚本

2.1 第一个脚本,修改token

token可以在网页剪藏器中获取

在这里插入图片描述

import requests
import sys
import json
import subprocess# 修改为你的token
token = "请修改我"
# WARNING: replace 41184 with your joplin web clipper port
port = 41184
# 修改为你的python路径
python_exe_path = r'C:\Users\realw\AppData\Local\Microsoft\WindowsApps\python.exe'
# 修改为你的第二个脚本路径
second_script_path = r'D:\app\Typora\job\typora-windows-2.py'# collect args for typora-windows-2.py
args = []
for arg in sys.argv:# the first arg is .py file, ignore itif(".py" in arg):continue# the second arg is the current editing file passed by Typoraif(".md" in arg):args.append(arg)continue# other arg is the local Typora-Image path passed by Typoraurl = "http://127.0.0.1:" + str(port) + "/resources/?token=" + tokenpayload = {'props': '{}'}files = [('data', ('typora.png', open(arg, 'rb'), 'image/png'))]headers = {}# upload your images to joplin resources using joplin web clipper APIresponse = requests.request("POST", url, headers=headers, data=payload, files=files)newFilePath = "http://127.0.0.1:" + str(port) + "/resources/" + json.loads(response.text)["id"] + "/file?token=" + token# print newFilePath, so Typora can replace the local-typora-image path with the joplin web clipper url.# We cannot directly use "resources/" + json.loads(response.text)["id"] + ".png" since Typora thinks it is an illegal URL,# and a warning will show up.print(newFilePath)args.append(newFilePath)args.append("resources/" + json.loads(response.text)["id"] + ".png")# first arg is .py file, second arg is .md file, then newFilePath and "resources/" + json.loads(response.text)["id"] + ".png" appear in order
# We use subprocess because Typora will wait for the result of the first script and then replace the Typora_local_path with newFilePath.
# If we don't use subprocess, our replacement will be ahead of Typora's, and covered by Typora, which makes newFilePath as the final result link.
# This is not what we want, we want "resources/" + json.loads(response.text)["id"] + ".png" as the result.
subprocess.Popen([python_exe_path, second_script_path] + args, creationflags=subprocess.DETACHED_PROCESS, shell=False)sys.exit()

2.1 准备第二个脚本,按需修改delay时间

import sys
import time# We need to wait Typora's replacement happens first
delay_time = 5# Typora 将 typora-local-image-link 替换为 web-clipper-link 后,
# 而您没有按“ctrl + s”保存,您的内容不会“提交”到当前文件,
# 这使得 python 无法检测到 web-clipper-link 并将其替换为 joplin-resources-link。
# 因此我们至少重试该函数 10 次以等待您的保存。(如果您在 50 秒内没有按“ctrl + s”保存,则替换将失败)
retry_times = 10
time.sleep(delay_time)for i in range(retry_times):try:with open(sys.argv[1], 'r+', encoding='utf-8') as file:file_content = file.read()file_content_copy = file_contentfor index, arg in enumerate(sys.argv):if ((".png" in arg) or (".md" in arg) or (".py" in arg)):continue# replace newFilePath with "resources/{id}.png"file_content = file_content.replace(sys.argv[index], sys.argv[index + 1])file.seek(0)file.write(file_content)file.truncate()time.sleep(delay_time)except Exception as e:print(f"An error occurred: {e}")time.sleep(delay_time)
sys.exit()

3. 修改Typora配置

在这里插入图片描述

选择图象,上传服务,命令,确保你的python环境和模块正确

python D:\app\Typora\job\typora-windows.py ${filepath}

点击验证图片上传
在这里插入图片描述

4 在编辑器内测试

用法:

在编辑器内粘贴图片,按下ctrl+s 保存,等待几秒后自动替换为内部连接,大公告成

如果遇到问题,可以手动点击上传图片,检查顶部报错

在这里插入图片描述

http://www.dtcms.com/wzjs/114913.html

相关文章:

  • 服务器维护廊坊百度快照优化哪家服务好
  • 惠州做网站的公司全网推广方案
  • 网站图片展示源码最新网站发布
  • 日本建筑网站大数据网络营销
  • 酒店网站设计公司网站seo工具
  • 宁远县建设局网站一网信息一个简单便捷的新闻网站
  • 找外包做网站不给代码seo标题关键词优化
  • 买卖域名的网站免费推广软件 推广帮手
  • t.cn这种网站怎么做的重庆森林为什么不能看
  • 烟台网站排行榜江小白网络营销案例
  • 网站建设方案实例虎扑体育网体育
  • 织梦html5手机网站模板广东全网推广
  • 园艺建设网站竞价排名服务
  • 关于电商网站规划方案网络推广渠道都有哪些
  • 做网站页面代码国内电商平台有哪些
  • 表白网站是怎么做的百度引擎搜索
  • 网站建设优化价格网络销售真恶心
  • 廊坊建设网站外贸建站推广公司
  • 网站顶部轮播怎么做的如何免费注册一个网站
  • 亳州网站建设搜收录网
  • 公司想做个网站应该怎么做网时代教育培训机构怎么样
  • 做网站最小的字体是多少钱百度竞价怎么开户
  • 网站建设方案大全关键词seo公司真实推荐
  • 郑州模板网站建设品牌运营策划方案
  • 哪些免费的网站可以做企业宣传各地疫情最新消息
  • 做的不错的网站写软文怎么接单子
  • 2024新冠疫情数据实时动态seo网络营销外包公司
  • 常用分类信息网站企业培训课程有哪些
  • 办公室工作绩效 网站建设深圳网络公司推广公司
  • 建设银行商城网站什么叫关键词