[Step-by-Step Guide] Find keywords, create and publish 150 articles to wordpress site in less than 30 minutes using GPTChat and Python/Google Colab

Would be awesome if someone could add support for downloading images from Pexels as well. Thanks a lot for sharing this information anyhow! Highly appreciated.

Seems simple, they just give you result based on keyword?

I will try to add next week.

Dalle images based on KW are pretty bad.
 
still not able to post to category, I've tried both string and no string "1" and 1
also every possible way with space without space still a no go.
tried both with no image and image version of the code.

is it because of the newest wordpress version?
 
still not able to post to category, I've tried both string and no string "1" and 1
also every possible way with space without space still a no go.
tried both with no image and image version of the code.

is it because of the newest wordpress version?

Code:
def make_post(the_title,the_text,your_user,your_password,your_site,wordpress_category):
        import requests
        import base64
        your_credentials = your_user + ":" + your_password
        your_token = base64.b64encode(your_credentials.encode())
        your_header = {'Authorization': 'Basic ' + your_token.decode('utf-8')}
 
        api_url = your_site+'/wp-json/wp/v2/posts'
        if not wordpress_category == "":
            data = {
                'title' : the_title,
                'status': 'publish',
                'content': the_text,
                'categories': 3
                ##'slug' : 'example-post',
                }
        else:
            data = {
                'title' : the_title,
                'status': 'publish',
                'content': the_text,
                }
           
        response = requests.post(api_url,headers=your_header, json=data)
        return response.json()

Here you change line:
Code:
 'categories': 3

with

Code:
 'categories': your_category_id

where your_category_id is a number (id of your category) or a list ( such as [1,2] ) I am not sure.
Try to put just the id for example: 1 or a list such as [1]

Of course, do not use 1, but your category id
 
Last edited:
  1. It takes less that 30 mins to start posting 150 posts to your wordpress site, and it should not take more than 1 hour to have them all online.
  2. 100% free method except that we need an GPTChat api key. But you can get a free 5 usd trial so this can be free as well
  3. We create 150 keywords using ahrefs free tool - https://ahrefs.com/keyword-generator
  4. We paste some code in Google colab.
  5. Make sure to not make your Google colab public for safety. It should be private by default, but it is better to check that all the time.
  6. This code is responsible for creating posts via GPTChat API and posting to your wordpress site.
  7. We create credential for wordpress site to be able to post there
  8. We decide how much posts we want and then click a button
  9. It posts automatically after we click a button.

Please note this is my first tutorial so If I broken any rules let me know and I will fix that. I have google colab file with code, I am not sure how to upload it.


Lets start...
1) Go to https://ahrefs.com/keyword-generator and add any keyword you want. Select both the keywords and the questions exactly like this, and paste them to a txt file.

View attachment 274230


keyword file is going to look like this, it is messy, but we will format it automatically using python.

View attachment 274231


02) Now we need to create out own Google Colab (which is also 100% free to use)

go to https://colab.google/ and click on New Notebook

View attachment 274232

This is how it looks like, we just need to add a few lines of code, create file and we are ready to go

View attachment 274233


Add this code to first line, this install openai:

Code:
 !pip install openai --quiet

This code need to be added to the second line, it formats keywords and contain all the functions:

Code:
import openai
import os
openai.api_key = "your_open_ai_api_key"

def make_post(the_title,the_text,your_user,your_password,your_site,wordpress_category):
        import requests
        import base64
        your_credentials = your_user + ":" + your_password
        your_token = base64.b64encode(your_credentials.encode())
        your_header = {'Authorization': 'Basic ' + your_token.decode('utf-8')}
 
        api_url = your_site+'/wp-json/wp/v2/posts'
        if not wordpress_category == "":
            data = {
                'title' : the_title,
                'status': 'publish',
                'content': the_text,
                'categories': 3
                ##'slug' : 'example-post',
                }
        else:
            data = {
                'title' : the_title,
                'status': 'publish',
                'content': the_text,
                }
         
        response = requests.post(api_url,headers=your_header, json=data)
        return response.json()

def gpt_chat(all_params):
    the_keyword,the_prefix,the_temperature,the_max_tokens = all_params
    the_text = the_prefix + the_keyword + ":"
        #the_text =  the_prefix + the_text
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": the_text}],
        temperature=the_temperature,
        max_tokens=the_max_tokens
        )
 
    the_result = response["choices"][0]["message"]["content"]
 
    return the_result

