Added supprt for amazon affiliate links, user inputs and changes to README
This commit is contained in:
31
README.md
31
README.md
@@ -8,21 +8,42 @@ Thus, the generated blog will have text and relevant images.
|
||||
|
||||
Presently, wordpress and WIX integration is present for uploading the generated blog, but needs testing.
|
||||
|
||||
|
||||
This is based on openai gpt models for content generation, google bard for keyword research and some basic tools for plagiarism checker, SEO audit and suggestions to improve the generated content.
|
||||
### This is based on openai gpt models for content generation, google bard for keyword research and some basic tools for plagiarism checker, SEO audit and suggestions to improve the generated content.
|
||||
As prompts are the important ingredients to get the best result, they are stored in prompts folder. Edit these prompts to produce results as per your likings.
|
||||
|
||||
API based blog generation are much cheaper, almost 10x, but difficult to use for everyone. We use bard for search related prompts and chatgpt for generative requirements.
|
||||
### API based blog generation are much cheaper, almost 10x, but difficult to use for everyone. We use bard for search related prompts and chatgpt for generative requirements.
|
||||
|
||||
Check TBD for features currently under development.
|
||||
### Check TBD for features currently under development.
|
||||
|
||||
### Amazon affiliate links are also supported. Given, affiliate tag, your affiliate product links will included in the blogs.
|
||||
To use the module, simply create an instance of the AmazonAffiliateImages class, passing in your Amazon affiliate tag.
|
||||
Then, you can use the get_image_url() or get_image_html() methods to get the Amazon affiliate image URL or HTML
|
||||
for a product, passing in either the product ASIN or the product URL.
|
||||
|
||||
----------------------------------
|
||||
|
||||
## How to use this tool
|
||||
|
||||
*Prerequisites: pip install requirements.txt
|
||||
|
||||
This is in active development and needs ironing out. The main concern is make it general purpose, for all.
|
||||
Usuability and extendibility are major concerns. This section will be updated soon.
|
||||
|
||||
python3 pseo_main.py -h
|
||||
usage: pseo_main.py [-h] [--num_blogs NUM_BLOGS] --keywords KEYWORDS [--niche NICHE]
|
||||
|
||||
Accepts user input for the number of blogs, keywords, and niche.
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
--num_blogs NUM_BLOGS
|
||||
The number of blogs (default: 1).
|
||||
--keywords KEYWORDS The keywords.
|
||||
--niche NICHE Whether the blog is a niche blog (default: False).
|
||||
|
||||
*Example:
|
||||
python3 pseo_main.py --num_blogs "10" --keywords Python, programming, data science --niche True
|
||||
|
||||
----------------------------------
|
||||
|
||||
# The detailed SEO checks are as follows:
|
||||
@@ -41,7 +62,7 @@ Usuability and extendibility are major concerns. This section will be updated so
|
||||
|
||||
-----------------------------------
|
||||
|
||||
#What to write on ?
|
||||
# What to write on ?
|
||||
|
||||
This is basically keyword research for a specific domain, narrowed down by blog topics.
|
||||
We can craft prompts to get an idea on what to generate blogs on. Divide them in topic and write for most searched ones, as below:
|
||||
|
||||
79
lib/amzn_affliate_links/amzn_afflt_img_html.py
Normal file
79
lib/amzn_affliate_links/amzn_afflt_img_html.py
Normal file
@@ -0,0 +1,79 @@
|
||||
###############################################################################
|
||||
#
|
||||
# To use the module, simply create an instance of the AmazonAffiliateImages class,
|
||||
# passing in your Amazon affiliate tag. Then, you can use the get_image_url() or
|
||||
# get_image_html() methods to get the Amazon affiliate image URL or HTML for a product,
|
||||
# passing in either the product ASIN or the product URL.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
class AmazonAffiliateImages:
|
||||
def __init__(self, associate_tag):
|
||||
self.associate_tag = associate_tag
|
||||
|
||||
def get_product_asin(self, product_url):
|
||||
"""Gets the Amazon product ASIN from a product URL.
|
||||
|
||||
Args:
|
||||
product_url: The Amazon product URL.
|
||||
|
||||
Returns:
|
||||
The Amazon product ASIN, or None if the product URL is not valid.
|
||||
"""
|
||||
|
||||
soup = BeautifulSoup(requests.get(product_url).content, "html.parser")
|
||||
asin = soup.find("input", type="hidden", name="ASIN")
|
||||
if asin is not None:
|
||||
return asin.get("value")
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_image_url(self, product_asin):
|
||||
"""Gets the Amazon affiliate image URL for a product.
|
||||
|
||||
Args:
|
||||
product_asin: The Amazon product ASIN.
|
||||
|
||||
Returns:
|
||||
The Amazon affiliate image URL, or None if the product is not found.
|
||||
"""
|
||||
|
||||
url = f"https://images-na.ssl-images-amazon.com/images/I/{product_asin}.jpg"
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
return url
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_image_html(self, product_asin):
|
||||
"""Gets the Amazon affiliate image HTML for a product.
|
||||
|
||||
Args:
|
||||
product_asin: The Amazon product ASIN.
|
||||
|
||||
Returns:
|
||||
The Amazon affiliate image HTML, or None if the product is not found.
|
||||
"""
|
||||
|
||||
image_url = self.get_image_url(product_asin)
|
||||
if image_url is not None:
|
||||
return f'<img src="{image_url}" alt="Amazon Affiliate Image" />'
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
#######################################################
|
||||
|
||||
import amazon_affiliate_images
|
||||
|
||||
affiliate_images = AmazonAffiliateImages("YOUR_ASSOCIATE_TAG")
|
||||
image_html = affiliate_images.get_image_html("B00004CB54")
|
||||
|
||||
# Print the image HTML
|
||||
print(image_html)
|
||||
|
||||
# Output : <img src="https://images-na.ssl-images-amazon.com/images/I/B00004CB54.jpg" alt="Amazon Affiliate Image" />
|
||||
# You can then use this image HTML in your blog post.
|
||||
56
pseo_main.py
56
pseo_main.py
@@ -10,6 +10,7 @@
|
||||
#########################################################
|
||||
import sys
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import traceback
|
||||
from loguru import logger
|
||||
@@ -19,19 +20,48 @@ from lib.generate_image_from_prompt import generate_image, gen_new_from_given_im
|
||||
from lib.get_text_response import get_prompt_reply, generate_detailed_blog
|
||||
|
||||
|
||||
try:
|
||||
logger.info("Starting homebrew pseo blog generator.")
|
||||
prompt = "Create a detailed and technical blog of best AI tools for text-to-video conversion in 2023, along with features, pricing, pros, cons, and website links and if free or paid version. Summarize this blog in conclusion at the end. Write in markdown."
|
||||
#txt_reply = get_prompt_reply(prompt, 2000)
|
||||
def main():
|
||||
"""Parses user arguments and prints them to the console.
|
||||
|
||||
# The idea is to
|
||||
#generate_image(logger)
|
||||
#gen_new_from_given_img(logger)
|
||||
Raises:
|
||||
TypeError: If the user input is not valid.
|
||||
ValueError: If the number of blogs is less than 1.
|
||||
"""
|
||||
|
||||
# Generate detailed blog by only providing keywords from blog title.
|
||||
# Example: AI text to video tools
|
||||
generate_detailed_blog("text to video AI tools")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Accepts user input for the number of blogs, keywords, and niche."
|
||||
)
|
||||
parser.add_argument("--num_blogs", type=int, default=1, help="The number of blogs (default: 1).")
|
||||
parser.add_argument("--keywords", type=str, required=True, help="The keywords.")
|
||||
parser.add_argument("--niche", type=bool, default=False, help="Whether the blog is a niche blog (default: False).")
|
||||
|
||||
except Exception as err:
|
||||
#logger.exception(f"traceback.print_exc()")
|
||||
logger.error(f"Error occured in main::{err}")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check if the user input is valid
|
||||
if not isinstance(args.num_blogs, int) or not isinstance(args.keywords, str) or not isinstance(args.niche, bool):
|
||||
raise TypeError("Invalid user input.")
|
||||
|
||||
# Check if the number of blogs is less than 1
|
||||
if args.num_blogs < 1:
|
||||
raise ValueError("The number of blogs must be at least 1.")
|
||||
|
||||
# Print the user input to the console
|
||||
print(f"Number of blogs: {args.num_blogs}")
|
||||
print(f"Keywords: {args.keywords}")
|
||||
print(f"Niche blog: {args.niche}")
|
||||
|
||||
return args.num_blogs, args.keywords, args.niche
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Check if we have everything, we need to start writing blogs.
|
||||
try:
|
||||
num_blogs, keywords, niche = main()
|
||||
print(f"returned value: {num_blogs} {keywords}")
|
||||
except TypeError as e:
|
||||
print(e)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
else:
|
||||
print(f"Starting to write {num_blogs} on {keywords}")
|
||||
generate_detailed_blog(num_blogs, keywords, niche)
|
||||
|
||||
Reference in New Issue
Block a user