Hey there! π
Thanks for visiting this project. I built it to help fellow developers, content creators, and AI enthusiasts like you automate the generation and publishing of news articles using OpenAIβs API. This script fetches fresh, Kenya-relevant news articles in categories like Technology, Politics, Medicine, Education, Business, and Entertainment β and inserts them straight into your database.
No more writing boilerplate news manually. The script generates AI-powered content, checks for duplicates, and logs what it inserted β all in a cron-job-friendly format. Whether youβre running a blog, a content site, or building a news aggregator, this should save you serious time.
- The PHP script loops through your selected news categories.
- For each category, it calls OpenAIβs GPT model with a writing prompt.
- It receives and parses 3 articles (each with a title and body).
- It checks the database for duplicates (by title).
- It inserts only fresh articles into the
gonewstable. - Logs are saved in
cron_news.logto track each run.
Before running the script:
-
Replace the following placeholders in the script:
DB_USERNAME,DB_PASSWORD,DB_NAMEβ your MySQL DB configYOUR_OPENAI_API_KEYβ your OpenAI API key
-
Ensure the following MySQL table exists:
CREATE TABLE `gonews` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`category` VARCHAR(32) NOT NULL,
`title` VARCHAR(255) NOT NULL,
`slug` VARCHAR(255) NOT NULL,
`content` TEXT NOT NULL,
`author_id` INT(11) DEFAULT NULL,
`featured_image` VARCHAR(255) DEFAULT NULL,
`is_top` TINYINT(1) DEFAULT 0,
`status` ENUM('draft','published','archived') DEFAULT 'draft',
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
π Thanks
I truly appreciate you taking a look at this project! I hope it helps you build something amazing. If you have ideas, need improvements, or want to collaborate, feel free to fork, star βοΈ, or contribute. Let AI take care of the writing so you can focus on building. Happy coding! π