def fix_ahrefs_keywords(file_with_keywords):
    #remove empty lines and non keyword lines from output of https://ahrefs.com/keyword-generator
    with open(file_with_keywords, 'r') as fyl:
        lines = fyl.readlines()
 
    good_lines = []
    for aline in lines:
        aline = aline.strip()
        if (not any(str.isdigit(x) for x in aline) or len(aline.split())>3) and not aline.strip()=="" and not "Sign up" in aline and not "N/A" in aline:
            good_lines.append(aline)
 
 
  
    with open(file_with_keywords, 'w') as f:
        for line in good_lines:
            f.write(f"{line}\n")

#load file with your keywords
file_with_keywords = "sample_data/keywords.txt"
#this step fixes the file with keywords from https://ahrefs.com/keyword-generator
fix_ahrefs_keywords(file_with_keywords)


Add this code to the third line:

Code:
# SETTINGS
begin_index = 11
end_index = 12
your_site = "yur site url"
your_user = "your site username"
your_password = "your site application password"
wordpress_category = "" # or you can add here a category id
title_is_keyword = "yes" #cam be "yes" or "no". If yes then the title is the keyword, if no then the title is created by GPTCHAT
remove_ai_detection = "no"


#prefix = "Write an article about"
prefix = "Write a very extremelly long and detailed article about "
#load the fixed keywords
with open(file_with_keywords, 'r') as fyl:
    keywords = fyl.readlines()
keywords = [x.strip() for x in keywords]
 
#now we create posts using GPT-chat and post them to our wordpress site
for e,akeyword in enumerate(keywords):
 
    if e<begin_index or e>=end_index:continue #this makes sure we only add article from begin to end
    the_temperature = 0.7
    the_max_tokens = 2000
    all_params = akeyword,prefix,the_temperature,the_max_tokens
    print("we are writing post #",e,", using keyword:",akeyword)
    gptchat_article = gpt_chat(all_params)
    title = akeyword.title()
 
    try:
        gptchat_article_list = gptchat_article.split("\n")
        if gptchat_article_list[0].count(".")<=1 and gptchat_article_list[1].strip()=="":
            title = gptchat_article_list[0]
            gptchat_article = gptchat_article.replace(title,"").strip()
            if title_is_keyword=="yes":
                title = akeyword.title()
    except:pass
 
 
    #now we post to out wordpres site
    try:
        the_response = make_post(title,gptchat_article,your_user,your_password,your_site,wordpress_category)
        the_link = the_response['guid']['rendered']
        print("the_link",the_link,"word count",len(gptchat_article.split()),"the_title:",title)
    except Exception as err:
        print("we have an error",err)

This should look like this:

View attachment 274243



03) The next step is to create a file with keyword and paste the keywords we already have. We click on folder on the left, and create a file in folder sample_data called keywords. Then we click on keywords and there we add out keywords.
View attachment 274235



05) So now the keyword part is done we just need to add out WordPress credentials and we are ready to go.

View attachment 274241

We go to Users/profile in the WordPress dashboard and then we create New Application Password Name. This is just name of password, we do not use it anywhere else. So after we add it, we click on Add New Application Password. This is the password that we need to copy and add to the Google Colab.

06) Then we add our settings that we have just created:

View attachment 274238

To control how many posts to you post you change begin_index and end_index. For example if begin_index=0 and end_index=1 it will post just the first posts. To post to your site, you need to click on run button in every cell. There are 3 cells, so you need to click each time.



Edit: 8/17/2023

Now lets add image post function.

It uses openai API as wee (dalle api), so you should check how much does it cost, but I believe it is pretty cheap.

Here are the main settings, you can choose if you want to add images, and also if you wanna make them features images, or just put them at the end of post. Quality of Dalle images is pretty good, but sometimes you need to play with prompt to be able to create exactly the image you want.
Code:
create_and_add_an_image = "yes" #can be yes or no
make_the_image_featured = "yes" #can be yes or no
image_prefix = "A detailed high quality natural image about: "
image_resolution="512x512"

if you choose create_and_add_an_image and make_the_image_featured it will post the image as featured and add it to the post at the top left. You can also change HTML from the code as per your needs.

