Created
January 3, 2023 17:55
-
-
Save skolo-online/f6c64935ff2c46433b30d5bb0e0c3958 to your computer and use it in GitHub Desktop.
Building the Business Plan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THank You!!
Please where are the Prompts?