Mac 中如何借助 DeepSeek 每天写一篇文章

在 macOS 上编写和运行脚本可以使用多种语言,如 Bash、Python 等。以下是一个示例,展示如何编写一个 Python 脚本来调用 DeepSeek API 生成文章,并使用 cron 定时任务每天运行该脚本。

1. 编写 Python 脚本

首先,创建一个 Python 脚本(例如 generate_article_deepseek.py),使用 DeepSeek 的 API 生成文章。

python 复制代码
import requests

# 设置 DeepSeek API 密钥

api_key = 'your-deepseek-api-key'

api_url = 'https://api.deepseek.com/v1/generate'

def generate_article(topic):

    headers = {

        'Authorization': f'Bearer {api_key}',

        'Content-Type': 'application/json'

    }

    

    data = {

        'prompt': f"Write a 500-word article about {topic}.",

        'max_tokens': 1024,

        'temperature': 0.7

    }

    

    response = requests.post(api_url, headers=headers, json=data)

    

    if response.status_code == 200:

        article = response.json().get('text', '').strip()

        return article

    else:

        print(f"Failed to generate article: {response.status_code} - {response.text}")

        return None

if __name__ == "__main__":

    topic = "the benefits of daily exercise"

    article = generate_article(topic)

    if article:

        print("Generated Article:")

        print(article)

        # 将生成的文章保存到文件

        with open("generated_article.txt", "w") as file:

            file.write(article)

2. 运行脚本

您可以在终端中运行该脚本来测试它是否正常工作:

复制代码
python3 generate_article_deepseek.py

3. 使用 cron 定时任务

要每天自动运行该脚本,可以使用 cron 定时任务。以下是设置 cron 任务的步骤:

  1. 打开终端并编辑 crontab 文件:

    crontab -e

  2. 添加以下行以每天在指定时间(例如每天早上 9 点)运行脚本:

ruby 复制代码
0 9 * * * /usr/bin/python3 /path/to/generate_article_deepseek.py

确保将 /path/to/generate_article_deepseek.py 替换为您的脚本的实际路径。

示例 crontab 条目

bash 复制代码
0 9 * * * /usr/bin/python3 /Users/yourusername/path/to/generate_article_deepseek.py

4. 保存并退出

保存 crontab 文件并退出编辑器。cron 将根据您设置的时间表自动运行脚本。

总结

通过这些步骤,您可以在 macOS 上编写一个 Python 脚本来调用 DeepSeek API 生成文章,并使用 cron 定时任务每天自动运行该脚本。这样可以确保每天生成一篇新的文章并保存到文件中。

相关推荐
YDS8295 小时前
DeepSeek RAG&MCP + Agent智能体项目 —— 环境搭建和项目初始化
java·springboot·agent·rag·deepseek
kaixuan_dashen19 小时前
Codex使用DeepSeek API的方法(cc switch + codex bridge方案)
人工智能·codex·deepseek·cc switch·codex bridge
AC赳赳老秦1 天前
OpenClaw与WPS宏联动:批量执行WPS复杂操作,解决办公表格批量处理难题
java·前端·数据库·自动化·需求分析·deepseek·openclaw
wujian83111 天前
AI表格怎么导出word
人工智能·ai·word·豆包·deepseek·ai导出鸭
Caster_Z1 天前
Win10本地部署QQ智能机器人:AstrBot+NapCat+DeepSeekAI
机器人·deepseek·napcat·astrbot·自动客服
青春不败 177-3266-05201 天前
MATLAB 2024b深度学习新特性全面解析与DeepSeek大模型集成开发
人工智能·深度学习·机器学习·matlab·卷积神经网络·自编码器·deepseek
codingxb451 天前
VSCode中使用ClaudeCode接入Deepseek-v4模型
vscode·deepseek·claude code
Orange_sparkle1 天前
什么是前缀缓存,缓存命中
缓存·ai·deepseek·claude code
只看不学2 天前
Claude Code接入 DeepSeek V4 模型
deepseek·claude code
咪的Coding2 天前
为什么在 DeepSeek 输入 <think>,它竟吐出别人的“记忆碎片”!?
后端·deepseek