Here is complete code, which consist of 2 parts, the same as before:


#cell 1
Code:
import openai
import os
openai.api_key = "your_open_ai_api_key"

def upload_image(filename,your_site,your_user,your_password):
    import requests, json
    api_url_image = your_site+'/wp-json/wp/v2/media'
    the_pic = open(filename, 'rb').read()
    fnm = os.path.basename(filename)
    result = requests.post(
        url=api_url_image,
        data=the_pic,
        headers={ 'Content-Type': 'image/jpg','Content-Disposition' : 'attachment; filename=%s'% fnm},
        auth=(your_user, your_password)
        )

    response =result.json()
    the_image_id = response.get('id')
    the_image_url = response.get('guid').get("rendered")
    return (the_image_id, the_image_url)

def make_post(the_title,the_text,your_user,your_password,your_site,wordpress_category,the_image_id):
        import requests
        import base64
        your_credentials = your_user + ":" + your_password
        your_token = base64.b64encode(your_credentials.encode())
        your_header = {'Authorization': 'Basic ' + your_token.decode('utf-8')}
 
        api_url = your_site+'/wp-json/wp/v2/posts'
  
        if the_image_id>0:
            if not wordpress_category == "":
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    'categories': 3,
                    'featured_media': the_image_id
                    ##'slug' : 'example-post',
                    }
            else:
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    'featured_media': the_image_id
                    ##'slug' : 'example-post',
                    }
        else:
            if not wordpress_category == "":
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    'categories': 3,
                    }
            else:
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    }              
          
          
        response = requests.post(api_url,headers=your_header, json=data)
        return response.json()

def gpt_chat(all_params):
    the_keyword,the_prefix,the_temperature,the_max_tokens = all_params
    the_text = the_prefix + the_keyword + ":"
        #the_text =  the_prefix + the_text
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": the_text}],
        temperature=the_temperature,
        max_tokens=the_max_tokens
        )
 
    the_result = response["choices"][0]["message"]["content"]
 
    return the_result

def fix_ahrefs_keywords(file_with_keywords):
    #remove empty lines and non keyword lines from output of https://ahrefs.com/keyword-generator
    with open(file_with_keywords, 'r') as fyl:
        lines = fyl.readlines()
 
    good_lines = []
    for aline in lines:
        aline = aline.strip()
        if (not any(str.isdigit(x) for x in aline) or len(aline.split())>3) and not aline.strip()=="" and not "Sign up" in aline and not "N/A" in aline:
            good_lines.append(aline)
 
 
 
    with open(file_with_keywords, 'w') as f:
        for line in good_lines:
            f.write(f"{line}\n")

#load file with your keywords
file_with_keywords = "sample_data/keywords.txt"
#this step fixes the file with keywords from https://ahrefs.com/keyword-generator
fix_ahrefs_keywords(file_with_keywords)


#cell 2
Code:
# SETTINGS
begin_index = 11
end_index = 12
your_site = "yur site url"
your_user = "your site username"
your_password = "your site application password"
wordpress_category = "" # or you can add here a category id
title_is_keyword = "yes" #cam be "yes" or "no". If yes then the title is the keyword, if no then the title is created by GPTCHAT
remove_ai_detection = "no"

create_and_add_an_image = "yes" #can be yes or no
make_the_image_featured = "yes" #can be yes or no
image_prefix = "A detailed high quality natural image about: "
image_resolution="512x512"


#prefix = "Write an article about"
prefix = "Write a very extremelly long and detailed article about "
#load the fixed keywords
with open(file_with_keywords, 'r') as fyl:
    keywords = fyl.readlines()
keywords = [x.strip() for x in keywords]
 
#now we create posts using GPT-chat and post them to our wordpress site
for e,akeyword in enumerate(keywords):
 
    if e<begin_index or e>=end_index:continue #this makes sure we only add article from begin to end
    the_temperature = 0.7
    the_max_tokens = 2000
    all_params = akeyword,prefix,the_temperature,the_max_tokens
    print("we are writing post #",e,", using keyword:",akeyword)
    gptchat_article = gpt_chat(all_params)
    title = akeyword.title()


    the_image_url = ""
    the_image_id = -1
    if create_and_add_an_image == "yes":
        response = openai.Image.create(
            prompt= image_prefix + akeyword,
            n=1,
            size=image_resolution
            )
  
        image_url = response['data'][0]['url']
        image_file = "sample_data/" + str(e)+'.jpeg'
        import urllib.request
  
        #download the image to file image_file
        urllib.request.urlretrieve(image_url, image_file)  
  
        if not make_the_image_featured=="yes":the_image_id = -1
  
        try:
            the_image_id,the_image_url = upload_image(image_file,your_site,your_user,your_password)
            print("image_url",the_image_url)            
        except Exception as error:
            print("we could not upload image",error)


    try:
        gptchat_article_list = gptchat_article.split("\n")
        if gptchat_article_list[0].count(".")<=1 and gptchat_article_list[1].strip()=="":
            title = gptchat_article_list[0]
            gptchat_article = gptchat_article.replace(title,"").strip()
            if title_is_keyword=="yes":
                title = akeyword.title()
    except:pass

    if not the_image_url.strip()=="":
        if make_the_image_featured=="yes":
            image_insert_html_code =  '<img src="'+the_image_url +'" alt="'+akeyword+'" style="float: left; margin-right: 10px;">'        
            gptchat_article = image_insert_html_code + gptchat_article
        else:
            image_insert_html_code =  '<img src="'+the_image_url +'" alt="'+akeyword+'" style="margin:10px;">'        
            gptchat_article =  gptchat_article + image_insert_html_code
 
 
    #now we post to out wordpres site
    try:
        the_response = make_post(title,gptchat_article,your_user,your_password,your_site,wordpress_category
,the_image_id
)
        the_link = the_response['guid']['rendered']
        print("the_link",the_link,"word count",len(gptchat_article.split()),"the_title:",title)
    except Exception as err:
        print("we have an error",err)
I have tested the way to get Free SEO traffic on WP sites. not very efficient. just 5% of them are available to get stable traffic about 100-500 UV/Day. Some European languages of articles are more useful in SERP.
 
How can we get 1500+ words articles. Does anyone achieve this?
 
i am on to it. i will let you know the update. thanks.
 
  1. It takes less that 30 mins to start posting 150 posts to your wordpress site, and it should not take more than 1 hour to have them all online.
  2. 100% free method except that we need an GPTChat api key. But you can get a free 5 usd trial so this can be free as well
  3. We create 150 keywords using ahrefs free tool - https://ahrefs.com/keyword-generator
  4. We paste some code in Google colab.
  5. Make sure to not make your Google colab public for safety. It should be private by default, but it is better to check that all the time.
  6. This code is responsible for creating posts via GPTChat API and posting to your wordpress site.
  7. We create credential for wordpress site to be able to post there
  8. We decide how much posts we want and then click a button
  9. It posts automatically after we click a button.

Please note this is my first tutorial so If I broken any rules let me know and I will fix that. I have google colab file with code, I am not sure how to upload it.


Lets start...
1) Go to https://ahrefs.com/keyword-generator and add any keyword you want. Select both the keywords and the questions exactly like this, and paste them to a txt file.

View attachment 274230


keyword file is going to look like this, it is messy, but we will format it automatically using python.

View attachment 274231


02) Now we need to create out own Google Colab (which is also 100% free to use)

go to https://colab.google/ and click on New Notebook

View attachment 274232

This is how it looks like, we just need to add a few lines of code, create file and we are ready to go

View attachment 274233


Add this code to first line, this install openai:

Code:
 !pip install openai --quiet

This code need to be added to the second line, it formats keywords and contain all the functions:

Code:
import openai
import os
openai.api_key = "your_open_ai_api_key"

def make_post(the_title,the_text,your_user,your_password,your_site,wordpress_category):
        import requests
        import base64
        your_credentials = your_user + ":" + your_password
        your_token = base64.b64encode(your_credentials.encode())
        your_header = {'Authorization': 'Basic ' + your_token.decode('utf-8')}
 
        api_url = your_site+'/wp-json/wp/v2/posts'
        if not wordpress_category == "":
            data = {
                'title' : the_title,
                'status': 'publish',
                'content': the_text,
                'categories': 3
                ##'slug' : 'example-post',
                }
        else:
            data = {
                'title' : the_title,
                'status': 'publish',
                'content': the_text,
                }
          
        response = requests.post(api_url,headers=your_header, json=data)
        return response.json()

