如何用脚本快速生成名片

wen 实用脚本 3

本文目录导读:

如何用脚本快速生成名片

  1. 方案1:Python脚本生成HTML名片(最实用)
  2. 方案2:超简单Shell脚本一键生成
  3. 方案3:一键生成HTML名片(最快速)
  4. 使用推荐

我来帮你生成一个快速创建名片的脚本,这里提供几种不同方式:

方案1:Python脚本生成HTML名片(最实用)

import json
import os
from datetime import datetime
def generate_business_card():
    """交互式生成名片HTML文件"""
    # 收集名片信息
    card_data = {
        "name": input("姓名: "),
        "title": input("职位: "),
        "company": input("公司: "),
        "phone": input("电话: "),
        "email": input("邮箱: "),
        "website": input("网站(可选): "),
        "address": input("地址(可选): "),
        "color": input("主题色 (如 #2196F3): ") or "#2196F3"
    }
    # HTML模板
    html_template = f"""
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>{card_data['name']} - 名片</title>
        <style>
            .card {{
                width: 350px;
                height: 200px;
                background: linear-gradient(135deg, {card_data['color']}, {card_data['color']}88);
                border-radius: 15px;
                padding: 25px;
                color: white;
                font-family: 'Arial', sans-serif;
                box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            }}
            .name {{ font-size: 24px; font-weight: bold; margin-bottom: 5px; }}
            .title {{ font-size: 14px; opacity: 0.9; margin-bottom: 15px; }}
            .info {{ font-size: 12px; opacity: 0.8; line-height: 1.8; }}
            .company {{ font-size: 16px; margin-bottom: 10px; }}
        </style>
    </head>
    <body>
        <div class="card">
            <div class="name">{card_data['name']}</div>
            <div class="title">{card_data['title']}</div>
            <div class="company">{card_data['company']}</div>
            <div class="info">
                📞 {card_data['phone']}<br>
                ✉️ {card_data['email']}<br>
                {f"🌐 {card_data['website']}<br>" if card_data['website'] else ""}
                {f"📍 {card_data['address']}" if card_data['address'] else ""}
            </div>
        </div>
    </body>
    </html>
    """
    # 保存文件
    filename = f"business_card_{card_data['name']}.html"
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(html_template)
    print(f"✅ 名片已生成:{filename}")
    print("📋 用浏览器打开即可查看")
# 批量生成名片
def batch_generate(cards_json: str):
    """从JSON批量生成名片"""
    cards = json.loads(cards_json)
    for card in cards:
        generate_business_card()
if __name__ == "__main__":
    generate_business_card()

方案2:超简单Shell脚本一键生成

#!/bin/bash
# 文件名: create_card.sh
echo "=== 快速生成名片 ==="
read -p "姓名: " name
read -p "职位: " title
read -p "公司: " company
read -p "电话: " phone
read -p "邮箱: " email
# 生成vCard格式(可导入手机通讯录)
cat > "${name}_contact.vcf" << EOF
BEGIN:VCARD
VERSION:3.0
FN:${name}
ORG:${company}${title}
TEL:${phone}
EMAIL:${email}
END:VCARD
EOF
echo "✅ 已生成 ${name}_contact.vcf(可导入手机)"

方案3:一键生成HTML名片(最快速)

<!-- 直接保存为HTML文件,打开即可使用 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">名片生成器</title>
</head>
<body>
    <script>
        const name = prompt('姓名') || '张三';
        const title = prompt('职位') || 'CEO';
        const company = prompt('公司') || '某某科技有限公司';
        const phone = prompt('电话') || '13800138000';
        const email = prompt('邮箱') || 'example@company.com';
        document.write(`
            <div style="
                width: 350px;
                height: 200px;
                background: linear-gradient(135deg, #667eea, #764ba2);
                border-radius: 15px;
                padding: 25px;
                color: white;
                font-family: Arial;
                box-shadow: 0 10px 30px rgba(0,0,0,0.2);
                margin: 50px auto;
            ">
                <h2 style="margin:0">${name}</h2>
                <p style="opacity:0.9">${title}</p>
                <p style="font-size:18px">${company}</p>
                <p style="opacity:0.8;font-size:14px">
                    📞 ${phone}<br>
                    ✉️ ${email}
                </p>
            </div>
        `);
    </script>
</body>
</html>

使用推荐

  1. 最实用:使用Python脚本,可以自定义颜色和更多信息
  2. 最快速:直接保存HTML文件,双击打开输入信息即可
  3. 导入手机:使用Shell脚本生成vcf格式,可直接导入通讯录

Python脚本使用方法

# 1. 保存为 card_generator.py
# 2. 运行
python card_generator.py
# 3. 按提示输入信息
# 4. 打开生成的HTML文件

需要我帮你定制其他格式(如二维码、PDF)吗?

抱歉,评论功能暂时关闭!