About Us Services Blog Contact Us Learn

import requests # OpenAI API Configuration OPENAI_API_KEY = "your_openai_api_key" OPENAI_API_URL = "https://api.openai.com/v1/completions" # Blogger API Configuration BLOGGER_API_KEY = "your_blogger_api_key" BLOG_ID = "your_blog_id" # Get this from your Blogger settings BLOGGER_API_URL = f"https://www.googleapis.com/blogger/v3/blogs/{BLOG_ID}/posts" # Generate SEO Content with OpenAI def generate_seo_content(topic, keywords): headers = { "Authorization": f"Bearer {OPENAI_API_KEY}", "Content-Type": "application/json", } prompt = f"Write a detailed, SEO-optimized blog post about {topic}. Include the following keywords: {keywords}. Use headings, subheadings, bullet points, and a meta description." data = { "model": "text-davinci-003", "prompt": prompt, "max_tokens": 1500, "temperature": 0.7, } response = requests.post(OPENAI_API_URL, headers=headers, json=data) return response.json()["choices"][0]["text"].strip() # Post Content to Blogger def post_to_blogger(title, content): headers = {"Content-Type": "application/json"} data = { "kind": "blogger#post", "title": title, "content": content, } params = {"key": BLOGGER_API_KEY} response = requests.post(BLOGGER_API_URL, headers=headers, json=data, params=params) if response.status_code == 200: print("Post published successfully!") else: print(f"Failed to publish: {response.status_code} {response.text}") # Main Function if __name__ == "__main__": topic = "Top AI Tools for Bloggers in 2024" keywords = "AI tools, blogging tools, best AI tools 2024" content = generate_seo_content(topic, keywords) post_to_blogger(topic, content)

Recent Posts

No comments:

Post a Comment