跳到主要内容

路线 3 · AI 每日极客早报与电子墨水报纸实战

💻 工程源码路径github.com/Xepanda/kindle-geek-toolbox/tree/master/ai_newspaper

每天清晨自动汇总 AI 前沿进展、GitHub 趋势与技术短评,排版成高颜值的 Vintage 极客早报 (600×800 竖屏) 推送到 Kindle。


1. 报纸版面排版设计 (Editorial Layout)


2. 核心代码 (generate_newspaper.py)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Kindle 8 (600x800 Portrait) AI Daily Tech Briefing & Newspaper Generator
"""
import os, sys, subprocess
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont

WIDTH, HEIGHT = 600, 800

def render_newspaper(output_path='newspaper.png'):
img = Image.new('L', (WIDTH, HEIGHT), color=255)
draw = ImageDraw.Draw(img)

font_path = "C:\\Windows\\Fonts\\msyh.ttc"
font_h1 = ImageFont.truetype(font_path, 20)
font_h2 = ImageFont.truetype(font_path, 16)
font_body = ImageFont.truetype(font_path, 14)
font_serif = ImageFont.truetype("C:\\Windows\\Fonts\\georgia.ttf", 24)

# 1. 经典复古双线报头 (Y: 20 ~ 95)
draw.line([(20, 20), (580, 20)], fill=0, width=3)
draw.text((120, 28), "THE DAILY GEEK TRIBUNE", fill=0, font=font_serif)
draw.text((190, 62), "极客技术早报 · 深度思考与技术快讯", fill=60, font=ImageFont.truetype(font_path, 12))
draw.line([(20, 88), (580, 88)], fill=0, width=3)

# 2. 深度 AI 浪潮卡片 (Y: 120 ~ 360)
draw.rectangle([(20, 120), (580, 360)], fill=255, outline=0, width=1)
draw.text((30, 126), "🤖 深度AI · AGENT 浪潮与代码结对", fill=0, font=font_h2)

# 3. GitHub 开源头条 (Y: 375 ~ 585)
draw.rectangle([(20, 375), (580, 585)], fill=255, outline=0, width=1)
draw.text((30, 381), "⭐ GITHUB 开源头条与极客精选", fill=0, font=font_h2)

# 4. 每日单词 (Y: 600 ~ 775)
draw.rectangle([(20, 600), (580, 775)], fill=248, outline=0, width=1)
draw.text((30, 612), "📖 每日单词 · WORD OF THE DAY", fill=0, font=font_h2)
draw.text((30, 642), "Serendipity [ˌserənˈdɪpəti]", fill=0, font=font_body)

img.save(output_path)
return output_path

def push_newspaper(img_path='newspaper.png'):
subprocess.run(f'scp -o ConnectTimeout=4 "{img_path}" root@kindle:/mnt/us/newspaper.png', shell=True)
subprocess.run('ssh kindle "eips -c; eips -g /mnt/us/newspaper.png"', shell=True)

if __name__ == '__main__':
push_newspaper(render_newspaper())

3. 实机效果与体验

推送后,Kindle 墨水屏立刻展现出极具古典报纸油墨质感的 600×800 竖版版面,无背光刺眼感,是清晨早餐阅读的绝佳伴侣。