Automated Blog Post Creator

Hi, I’m trying to create a way to do the following:

  1. after I read a article on a website I find interesting I want to
  2. send it to ChatGPT for a 60 word summary
  3. and have ChatGPT ask 2 open questions about the text
  4. next save the results (summary and questions) as a draft blogpost in Wordpress
  • I am trying to achieve this without lots of paid apps and sending all the data across the globe, so ideally would do it locally on my Mac.
  • sharing the article with ChatGPT could be as simple as sending it to a specific email address and then triggering an apple script through the rules in Apple mail.
  • the script could then send it to an email linked to WordPress where it is saved as a draft
  • I’d like the article title in the subject line and the link below the ChatGPT results
  • I asked ChatGPT to help me put the code together (I really have no clue what I am doing) but so far I don’t get the desired results (errors, I have no clue what they mean and ChatGPT seems to not be able to help me any further. Any ideas?
--- Set your OpenAI API key
set api_key to "your_openai_api_key"

-- Function to extract article content from email body or link
on extractArticleContent(emailContent)
    -- Check if the email content contains "http" indicating a link
    if emailContent contains "http" then
        -- Use a command-line tool (lynx) to fetch the content from the link
        set cmd to "lynx -dump " & quoted form of emailContent
        set articleContent to do shell script cmd
    else
        -- If it's not a link, assume the email content is the article
        set articleContent to emailContent
    end if
    return articleContent
end extractArticleContent

-- Extracted email content (replace this with actual email content)
set emailContent to "..." -- Replace with the actual email content

-- Extract the article content from the email
set articleContent to extractArticleContent(emailContent)

-- Extract the article title from the email (assuming the title is in the subject)
set articleTitle to "..." -- Replace with the actual article title

-- Construct the prompt for summarization
set prompt to "Summarize the following article: " & articleContent

-- Call OpenAI API for summarization
set summary to doAPICall(api_key, prompt, 100) -- Adjust max tokens as needed

-- Ask an open-ended question
set questionPrompt to "What are two open questions you could ask readers about the text so they can think more deeply about the topic discussed?"
set questionResponse to doAPICall(api_key, questionPrompt, 50) -- Adjust max tokens as needed

-- Create email body with results
set emailSubject to "blogpost draft: " & articleTitle
set emailBody to "Original Article: " & emailContent & linefeed & linefeed & "Summary: " & summary & linefeed & linefeed & "Questions: " & questionResponse

-- Send email with results
tell application "Mail"
    set newMessage to make new outgoing message with properties {subject:emailSubject, content:emailBody & linefeed & linefeed}
    tell newMessage
        make new to recipient at end of to recipients with properties {address:"recipient_email@example.com"} -- Replace with recipient's email
        send
    end tell
end tell

-- Handler to make API call to OpenAI
on doAPICall(apiKey, promptText, maxTokens)
    -- ... your API call code ...
    -- Make sure to define a variable named "responseText" with the API response
    return responseText
end doAPICall


Further ChatGPT says:
Replace "your_openai_api_key" with your actual OpenAI API key, and replace "recipient_email@example.com" with the recipient’s email address.

This script extracts the article content from the email, summarizes it, asks open questions, and then sends the results in an email to the specified recipient. The recipient’s email address is specified in the make new to recipient line.