Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save k13f7401d/f868625c9019e9543906c796cf7318fa to your computer and use it in GitHub Desktop.
Save k13f7401d/f868625c9019e9543906c796cf7318fa to your computer and use it in GitHub Desktop.
SMAudit
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.togglebutton import ToggleButton
from datetime import datetime
from fpdf import FPDF
import os
class ReportCardGenerator(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = 'vertical'
self.padding = 50
self.spacing = 20
self.title_label = Label(text="Social Media Audit Report Card", font_size=16, bold=True)
self.add_widget(self.title_label)
self.sections = BoxLayout(orientation='vertical', spacing=10)
self.add_widget(self.sections)
self.generate_button = Button(text="Generate Report Card", size_hint=(1.0, 0.5), font_size=22,
on_release=self.generate_report_card)
self.add_widget(self.generate_button)
# Add label widgets with radio buttons
self.add_section("Engagement Rate:", [
"> 5%",
"3%-5%",
"1%-3%",
"< 1%"
])
self.add_section("Follower Growth:", [
"> 10%",
"5%-10%",
"1%-5%",
"No growth"
])
self.add_section("Reach and Impressions:", [
"Consistent +",
"Stable",
"Fluctuations",
"Declining"
])
self.add_section("Click-Through Rate (CTR):", [
">= 5% CTR",
"3%-5% CTR",
"1%-3% CTR",
"< 1% CTR"
])
self.add_section("Conversion Rate:", [
">= 5%",
"3%-5%",
"1%-3%",
"< 1%"
])
def add_section(self, section_name, options):
section_layout = BoxLayout(orientation='horizontal', spacing=10)
section_label_widget = Label(text=section_name, font_size=14, bold=True, size_hint=(0.4, 1))
section_layout.add_widget(section_label_widget)
radio_group = BoxLayout(orientation='horizontal', spacing=10, size_hint=(0.6, 1))
for option in options:
radio_button = ToggleButton(text=option, font_size=12)
radio_group.add_widget(radio_button)
section_layout.add_widget(radio_group)
self.sections.add_widget(section_layout)
def generate_report_card(self, *args):
# Collect the grades from the radio buttons
data = {}
for section_layout in self.sections.children:
section_label_widget = section_layout.children[0].children[0]
section_name = section_label_widget.text
selected_option = None
radio_group = section_layout.children[1]
for radio_button in radio_group.children:
if radio_button.state == 'down':
selected_option = radio_button.text
break
data[section_name] = selected_option
# Generate the date and time string
current_datetime = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# Create the PDF file name using the date and time string
pdf_file_name = f"Report_Card_{current_datetime}.pdf"
# Create the FPDF object
pdf = FPDF()
pdf.add_page() # Add a page to the PDF
pdf.set_font("Arial", "B", 16)
# Add the title
pdf.cell(0, 10, txt="Social Media Audit Report Card", ln=True, align="C")
# Add the sections and grades
pdf.set_font("Arial", "", 12)
for section, grade in data.items():
pdf.cell(0, 10, txt=f"{grade}: {section}", ln=True)
# Save the PDF file
downloads_folder = os.path.expanduser("~/Downloads")
pdf_path = os.path.join(downloads_folder, pdf_file_name)
pdf.output(pdf_path)
print(f"Report card generated successfully. File saved to: {pdf_path}")
class ReportCardApp(App):
def build(self):
return ReportCardGenerator()
if __name__ == "__main__":
ReportCardApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment