Automated News Website Using Google News ChatGPT WordPress Make $1000 Per Day — Part 2
How to make minimum $1000 Per Day money using ChatGPT and Google News | Millions Dollar Business Ideas
Introduction
So we are in the process of building an Automated News Website by using ChatGPT. If you already read our Part 1 article then you can read this Part 2 article and understand how you can create an entire full-fledged Automated News website using ChatGPT API, Google Trends API, WP Rest API, and Nest JS.
Recap of Part 1
So we will do a quick recap and summarise the point which we have mentioned in our Part 1 Article. So In Part 1, we have mentioned a couple of important points which are given below.
- What is Google Trend and how to install google-trends-api and how to use it?
- By using google-trends-api how to get a List of Real Time Trending Article links based on different Google Trends Real-Time Categories?
- How to use ChatGPT API and ChatGPT 3.5 turbo free models function which will generate SEO-friendly, non-detectable AI-free content for your website.
- How to use the WPLocal platform to create a WordPress instance locally and then post your content to your WordPress website and develop it locally to test it.
So the above points we have mentioned in our Part 1 Article and in this Part 2 article we will discuss in-depth technical flow with code and end-to-end solutions to create a production-ready Automated News Website.
Google Trends Categories and Country
To post content on your WordPress News Website you have to post the content in a certain category. As we are using Google Trends API to get the Real Time Trending Articles, there are a fixed number of categories available in Google Trends. Based on those categories we need to generate content and post it to WordPress. Along with that, Real-Time Trending Articles will be GEO-based, so based on different countries you can get a list of Real-Time Trending Articles from Google Trends. You can get the country list on the Google Trends website. But for our development, we have targeted the US country so that we will get Real-Time Trends for the US country only.
So now we know to get Real-Time trends we need two mandatory parameters one is category and the other one is country. There are 6 categories available in Google Trends. Each category has a unique character available which will define the value of the category google trends API identifies the category based on the category value. The list of Google Trends Real-Time Categories and their corresponding shortcode is given below.
- Category — Business, Short Code — b
- Category — Entertainment, Short Code — e
- Category — Health, Short Code — m
- Category — Sports, Short Code — s
- Category — Technology, Short Code — t
- Category — Top Stories, Short Code — h
Now we know how many and what categories are available in Google Trends, Based on each category we need to check how many lists of Real-Time articles are available which we can rewrite using ChatGPT and post to WordPress. So let’s create an Rest API to get the Count of articles for different categories.
AppController.ts
enum DropdownValues {
b = 'b',
e = 'e',
m = 'm',
s = 's',
h = 'h',
t='t'
}
@Get('/wp-categories-length')
@ApiQuery({ name: 'dropdown', enum: DropdownValues, required: true, description: 'Category' })
async getWpCategoriesEnum(@Query('dropdown') dropdown: DropdownValues): Promise<any> {
return await this.appService.getTrendsArticlesCount(dropdown);
}
So we have created an enum in TypeScript to define the shortcode of categories and if you open the swagger in this URL in localhost http://localhost:3000/api then you can select different category short code and get the count of Real-Time Articles based on certain categories.
AppService.ts
async getTrendsArticlesCount(category): Promise<any> {
const response: RealTimeTrends = await this.getTrendsArticles(category);
return {articlesCount: response.storySummaries.trendingStories.length, category: category};
}
Once you get the length that how many articles are available for each category then you can rewrite that much content to WordPress using ChatGPT.
Connect WordPress with Nest JS
As we mentioned for our local development we will use WPLocal and then we will start the WP Local and create a website using WP Local. Once this process is done then we need to connect that local website with our Nest JS application through WP Rest API. There is Nest JS package is available which will connect WordPress to Nest JS application very easily. So let's install this package.
npm i @ntegral/nestjs-wpapi
After the installation, we need to import the wpApiModule and configure it in the @Module decorator and there we need to pass the WordPress configuration details given below.
imports: [
ConfigModule.forRoot(),
WpApiModule.forRoot({
endpoint: 'http://your-wordpress-domain/wp-json/',
username: 'WP Admin Username',
password: 'WP Application Password',
auth: true
})
]
Note that this password does not mean the WP admin password by which you log in to WordPress Admin. This is an Application Password and you need to generate an Application Password from WordPress Admin. So you need to go in this route Users>Profile and then come to the bottom of the page here you can see that you can create a name of Application Password and it will generate a password for you and you need to use this password in the configuration of WpApiModule. Once you do that you have connected your Nest JS application with your WordPress website using WP Rest API. So now you can get, post, update and delete content in WordPress through the Nest JS application.
Add Google Trends Category in WordPress Website
So we already know there are 6 Google Trends Categories available and those are static categories which will not change often let post those Google Trend categories on WordPress So that we can manage the category from WordPress only. In your WP Admin go to Posts>Category section and there you need to add the Category Name in the Name field in the description you should add the shortcode of the category, example given below.
Rewrite Content Using ChatGPT API
Now we connected the WordPress website with Nest JS and also know how many articles are available for each Google Trends category, So now we need to use the index of each article for that particular category rewrite that content using ChatGPT and then post it on WordPress, as simple as like that. So to do that we will already have one POST API namely /trends that we created in Part 1 and we need to extend it by giving an index in this API URL so that we can rewrite each content one by one and post it on WordPress.
AppController.ts
@Post("/trends/:index")
@ApiQuery({ name: 'dropdown', enum: DropdownValues, required: true, description: 'Category' })
async getTrends(@Body() data: Question, @Param('index') index: number,
@Query('dropdown') dropdown: DropdownValues) {
try {
const categories = await this.appService.getAllWpCategories();
const category = categories.find((val) => val.description === dropdown)
if (category) {
try {
const realTimeTrends = await this.appService.getTrendsArticles(category.description);
if (Number(index) > realTimeTrends.storySummaries.trendingStories.length-1) {
return {error: true, message: 'exceed category limit'};
}
// return realTimeTrends;
const trndingArticle: CreatePost = await this.appService.createChatCompletion(realTimeTrends, index);
...
}
So there is a function called getAllWpCategories which we will give all lists of categories which we have posted to WordPress. Then it will filter the current category which we have selected in the dropdown of swagger and get the category object and then we will pass the shortcode to get Real Time Trends Articles using shortcode and function name is getTrendsArticles.
There is a condition we have written that if we give an index which is greater than the number of articles are available in particular category then it will throw an error that ‘exceed category limit’. We have done some error handling, now let’s look into the AppService how to get content and generate content using ChatGPT.
AppService.ts
npm i wpapi --save
import { Injectable } from '@nestjs/common';
import * as googleTrends from 'google-trends-api';
import { RealTimeTrends } from './models/RealTimeTrends';
import { Configuration, CreateChatCompletionRequest, CreateCompletionRequest, OpenAIApi } from 'openai';
import { InjectWpApi } from '@ntegral/nestjs-wpapi';
import WPAPI from 'wpapi';
import { CreatePost } from './models/WpModels';
// Updated Connstructore with wpapi
constructor(@InjectWpApi() private readonly wpApi: WPAPI, private readonly reflector: Reflector) {
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
organization: process.env.ORGANIZATION_ID
});
this.opneApi = new OpenAIApi(configuration);
}
async getAllWpCategories(): Promise<any> {
return await this.wpApi.categories().get();
}
async getTrendsArticles(category: string = 'all', geo: string = 'US'): Promise<any> {
if (category) {
const realTimeTrendsString = await googleTrends.realTimeTrends({category: category,geo: geo});
const realTimeTrends: RealTimeTrends = JSON.parse(realTimeTrendsString);
return realTimeTrends
}
}
async createChatCompletion(realTimeTrends, index): Promise<any> {
const prompt = (url: string): string => `Outrank the competition with an in-depth, SEO-optimized article based on ${url}. Be like your competition, just a little better`;
const imgTitle = realTimeTrends.storySummaries.trendingStories[index].articles[0].articleTitle.toLocaleLowerCase().split(' ').join('-');
await this.downloadImage(realTimeTrends.storySummaries?.trendingStories[index].image.imgUrl, imgTitle);
if (realTimeTrends.storySummaries?.trendingStories.length && realTimeTrends.storySummaries?.trendingStories[index].articles.length) {
const firstArticleUrl = realTimeTrends.storySummaries?.trendingStories[index].articles[0].url;
const response: any = await this.opneApi.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{"role": "system", "content": prompt(firstArticleUrl)}]
});
return {title: realTimeTrends.storySummaries.trendingStories[index].articles[0].articleTitle, content: response.data?.choices[0].message.content, imgTitle: imgTitle};
}
}
First, if you see the function namely getAllWpCategories it will simply return the list of Categories from WordPress which is the same as Google Trends Category.
Second, this function getTrendsArticles will return Real-Time Trending Articles based on certain categories and countries. The country is defaulted to “US ” and the category is defaulted to “all “if we do not pass any category.
Third, this function createChatCompletion will rewrite the content one by one based on certain category articles. So if you see the function we have given a prompt by combining it with the AIPMT extension which will generate human-friendly, SEO-friendly content for your website. In the Real-Time Articles, we will get a list of articles from different websites for the same topic for a certain category and a certain index. So we take any one of the websites news randomly but here we have taken the first website news and rewritten it using ChatGPT. So this is the code which will pick the first website news at index 0 position
realTimeTrends.storySummaries.trendingStories[index].articles[0]
Once we get the current website news we will take the Image Title and also take the Image URL both of those two things are required to download the image and upload it to WordPress. You can also use your watermark at runtime using node JS before uploading an image for example you can use this npm library like image-watermark to give a watermark on your image.
The downloadImage function will be discussed in more detail in the Next Chapter Part 3. After downloading the image we will take the website URL and pass it into the prompt(firstArticleUrl) function which will build the entire prompt with the URL. And Open API 3.5 turbo model uses this function namely createChatCompletion given below.
await this.opneApi.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{"role": "system", "content": prompt(firstArticleUrl)}]
});
which will generate SEO Friendly Human-like Written content for our website. Once it is done then we will return the generated content, article title and image title which is required to post in WordPress.
Conclusion
So as we have seen step by step how we can use Nest JS and WP Rest API to get WordPress content and rewrite the content using the ChatGPT 3.5 turbo model. In the next chapter Part 3 will describe how to post content using WordPress, download images using axios and how to automate it. We will use Swagger doc as a reference to post content one by one from Swagger doc, We cannot post all content through a loop because one article will take some time to rewrite it using ChatGPT. If we need to achieve these things then we need to use queues using Nest JS and run the process in the background, those are a couple of advanced things which we can cover later.
We have successfully created a full-fledged Automated News Website using ChatGPT, Nest JS, WordPress and with Newspaper Premium Theme. The website Link is given below.
Website Link — https://trendsnewsstories.com/
We have not only made it automated but also made automated posting features for different social media by which AI is managing the website and everything is automated. So there is very little human intervention is there to manage the website. So if you want to build this same news website or any kind of automated website or portal which is scalable and can handle millions of page views using AI features. Then I have a gig in Fiver by which you can take my service and create the same kind of website in any language.
Fiver Gig Link — https://www.fiverr.com/designmart/create-professional-amp-news-website-in-wordpress
Also, the Newspaper is one of the best themes to create a News Website with AMP features. I will always recommend Newspaper theme over any other regular theme if you want to build a News Website using WordPress. This is a premium theme which will cost you some decent money but If want to buy the latest version of Newspaper 12 theme at a lower price with lifetime support then you can buy the theme by using this link at a very nominal price.
Newspaper Theme Link — https://www.etsy.com/in-en/listing/1692514600/newspaper-theme-news-woocommerce