def gpt_chat(all_params):
    the_keyword,the_prefix,the_temperature,the_max_tokens = all_params
    the_text = the_prefix + the_keyword + ":"
        #the_text =  the_prefix + the_text
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": the_text}],
        temperature=the_temperature,
        max_tokens=the_max_tokens
        )
 
    the_result = response["choices"][0]["message"]["content"]
 
    return the_result

def fix_ahrefs_keywords(file_with_keywords):
    #remove empty lines and non keyword lines from output of https://ahrefs.com/keyword-generator
    with open(file_with_keywords, 'r') as fyl:
        lines = fyl.readlines()
 
    good_lines = []
    for aline in lines:
        aline = aline.strip()
        if (not any(str.isdigit(x) for x in aline) or len(aline.split())>3) and not aline.strip()=="" and not "Sign up" in aline and not "N/A" in aline:
            good_lines.append(aline)
 
 
   
    with open(file_with_keywords, 'w') as f:
        for line in good_lines:
            f.write(f"{line}\n")

#load file with your keywords
file_with_keywords = "sample_data/keywords.txt"
#this step fixes the file with keywords from https://ahrefs.com/keyword-generator
fix_ahrefs_keywords(file_with_keywords)


Add this code to the third line:

Code:
# SETTINGS
begin_index = 11
end_index = 12
your_site = "yur site url"
your_user = "your site username"
your_password = "your site application password"
wordpress_category = "" # or you can add here a category id
title_is_keyword = "yes" #cam be "yes" or "no". If yes then the title is the keyword, if no then the title is created by GPTCHAT
remove_ai_detection = "no"


#prefix = "Write an article about"
prefix = "Write a very extremelly long and detailed article about "
#load the fixed keywords
with open(file_with_keywords, 'r') as fyl:
    keywords = fyl.readlines()
keywords = [x.strip() for x in keywords]
 
#now we create posts using GPT-chat and post them to our wordpress site
for e,akeyword in enumerate(keywords):
 
    if e<begin_index or e>=end_index:continue #this makes sure we only add article from begin to end
    the_temperature = 0.7
    the_max_tokens = 2000
    all_params = akeyword,prefix,the_temperature,the_max_tokens
    print("we are writing post #",e,", using keyword:",akeyword)
    gptchat_article = gpt_chat(all_params)
    title = akeyword.title()
 
    try:
        gptchat_article_list = gptchat_article.split("\n")
        if gptchat_article_list[0].count(".")<=1 and gptchat_article_list[1].strip()=="":
            title = gptchat_article_list[0]
            gptchat_article = gptchat_article.replace(title,"").strip()
            if title_is_keyword=="yes":
                title = akeyword.title()
    except:pass
 
 
    #now we post to out wordpres site
    try:
        the_response = make_post(title,gptchat_article,your_user,your_password,your_site,wordpress_category)
        the_link = the_response['guid']['rendered']
        print("the_link",the_link,"word count",len(gptchat_article.split()),"the_title:",title)
    except Exception as err:
        print("we have an error",err)

This should look like this:

View attachment 274243



03) The next step is to create a file with keyword and paste the keywords we already have. We click on folder on the left, and create a file in folder sample_data called keywords. Then we click on keywords and there we add out keywords.
View attachment 274235



05) So now the keyword part is done we just need to add out WordPress credentials and we are ready to go.

View attachment 274241

We go to Users/profile in the WordPress dashboard and then we create New Application Password Name. This is just name of password, we do not use it anywhere else. So after we add it, we click on Add New Application Password. This is the password that we need to copy and add to the Google Colab.

06) Then we add our settings that we have just created:

View attachment 274238

To control how many posts to you post you change begin_index and end_index. For example if begin_index=0 and end_index=1 it will post just the first posts. To post to your site, you need to click on run button in every cell. There are 3 cells, so you need to click each time.



https://www.blackhatworld.com/seo/step-by-step-guide-find-keywords-create-and-publish-150-articles-to-wordpress-site-in-less-than-30-minutes-using-gptchat-and-python-google-colab.1518413/page-4#post-16691962

Now lets add image post function.

It uses openai API as wee (dalle api), so you should check how much does it cost, but I believe it is pretty cheap.

