Skip to content

Instantly share code, notes, and snippets.

@skolo-online
Created January 3, 2023 17:55
Show Gist options
  • Save skolo-online/f6c64935ff2c46433b30d5bb0e0c3958 to your computer and use it in GitHub Desktop.
Save skolo-online/f6c64935ff2c46433b30d5bb0e0c3958 to your computer and use it in GitHub Desktop.
Building the Business Plan
from .aifile import *
import asyncio
loop = asyncio.new_event_loop()
## PDF Generation Stuff
import pdfkit
from django.template.loader import get_template
import os
def createPDF(chat, businessPlan):
##Variables we need
profile = chat.profile
#The name of your PDF file
filename = businessPlan.uniqueId+'.pdf'
#HTML FIle to be converted to PDF - inside your Django directory
template = get_template('business/document.html')
#Add any context variables you need to be dynamically rendered in the HTML
context = {}
context['date'] = businessPlan.date_created
context['business_name'] = chat.business_name
context['company_description'] = businessPlan.company_description
context['market_analysis'] = businessPlan.market_analysis
context['swot_analysis'] = businessPlan.swot_analysis
context['product_detail'] = businessPlan.product_detail
context['marketing_strategy'] = businessPlan.marketing_strategy
#Render the HTML
html = template.render(context)
#Options - Very Important [Don't forget this]
options = {
'encoding': 'UTF-8',
'enable-local-file-access': None, #To be able to access CSS
'page-size': 'A4',
'custom-header' : [
('Accept-Encoding', 'gzip')
],
}
#Remember that location to wkhtmltopdf
config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')
#Saving the File
file_path = settings.MEDIA_ROOT + '/business_plans/{}/'.format(profile.uniqueId)
os.makedirs(file_path, exist_ok=True)
pdf_save_path = file_path+filename
#Save the PDF
pdfkit.from_string(html, pdf_save_path, configuration=config, options=options)
return 'https://message.skolo.online/uploads'+'/business_plans/{}/{}'.format(profile.uniqueId, filename)
def buildBusinessPlan(chat):
company_description = companyDescriptionProgress(chat.business_name, chat.business_type, chat.country, chat.product_service, chat.short_description, chat.years, chat.progress)
market_analysis = marketAnalysis(chat.business_name, chat.product_service, chat.short_description)
swot_analysis = swotAnalysis(chat.business_name, chat.product_service, chat.short_description)
product_detail = productDetail(chat.business_name, chat.product_service, chat.short_description)
marketing_strategy = marketingStrategyAndPlan(chat.business_name, chat.product_service, chat.short_description)
businessPlan = BusinessPlan.objects.create(
profile = chat.profile,
company_description = company_description,
market_analysis = market_analysis,
swot_analysis = swot_analysis,
product_detail =product_detail,
marketing_strategy = marketing_strategy)
businessPlan.save()
return businessPlan
def createNewBusinessPlan(chat):
#1. Build the Business Plan
businessPlan = buildBusinessPlan(chat)
#2 .Create Document PDF
doc_url = createPDF(chat, businessPlan)
#3. Send Document Link to User
message = '😄 Your Business Plan is ready 👇🏽👇🏽 \n \n {}'.format(doc_url)
sendWhastAppMessage(chat.profile.phoneNumber, message)
####Delete the chat at the end
chat.delete()
@nonsonwune
Copy link

THank You!!
Please where are the Prompts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment