<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
    <title>IT Notes</title>
    <subtitle>Personal notes on software engineering, systems</subtitle>
    <link rel="self" type="application/atom+xml" href="https://blog.1192929.xyz/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://blog.1192929.xyz"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2025-01-15T00:00:00+00:00</updated>
    <id>https://blog.1192929.xyz/atom.xml</id>
    <entry xml:lang="zh-CN">
        <title>我的第二篇 IT 笔记：Python 小工具</title>
        <published>2025-01-15T00:00:00+00:00</published>
        <updated>2025-01-15T00:00:00+00:00</updated>
        
        <author>
          <name>刘林浩</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://blog.1192929.xyz/posts/second-post/"/>
        <id>https://blog.1192929.xyz/posts/second-post/</id>
        
        <content type="html" xml:base="https://blog.1192929.xyz/posts/second-post/">&lt;p&gt;记录一个常用的 Python 小工具：批量给目录下的文件添加日期前缀。它只依赖标准库，任何 Python 3.6+ 环境都能直接运行。&lt;/p&gt;
&lt;h2 id=&quot;jiao-ben&quot;&gt;脚本&lt;a class=&quot;zola-anchor&quot; href=&quot;#jiao-ben&quot; aria-label=&quot;Anchor link for: jiao-ben&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #E1E4E8; background-color: #24292E;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;import&lt;/span&gt;&lt;span&gt; pathlib&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;import&lt;/span&gt;&lt;span&gt; datetime&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #B392F0;&quot;&gt; add_date_prefix&lt;/span&gt;&lt;span&gt;(directory: pathlib.Path) -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt; int&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;Add a YYYY-MM-DD prefix to every regular file in the directory.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    today&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt; =&lt;/span&gt;&lt;span&gt; datetime.date.today().isoformat()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    renamed&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color: #FFAB70;&quot;&gt; file&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt; in&lt;/span&gt;&lt;span&gt; directory.iterdir():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #FFAB70;&quot;&gt; file&lt;/span&gt;&lt;span&gt;.is_file()&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt; and not&lt;/span&gt;&lt;span style=&quot;color: #FFAB70;&quot;&gt; file&lt;/span&gt;&lt;span&gt;.name.startswith(today):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FFAB70;&quot;&gt;            file&lt;/span&gt;&lt;span&gt;.rename(&lt;/span&gt;&lt;span style=&quot;color: #FFAB70;&quot;&gt;file&lt;/span&gt;&lt;span&gt;.with_name(&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt;{&lt;/span&gt;&lt;span&gt;today&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #FFAB70;&quot;&gt;file&lt;/span&gt;&lt;span&gt;.name&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            renamed&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt; +=&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; renamed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F97583;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt; __name__&lt;/span&gt;&lt;span style=&quot;color: #F97583;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt; &amp;quot;__main__&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #79B8FF;&quot;&gt;    print&lt;/span&gt;&lt;span&gt;(add_date_prefix(pathlib.Path(&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt;&amp;quot;.&amp;quot;&lt;/span&gt;&lt;span&gt;)))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;shi-yong-bu-zou&quot;&gt;使用步骤&lt;a class=&quot;zola-anchor&quot; href=&quot;#shi-yong-bu-zou&quot; aria-label=&quot;Anchor link for: shi-yong-bu-zou&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;把上面的脚本保存为 &lt;code&gt;prefix_dates.py&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;进入目标目录，运行 &lt;code&gt;python prefix_dates.py&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;检查输出：脚本会返回本次重命名的文件数量。&lt;/li&gt;
&lt;li&gt;如需回滚，把文件名开头的日期前缀删除即可。&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;shuo-ming&quot;&gt;说明&lt;a class=&quot;zola-anchor&quot; href=&quot;#shuo-ming&quot; aria-label=&quot;Anchor link for: shuo-ming&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;脚本跳过已经带当天前缀的文件，重复执行是幂等的。&lt;/li&gt;
&lt;li&gt;依赖零第三方库，Python 标准库即可满足。&lt;/li&gt;
&lt;li&gt;本文归入 &lt;code&gt;python&lt;/code&gt; 与 &lt;code&gt;tooling&lt;/code&gt; 两个标签，便于归档检索。&lt;/li&gt;
&lt;/ul&gt;
</content>
        
    </entry>
    <entry xml:lang="zh-CN">
        <title>我的第一篇 IT 笔记</title>
        <published>2025-01-01T00:00:00+00:00</published>
        <updated>2025-01-01T00:00:00+00:00</updated>
        
        <author>
          <name>刘林浩</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://blog.1192929.xyz/posts/first-post/"/>
        <id>https://blog.1192929.xyz/posts/first-post/</id>
        
        <content type="html" xml:base="https://blog.1192929.xyz/posts/first-post/">&lt;p&gt;这是我的第一篇技术笔记。本站使用 &lt;a rel=&quot;external&quot; href=&quot;https://www.getzola.org&quot;&gt;Zola&lt;/a&gt; 构建，它是一个用 Rust 编写的静态站点生成器。文章以 Markdown 编写，构建时自动生成带语法高亮的代码块、标签页和 Atom 订阅源。&lt;/p&gt;