Here are the main settings, you can choose if you want to add images, and also if you wanna make them features images, or just put them at the end of post. Quality of Dalle images is pretty good, but sometimes you need to play with prompt to be able to create exactly the image you want.
Code:
create_and_add_an_image = "yes" #can be yes or no
make_the_image_featured = "yes" #can be yes or no
image_prefix = "A detailed high quality natural image about: "
image_resolution="512x512"

if you choose create_and_add_an_image and make_the_image_featured it will post the image as featured and add it to the post at the top left. You can also change HTML from the code as per your needs.

Here is complete code, which consist of 2 parts, the same as before:


#cell 1
Code:
import openai
import os
openai.api_key = "your_open_ai_api_key"

def upload_image(filename,your_site,your_user,your_password):
    import requests, json
    api_url_image = your_site+'/wp-json/wp/v2/media'
    the_pic = open(filename, 'rb').read()
    fnm = os.path.basename(filename)
    result = requests.post(
        url=api_url_image,
        data=the_pic,
        headers={ 'Content-Type': 'image/jpg','Content-Disposition' : 'attachment; filename=%s'% fnm},
        auth=(your_user, your_password)
        )

    response =result.json()
    the_image_id = response.get('id')
    the_image_url = response.get('guid').get("rendered")
    return (the_image_id, the_image_url)

def make_post(the_title,the_text,your_user,your_password,your_site,wordpress_category,the_image_id):
        import requests
        import base64
        your_credentials = your_user + ":" + your_password
        your_token = base64.b64encode(your_credentials.encode())
        your_header = {'Authorization': 'Basic ' + your_token.decode('utf-8')}
 
        api_url = your_site+'/wp-json/wp/v2/posts'
   
        if the_image_id>0:
            if not wordpress_category == "":
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    'categories': 3,
                    'featured_media': the_image_id
                    ##'slug' : 'example-post',
                    }
            else:
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    'featured_media': the_image_id
                    ##'slug' : 'example-post',
                    }
        else:
            if not wordpress_category == "":
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    'categories': 3,
                    }
            else:
                data = {
                    'title' : the_title,
                    'status': 'publish',
                    'content': the_text,
                    }               
           
           
        response = requests.post(api_url,headers=your_header, json=data)
        return response.json()

def gpt_chat(all_params):
    the_keyword,the_prefix,the_temperature,the_max_tokens = all_params
    the_text = the_prefix + the_keyword + ":"
        #the_text =  the_prefix + the_text
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": the_text}],
        temperature=the_temperature,
        max_tokens=the_max_tokens
        )
 
    the_result = response["choices"][0]["message"]["content"]
 
    return the_result

def fix_ahrefs_keywords(file_with_keywords):
    #remove empty lines and non keyword lines from output of https://ahrefs.com/keyword-generator
    with open(file_with_keywords, 'r') as fyl:
        lines = fyl.readlines()
 
    good_lines = []
    for aline in lines:
        aline = aline.strip()
        if (not any(str.isdigit(x) for x in aline) or len(aline.split())>3) and not aline.strip()=="" and not "Sign up" in aline and not "N/A" in aline:
            good_lines.append(aline)
 
 
 
    with open(file_with_keywords, 'w') as f:
        for line in good_lines:
            f.write(f"{line}\n")

#load file with your keywords
file_with_keywords = "sample_data/keywords.txt"
#this step fixes the file with keywords from https://ahrefs.com/keyword-generator
fix_ahrefs_keywords(file_with_keywords)


#cell 2
Code:
# SETTINGS
begin_index = 11
end_index = 12
your_site = "yur site url"
your_user = "your site username"
your_password = "your site application password"
wordpress_category = "" # or you can add here a category id
title_is_keyword = "yes" #cam be "yes" or "no". If yes then the title is the keyword, if no then the title is created by GPTCHAT
remove_ai_detection = "no"

create_and_add_an_image = "yes" #can be yes or no
make_the_image_featured = "yes" #can be yes or no
image_prefix = "A detailed high quality natural image about: "
image_resolution="512x512"


#prefix = "Write an article about"
prefix = "Write a very extremelly long and detailed article about "
#load the fixed keywords
with open(file_with_keywords, 'r') as fyl:
    keywords = fyl.readlines()
keywords = [x.strip() for x in keywords]
 
