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 定时任务每天自动运行该脚本。这样可以确保每天生成一篇新的文章并保存到文件中。

相关推荐
AC赳赳老秦2 天前
OpenClaw生成博客封面图+标题,适配CSDN视觉搜索,提升点击量
运维·人工智能·python·自动化·php·deepseek·openclaw
陈振wx:zchen20082 天前
SpringAI+DeepSeek大模型开发
大模型·springai·deepseek
Aaron_Chou3132 天前
如何在Trae中配置Claude,gpt-5.4,deepseek等大模型的中转API
人工智能·gpt·claude·deepseek·cline·trae
大模型真好玩2 天前
大模型训练全流程实战指南工具篇(十一)—— 大模型训练参数调优实战:从小白到调参高手
人工智能·langchain·deepseek
Ztopcloud极拓云视角3 天前
GPT-6、Claude Opus 4.7、DeepSeek V4同期上线,如何快速搭一个自动选模型的路由网关?
gpt·claude·deepseek
时光之源4 天前
一场关于红绿灯检测项目的辩论赛——YOLOv26
深度学习·yolo·grok·gemini·deepseek
云和数据.ChenGuang4 天前
机器学习之方差和标准差计算
人工智能·python·机器学习·django·pygame·deepseek
大模型真好玩5 天前
GitHub 85K Star 新王挑战 357K Star 霸主:Hermes 还是 OpenClaw?最强Agent框架怎么选
人工智能·agent·deepseek
AC赳赳老秦5 天前
OpenClaw对接百度指数:关键词热度分析,精准定位博客创作方向
java·python·算法·百度·dubbo·deepseek·openclaw
视觉&物联智能6 天前
【杂谈】-人工智能疲劳是真实存在的,但它并非你想象的那样
人工智能·ai·chatgpt·agi·deepseek