&lt;h2 id=&quot;gou-jian-yu-bu-shu&quot;&gt;构建与部署&lt;a class=&quot;zola-anchor&quot; href=&quot;#gou-jian-yu-bu-shu&quot; aria-label=&quot;Anchor link for: gou-jian-yu-bu-shu&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;本地写文章，推送到 GitHub 后由 Cloudflare Pages 自动构建并部署：&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #E1E4E8; background-color: #24292E;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #B392F0;&quot;&gt;zola&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt; build&lt;/span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;                  # 生成静态文件到 public/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #B392F0;&quot;&gt;zola&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt; serve&lt;/span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;                  # 本地预览：http://127.0.0.1:1111&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #B392F0;&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color: #9ECBFF;&quot;&gt; push origin main&lt;/span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        # 推送后 Cloudflare Pages 自动部署&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;bu-shu-liu-cheng&quot;&gt;部署流程&lt;a class=&quot;zola-anchor&quot; href=&quot;#bu-shu-liu-cheng&quot; aria-label=&quot;Anchor link for: bu-shu-liu-cheng&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;下面用 ASCII 图画出代码从编辑到上线的完整流程：&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #E1E4E8; background-color: #24292E;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+----------+      +-----------+      +-----------+      +-------------+&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|  Markdown | ---&amp;gt; |  zola     | ---&amp;gt; |  public/  | ---&amp;gt; | Cloudflare  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|  文章文件  |      |  build    |      |  静态文件  |      | Pages       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+----------+      +-----------+      +-----------+      +-------------+&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                     +-----&amp;gt; GitHub 仓库（版本管理并触发部署）&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;注意：&lt;code&gt;text&lt;/code&gt; 代码块中的对齐依赖等宽字体和 &lt;code&gt;white-space: pre&lt;/code&gt;，排版时请使用空格对齐，不要依赖制表符。&lt;/p&gt;
&lt;h2 id=&quot;tu-pian&quot;&gt;图片&lt;a class=&quot;zola-anchor&quot; href=&quot;#tu-pian&quot; aria-label=&quot;Anchor link for: tu-pian&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;站内图片放在 &lt;code&gt;static/images/&lt;/code&gt; 下，文章中用 Markdown 语法引用：&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/example.svg&quot; alt=&quot;示例图片：构建流程占位图&quot; /&gt;&lt;/p&gt;
&lt;p&gt;页面加载后由 &lt;code&gt;main.js&lt;/code&gt; 为所有图片统一加上 &lt;code&gt;loading=&quot;lazy&quot;&lt;/code&gt;，实现懒加载。&lt;/p&gt;
</content>
        
    </entry>
</feed>