#now we create posts using GPT-chat and post them to our wordpress site
for e,akeyword in enumerate(keywords):
 
    if e<begin_index or e>=end_index:continue #this makes sure we only add article from begin to end
    the_temperature = 0.7
    the_max_tokens = 2000
    all_params = akeyword,prefix,the_temperature,the_max_tokens
    print("we are writing post #",e,", using keyword:",akeyword)
    gptchat_article = gpt_chat(all_params)
    title = akeyword.title()


    the_image_url = ""
    the_image_id = -1
    if create_and_add_an_image == "yes":
        response = openai.Image.create(
            prompt= image_prefix + akeyword,
            n=1,
            size=image_resolution
            )
   
        image_url = response['data'][0]['url']
        image_file = "sample_data/" + str(e)+'.jpeg'
        import urllib.request
   
        #download the image to file image_file
        urllib.request.urlretrieve(image_url, image_file)   
   
        if not make_the_image_featured=="yes":the_image_id = -1
   
        try:
            the_image_id,the_image_url = upload_image(image_file,your_site,your_user,your_password)
            print("image_url",the_image_url)             
        except Exception as error:
            print("we could not upload image",error)


    try:
        gptchat_article_list = gptchat_article.split("\n")
        if gptchat_article_list[0].count(".")<=1 and gptchat_article_list[1].strip()=="":
            title = gptchat_article_list[0]
            gptchat_article = gptchat_article.replace(title,"").strip()
            if title_is_keyword=="yes":
                title = akeyword.title()
    except:pass

    if not the_image_url.strip()=="":
        if make_the_image_featured=="yes":
            image_insert_html_code =  '<img src="'+the_image_url +'" alt="'+akeyword+'" style="float: left; margin-right: 10px;">'         
            gptchat_article = image_insert_html_code + gptchat_article
        else:
            image_insert_html_code =  '<img src="'+the_image_url +'" alt="'+akeyword+'" style="margin:10px;">'         
            gptchat_article =  gptchat_article + image_insert_html_code
 
 
    #now we post to out wordpres site
    try:
        the_response = make_post(title,gptchat_article,your_user,your_password,your_site,wordpress_category
,the_image_id
)
        the_link = the_response['guid']['rendered']
        print("the_link",the_link,"word count",len(gptchat_article.split()),"the_title:",title)
    except Exception as err:
        print("we have an error",err)
Thank you so much for this!
 
I think only way is to create an outline of content first by gptchat and then adding the outline to the prompt.
I've created a prompt inside for creating outlines.
And the point is to be automated.

Everything works fine on my side and thank for this opportunity!
But if there is a way to create 1000+ worda articles i really wanna know.
 
I've created a prompt inside for creating outlines.
And the point is to be automated.

Everything works fine on my side and thank for this opportunity!
But if there is a way to create 1000+ worda articles i really wanna know.

This is what I said, you create outline in the code using ChatGPT, something like this: (I do not have time to test, so it might have some errors)


Code:
#now we create posts using GPT-chat and post them to our wordpress site
for e,akeyword in enumerate(keywords):
 
    if e<begin_index or e>=end_index:continue #this makes sure we only add article from begin to end
    the_temperature = 0.7
    the_max_tokens = 2000
    all_params = akeyword,prefix,the_temperature,the_max_tokens
    print("we are writing post #",e,", using keyword:",akeyword)
    gptchat_article = gpt_chat(all_params)
    title = akeyword.title()

replace this with something like this


Code:
#now we create posts using GPT-chat and post them to our wordpress site
for e,akeyword in enumerate(keywords):
 
    if e<begin_index or e>=end_index:continue #this makes sure we only add article from begin to end
    the_temperature = 0.7
    the_max_tokens = 2000
    ############### added lines ####
    prefix1 = "create an outline for a long and detailed article about: "
    all_params_outline = akeyword,prefix1,the_temperature,the_max_tokens
    gptchat_outline = gpt_chat(all_params_outline)
    prefix2 = "create an articles based on this outline: "
    all_params = gptchat_outline,prefix2,the_temperature,the_max_tokens
     ###############################
    print("we are writing post #",e,", using keyword:",akeyword)
    gptchat_article = gpt_chat(all_params)
    title = akeyword.title()
 
sadly these posts will never rank and even get deindexed later but a really great guide, thanks
 
Back
Top