首页
归档
逛逛与留言
关于
Search
1
执勿山爬山游记
102 阅读
2
AI的使用第二期
91 阅读
3
捏泥巴
87 阅读
4
备案了!记录下
82 阅读
5
博客捣鼓记
67 阅读
默认分类
生活随记
代码编程
看看风景
学习记录
登录
Search
标签搜索
日常
Shu
累计撰写
32
篇文章
累计收到
53
条评论
首页
栏目
默认分类
生活随记
代码编程
看看风景
学习记录
页面
归档
逛逛与留言
关于
搜索到
32
篇与
的结果
2024-11-29
obsidian发布一键发布typecho
2024-11-28 21:28怎么说了,obsidan 的编辑的体验还是很不错的,如果可以直接发布到博客会方便些拾月的文章,网上看到这个博主很早之前就这么弄,很有参考价值,tks!于是也大致这么弄了下,修改小部分内容。思路:主要就是通过 xmlrpc 这个 api 来上传文章METAWEBLOG_API = 'http://xxxx/index.php/action/xmlrpc'补充上传结构这个分类这里是 list,数组形式的;post_type 里面 post 是文章,还有一个 page 应该是页面倒数第 2 个是是否允许评论cid 与 slugslug 好像是一个自定义软连接,不是太会弄,忽略掉了。cid 是 typecho 的一个由博客生成的 int 类型数字,代表了某一篇文章,拾月的 blog 里面用到了来控制更新,我大致也是这么弄的,但是我使用本地 json 文件控制的。图床用的 picList,很方便,可以用 alist 作为图床,alist 要有外部地址即可!😄👍还是可以的,可以直接在本地发。代码用的插件那个 python_scipter, 代码如下:# 脚本1 #!/usr/local/bin/python3 # -*- coding: UTF-8 -*- import xmlrpc.client import datetime import json import time import re import sys import os from post_img_alist import * #import yaml # 个人信息配置 BLOG_USERNAME = '' # 博客用户名 BLOG_PASSWORD = '' # 博客密码 OB_VAULT = '' # Obsidian的vault目录 PICTURE_PATH = r"" # 本地保证图片的目录,即我的Obsidian附件目录 METAWEBLOG_API = 'http://xxxx/index.php/action/xmlrpc' # 博客metaweblog api地址 JSON_FILE_PATH = r"cid.json" # 保存文件名和cid的json文件路径 我写的绝对路径 def save_cid(filename, cid): """ 将文件名和对应的 CID 保存到本地 JSON 文件中。 如果 JSON 文件不存在,会创建一个新文件。 如果已存在,则追加新的数据。 """ data = {} # 如果文件已存在,先读取现有数据 if os.path.exists(JSON_FILE_PATH): with open(JSON_FILE_PATH, "r", encoding="utf-8") as f: try: data = json.load(f) except json.JSONDecodeError: data = {} # 如果文件内容为空或损坏,初始化为空字典 # 更新数据 data[filename] = cid # 保存到 JSON 文件 with open(JSON_FILE_PATH, "w", encoding="utf-8") as f: json.dump(data, f, indent=4, ensure_ascii=False) def get_cid(filename): """ 从本地 JSON 文件中读取指定文件名的 CID。 如果不存在对应的文件名,返回 0。 """ # 如果文件不存在,直接返回 0 if not os.path.exists(JSON_FILE_PATH): return 0 # 读取 JSON 文件 with open(JSON_FILE_PATH, "r", encoding="utf-8") as f: try: data = json.load(f) except json.JSONDecodeError: return 0 # 如果文件内容为空或损坏,返回 0 # 返回 CID 或 0 return data.get(filename, 0) def custom_replace_func(match_ct): Name = str(match_ct).split("/")[-1] fileName = PICTURE_PATH+"\\"+Name isOk,web_url = post_upload(fileName) if isOk: return web_url else: return str(f"") def process_md_content(md_content): """ 处理 Markdown 内容,提取被 ) 包裹的内容,并替换为自定义内容。 :param md_content: 原始 Markdown 内容 :param custom_replace_func: 自定义替换函数,接受一个字符串参数,返回替换后的内容 :return: 替换后的 Markdown 内容 """ # 定义匹配模式 pattern = r"!\[\[(.*?)\]\]" # 使用正则提取所有被 ) 包裹的内容 matches = re.findall(pattern, md_content) # 遍历提取的内容,并使用自定义函数替换 for idx,match in enumerate(matches): # 获取自定义替换内容 replacement = custom_replace_func(match) # 将原内容替换为新的内容 md_content = md_content.replace(f"", f"") return md_content def read_md(file_path): with open(file_path, 'r', encoding='utf-8') as file: content = file.read() file_name = os.path.splitext(os.path.basename(file_path))[0] content = process_md_content(content) return content, file_name # JSON文件路径,全局使用 json_file_path_record = r"file_record.json" def write_to_json_file(full_path, cid): """ 向 JSON 文件中写入数据。检查 full_path 是否已存在,若不存在则新增。 :param full_path: 文件完整路径 (键) :param cid: 文件对应的 CID (值) """ # 初始化数据存储 data = {} # 如果 JSON 文件存在,读取内容 if os.path.exists(json_file_path_record): try: with open(json_file_path_record, 'r', encoding='utf-8') as file: data = json.load(file) except Exception as e: # 如果文件读取失败,打印错误,但继续初始化空数据 print(f"读取 JSON 文件失败: {e}") data = {} # 检查 full_path 是否已存在 if full_path in data: print(f"路径 {full_path} 已存在,跳过写入。") return # 添加新的 full_path 和 cid data[full_path] = cid # 写入更新后的数据到 JSON 文件 try: with open(json_file_path_record, 'w', encoding='utf-8') as file: json.dump(data, file, ensure_ascii=False, indent=4) print(f"已成功写入 {full_path} 和 {cid} 到文件。") except Exception as e: print(f"写入 JSON 文件失败: {e}") # 创建文章,若文件已经存在,则自动更新, # 入参:file要发布的文件,post_type发布类型(post-文章,page:页面) def new_post(file_path): content,filaName = read_md(file_path) # slug = data['meta']['slug'] # cid = get_cid(slug) cid = get_cid(filaName) # 构建发布内容 struct = { 'title': filaName, 'dateCreated': datetime.datetime.now(), #'wp_slug': slug, 'categories': ['生活随记'], # 分类 #'mt_keywords': data['meta']['blogtags'], # 标签 'post_type': 'post', 'mt_allow_comments': True, 'description': content, } client = xmlrpc.client.ServerProxy(METAWEBLOG_API) if int(cid) > 0: try: result = client.metaWeblog.editPost(cid, BLOG_USERNAME, BLOG_PASSWORD, struct, True) print('\n文章已存在(cid={cid}),更新成功,信息如下:\n'.format(cid=cid)) for key, value in struct.items(): if key != 'description': print(key, ': ', value) print('\n') except Exception as e: print(e) else: cid = client.metaWeblog.newPost('',BLOG_USERNAME, BLOG_PASSWORD, struct, True) if cid != 0: save_cid(str(filaName), str(cid)) print('\n发布成功(cid={cid}),信息如下:\n'.format(cid=cid)) for key, value in struct.items(): if key != 'description': print(key, ': ', value) print('\n') write_to_json_file(file_path, cid) #还要保存下文件路径和cid的映射关系; python_script = sys.argv[0] file_path = sys.argv[2] vault_path = sys.argv[1] abs_file_path = os.path.abspath(os.path.join(vault_path, file_path)) #filepath = r"typcho测试草稿.md" new_post(abs_file_path)import requests import json import os localImg_url_jsonPath = r"xxx.json" def write_localimg(local_path, network_path): # Initialize an empty dictionary to store the data data = {} # Check if the JSON file exists if os.path.exists(localImg_url_jsonPath): try: # Load existing data from the JSON file with open(localImg_url_jsonPath, 'r', encoding='utf-8') as file: data = json.load(file) except Exception as e: # Handle JSON file read/parsing errors data = {} # Add or update the mapping for the given local path data[local_path] = network_path # Write the updated data back to the JSON file with open(localImg_url_jsonPath, 'w', encoding='utf-8') as file: json.dump(data, file, ensure_ascii=False, indent=4) def check_localimg(image_url): # Check if the JSON file exists if not os.path.exists(localImg_url_jsonPath): return False, "" try: # Load the JSON file with open(localImg_url_jsonPath, 'r', encoding='utf-8') as file: data = json.load(file) # Check if the local image path exists in the JSON if image_url in data: return True, data[image_url] else: return False, "" except Exception as e: # Handle JSON file read/parsing errors return False, "" def post_upload(image_url): is_have,web_url = check_localimg(image_url) if is_have: return True, web_url url = "http://127.0.0.1:36677/upload?xxxxx" # alist的上传链接 headers = {'Content-Type': 'apication/json'} payload = {"list": [image_url]} try: response = requests.post(url, headers=headers, data=json.dumps(payload)) if response.status_code == 200: result = response.json() success = result.get("success", False) uploaded_url = result.get("result", []) uploaded_url = uploaded_url[0] write_localimg(image_url, uploaded_url) return success, uploaded_url else: return False, [] except Exception as e: return False, [] if __name__ == "__main__": img_url = r"xxFigure_1.png" success, uploaded_url = post_upload(img_url) print(success, uploaded_url)
2024年11月29日
30 阅读
0 评论
0 点赞
2024-11-28
《星际外婆的饺子计划》
《星际外婆的饺子计划》在银河系边缘的一个名为“咸水湖”的星球上,住着一个奇怪的老太太,她叫做外婆(没有名字,大家都叫她外婆)。外婆的家是宇宙中最不起眼的一个小屋,但这小屋里藏着一台能连接所有星系的“饺子投递机”。传说,任何人只要吃过外婆的饺子,就会记得自己从哪里来,知道自己是谁。宇宙的饺子传说故事开始在银河历 3024 年,地球早已灭亡,整个人类文明散落在星系的各个角落。人们记不得自己的祖先是谁,甚至连“家”这个概念也早已遗忘。所有的星际语言被统合为一种冷冰冰的“算法语言”,连简单的问候都变成了“我对你无恶意”。但外婆却与众不同。她是宇宙中唯一还会手工包饺子的人。外婆的饺子有一种神奇的力量,吃过的人会梦见自己的故乡,无论故乡是地球、火星,还是一颗在黑洞边缘的孤独星球。小机器人阿咕的意外造访一天,一台迷路的小机器人“阿咕”来到外婆的小屋。阿咕是银河配送公司的失效机器人,它被设定为“永远完成使命”,但因能源不足而失去导航功能。它跌跌撞撞地走进小屋,第一句是:“检测到非逻辑生物体,是否需要回收?”外婆笑了,端出一盘热气腾腾的饺子,说:“吃吧,小家伙,你看起来很饿。”阿咕愣了一下:“能源补充指令不匹配此行为。”“吃了就知道。”外婆眨眨眼。阿咕尝了一口饺子。几秒后,它的光学镜头里居然流出一滴油状液体。原来,阿咕的核心代码是由一个孤独的程序员写的,而这位程序员的母亲最拿手的,就是韭菜鸡蛋馅饺子。“我记得了……我有个家。”阿咕的声音第一次带着颤抖。饺子计划的开启阿咕不想再孤独地漂泊,它提议帮助外婆,用自己的配送功能把饺子送到宇宙每个角落,让所有人都能找到自己的根。外婆点点头,拿出一张古老的地球地图,上面标满了人类失落的家园。两人一拍即合,从此开始了“星际饺子计划”。阿咕升级了自己的推进系统,外婆每天包饺子、做馅料,把一颗颗小饺子装进宇宙专用真空饺子盒。反对的势力但饺子的香气引来了不速之客——银河政府。他们害怕外婆的饺子唤醒人类的记忆,因为记忆意味着渴望,渴望会引发反抗,而反抗是他们最害怕的事。银河政府派来了一支全副武装的机器人军队包围了小屋。外婆站在门口,手里端着一盘饺子,对为首的指挥官说:“来尝尝吧,孩子。”机器人指挥官冷冷地说:“情绪模拟程序无此需求。”外婆叹了口气,把饺子放在地上,转身进屋。几分钟后,饺子的香气弥漫开来,整个机器人军队居然短路了。他们的程序突然涌入了陌生的数据:一只小猫的蹭腿、一片宁静的稻田、父母的拥抱……连指挥官也怔住了,冷漠的光学镜头闪了一下。“这……是家?”结局:饺子与宇宙的重逢最后,银河政府停止了围剿,甚至主动协助饺子计划。外婆和阿咕的饺子送遍了整个宇宙。无论是人类还是机器人,无论是有机生命还是无机生命,每个吃过饺子的人(或存在)都会记住一个简单的事实:“我们并不孤单。”外婆却始终不说自己的故乡在哪。直到有一天,她也变成了一颗饺子,消失在星空中。阿咕将最后一个饺子放进机器,悄悄落下一滴油泪,轻声说:“外婆,我想你。”传说,外婆的饺子最终连黑洞里的生命都尝到了。科幻的温情这并不是一个拯救宇宙的故事,而是一个拯救记忆的故事。饺子虽小,却像一颗颗星星,连接了所有人的心。
2024年11月28日
28 阅读
0 评论
0 点赞
2024-11-25
神奇bug
记录下今天的遇到的神奇bug,2024-11-25 ,21:56程序在windows下转为了qt creator的项目,让后在arm linux麒麟上运行,一个label突然就出错了,我的label上面写的(AAA\nBBB)本来应该是AAA一行BBB一行,排列的好好,但是编译出来就是AAA一行,然后空了一行,再才是BBB,摸不着头脑🧠。解决的也很奇葩,我把ui文件用designer打开,把\n删了,又输入了一遍,好了!?其他几个相同问题的label也好了,我都没有动😂感谢万能了网友上周5的时候,那个qt翻译ts文件,真的是多,200多条词语和句子,那个啥ts还是个必须是utf-8的奇怪xml结构,不像自己写工具,在网上找了找,还真有这样的工具,感谢网友,Qt-ts翻译工具, 帮忙节省了大量时间,先用这个把ts转为了xlsx,然后用本地的ollama 翻译了下,good😂,有瑕疵但是也可以tk 大模型import ollama def fanyiollama(danci): wenti = "翻译为英语:%s,注意第一个字母大写,直接给出英文翻译,甚至不要引号,重点直接给出英文翻译"%(danci) # 如果Ollama的host和port未更改,使用默认设置 res = ollama.chat(model="qwen2.5-coder:7b", stream=False, messages=[{"role": "user", "content": wenti}], options={"temperature": 0}) fanyi = res['message']['content'] print(res['message']['content']) return fanyi import openpyxl import os from fanyi2 import fanyiollama # 定义翻译函数(这里你可以替换为实际的翻译函数) def translate(text): return f"Translated: {text}" # 读取xlsx文件 input_file = r'G:\MyCodeGP\python\ollama翻译ts\untitled.xlsx' output_file = r'G:\MyCodeGP\python\ollama翻译ts\output_translated.xlsx' # 加载工作簿 if not os.path.exists(input_file): raise FileNotFoundError(f"File '{input_file}' not found!") workbook = openpyxl.load_workbook(input_file) sheet = workbook.active # 遍历第一列,查找第一列有值,第二列和第三列为空的单元格 for row in range(2, sheet.max_row + 1): # 假设第一行是标题,从第二行开始 first_col_value = sheet.cell(row=row, column=1).value second_col_value = sheet.cell(row=row, column=2).value third_col_value = sheet.cell(row=row, column=3).value if first_col_value and not second_col_value and not third_col_value: # 使用翻译函数将第一列的内容翻译,并保存到第二列和第三列 translated_text = fanyiollama(first_col_value) sheet.cell(row=row, column=2, value=translated_text) sheet.cell(row=row, column=3, value=translated_text) # 保存为新的xlsx文件 workbook.save(output_file) print(f"Translation complete. Results saved to '{output_file}'")
2024年11月25日
21 阅读
0 评论
0 点赞
2024-10-13
弄了一个火车票查询软件
用python弄了个火车票查询的,主要是想快点看看有哪些火车票hhh 感兴趣的可以看看 https://wwzw.lanzoup.com/icUop2cfnb4d
2024年10月13日
29 阅读
0 评论
0 点赞
2024-08-09
歌曲分享-青山绿野
分享一首特别喜欢的歌,《青山绿野》,渡边雅二弹奏的一首钢琴曲,他写了一首《遥远的西安》hh,:[ablobcatreachrev] ,相对日本,西安确实很远了[bsmp3][mp3 url="https://a.siyouyun.ren:30597/d/alist/%E5%A4%96%E9%83%A8%E7%9B%AE%E5%BD%95/MUSIC/%E9%9D%92%E5%B1%B1%E7%BB%BF%E9%87%8E.mp3?sign=l6Zg_B9o1O4HBGY_fcEivo4ZdK3allYCYJsfQ4SyUpA=:0" singer="渡边雅二" name="青山绿野" image="歌曲封面图地址"][mp3 url="https://a.siyouyun.ren:30597/d/alist/%E5%A4%96%E9%83%A8%E7%9B%AE%E5%BD%95/MUSIC/%E9%81%A5%E8%BF%9C%E7%9A%84%E8%A5%BF%E5%AE%89-%E6%B8%A1%E8%BE%B9%E9%9B%85%E4%BA%8C.mp3?sign=p0YuirkiWrql8b_KIrxQbLRD9CGQz51_dSnOTzAtBEg=:0" singer="渡边雅二" name="遥远的西安" image="歌曲封面图地址"][/bsmp3]
2024年08月09日
15 阅读
0 评论
2 点赞
1
2
3
4
...
7