Added version 4

This commit is contained in:
2026-01-30 11:47:06 +03:00
parent 05aea043b6
commit 801844807e
2205 changed files with 2048 additions and 0 deletions

BIN
jokes_bot/v3.0/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,684 @@
<!DOCTYPE html>
<!-- saved from url=(0069)file:///Users/home/Downloads/deepseek_html_20260120_a4e55e%20(1).html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Joke Bot Upgrade: SQLite Database Integration</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
body {
background: #f8fafc;
height: 100vh;
display: flex;
flex-direction: column;
padding: 20px;
}
.container {
flex: 1;
display: flex;
flex-direction: column;
max-width: 1000px;
margin: 0 auto;
width: 100%;
height: calc(100vh - 80px);
}
.slide {
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.08);
padding: 30px 40px;
margin: 10px 0;
display: none;
flex: 1;
overflow-y: auto;
}
.slide.active {
display: flex;
flex-direction: column;
}
h1 {
color: #2c3e50;
font-size: 2.2rem;
margin-bottom: 20px;
text-align: center;
}
h2 {
color: #2c3e50;
font-size: 1.8rem;
margin-bottom: 15px;
}
h3 {
color: #2c3e50;
font-size: 1.4rem;
margin: 20px 0 10px 0;
}
p {
font-size: 1.1rem;
line-height: 1.6;
margin: 15px 0;
color: #4a5568;
}
.code-block {
background: #1a202c;
color: #e2e8f0;
padding: 20px;
border-radius: 6px;
margin: 15px 0;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 0.95rem;
line-height: 1.5;
white-space: pre-wrap;
overflow-wrap: break-word;
}
.instruction-block {
background: #fff8e1;
border-left: 4px solid #ffb300;
padding: 15px;
margin: 15px 0;
border-radius: 0 4px 4px 0;
}
.step-number {
display: inline-block;
background: #ffb300;
color: white;
width: 24px;
height: 24px;
border-radius: 50%;
text-align: center;
line-height: 24px;
margin-right: 10px;
font-weight: bold;
}
.nav-container {
display: flex;
justify-content: space-between;
margin-top: 25px;
padding-top: 20px;
border-top: 1px solid #e2e8f0;
}
.nav-btn {
background: #4299e1;
color: white;
border: none;
padding: 10px 25px;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: 500;
min-width: 100px;
}
.nav-btn:hover {
background: #3182ce;
}
.nav-btn:disabled {
background: #cbd5e0;
cursor: not-allowed;
}
.slide-counter {
text-align: center;
color: #718096;
font-size: 0.9rem;
margin-bottom: 10px;
font-weight: 500;
}
.terminal {
background: #2d3748;
color: #e2e8f0;
padding: 15px;
border-radius: 6px;
font-family: 'Consolas', monospace;
margin: 10px 0;
font-size: 0.9rem;
line-height: 1.5;
white-space: pre-wrap;
}
.db-structure {
background: #f0fff4;
border: 1px solid #9ae6b4;
padding: 15px;
border-radius: 6px;
margin: 10px 0;
font-family: 'Consolas', monospace;
font-size: 0.9rem;
color: #2f855a;
line-height: 1.5;
white-space: pre-wrap;
}
ul {
margin: 15px 0 15px 20px;
color: #4a5568;
}
li {
margin: 8px 0;
}
code {
background: #edf2f7;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Consolas', monospace;
font-size: 0.9rem;
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.slide {
padding: 20px;
}
h1 {
font-size: 1.8rem;
}
h2 {
font-size: 1.5rem;
}
h3 {
font-size: 1.2rem;
}
}
</style>
</head>
<body>
<div class="slide-counter" id="slide-counter">Slide 3 of 8</div>
<div class="container">
<!-- Slide 1: Title -->
<div class="slide" id="slide1">
<div style="flex: 1; display: flex; flex-direction: column; justify-content: center;">
<h1>Joke Bot Upgrade: SQLite Database</h1>
<p style="font-size: 1.3rem; color: #4a5568;">From Static List to Dynamic Database</p>
<p style="margin-top: 30px; font-size: 1.1rem; color: #718096;">
Transform your simple joke bot into a collaborative joke database
</p>
</div>
<div class="nav-container">
<button class="nav-btn" id="prevBtn1">Previous</button>
<button class="nav-btn" id="nextBtn1">Next</button>
</div>
</div>
<!-- Slide 2: Original vs Upgraded Code -->
<div class="slide" id="slide2">
<h2>From Static List to Database</h2>
<p><strong>Original Code (Static List):</strong></p>
<div class="code-block"># Static joke list - hardcoded, unchanging
JOKE_LIST = [
"Why did the robot go to school? To recharge his brain!",
"Knock knock!\nWho's there?\nBoo!\nBoo who?\nDon't cry!",
"Why don't eggs tell jokes? They'd crack each other up!",
]
async def get_random_joke(update: Update, context: ContextTypes.DEFAULT_TYPE):
joke = random.choice(JOKE_LIST) # Limited to pre-defined jokes
await update.message.reply_text(joke)</div>
<p><strong>Upgraded Code (SQLite Database):</strong></p>
<div class="code-block"># Dynamic database - users can add jokes
import sqlite3
async def joke(update, context):
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
joke = conn.execute("SELECT text FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
conn.close()
await update.message.reply_text(joke[0] if joke else "No jokes! /addjoke to add one")
async def addjoke(update, context):
waiting[update.effective_user.id] = True
await update.message.reply_text("Type your joke:")</div>
<p><strong>Key Improvements:</strong></p>
<ul>
<li>Static list → Dynamic SQLite database</li>
<li>Hardcoded jokes → User-contributed content</li>
<li>Limited selection → Unlimited joke storage</li>
<li>Teacher-only → Collaborative system</li>
</ul>
<div class="nav-container">
<button class="nav-btn" id="prevBtn2">Previous</button>
<button class="nav-btn" id="nextBtn2">Next</button>
</div>
</div>
<!-- Slide 3: Step-by-Step Guide - Part 1 -->
<div class="slide active" id="slide3">
<h2>Step-by-Step Upgrade Guide - Part 1</h2>
<p>Let's upgrade your Joke Bot one step at a time:</p>
<div class="instruction-block">
<div class="step-number">1</div>
<strong>Remove the old joke list</strong>
<p>Find this line in your original code:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
JOKE_LIST = [
"Why did the robot go to school? To recharge his brain!",
# ... more jokes ...
]</div>
<p>Delete everything from <code>JOKE_LIST = [</code> to the closing <code>]</code> including all jokes.</p>
</div>
<div class="instruction-block">
<div class="step-number">2</div>
<strong>Add SQLite import</strong>
<p>At the VERY TOP of your file, add this line:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
import sqlite3</div>
<p>This should go right after the other imports, like:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
import random
import sqlite3 # ← ADD THIS LINE</div>
</div>
<div class="instruction-block">
<div class="step-number">3</div>
<strong>Add waiting dictionary</strong>
<p>Find your <code>BOT_TOKEN</code> line and add this right after it:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
BOT_TOKEN = "YOUR_BOT_TOKEN_HERE"
waiting = {} # ← ADD THIS LINE</div>
<p>This dictionary will track users who are typing jokes.</p>
</div>
<div class="nav-container">
<button class="nav-btn" id="prevBtn3">Previous</button>
<button class="nav-btn" id="nextBtn3">Next</button>
</div>
</div>
<!-- Slide 4: Step-by-Step Guide - Part 2 -->
<div class="slide" id="slide4">
<h2>Step-by-Step Upgrade Guide - Part 2</h2>
<div class="instruction-block">
<div class="step-number">4</div>
<strong>Update the joke function</strong>
<p>Find your <code>get_random_joke</code> function. DELETE this entire function:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
async def get_random_joke(update: Update, context: ContextTypes.DEFAULT_TYPE):
joke = random.choice(JOKE_LIST)
await update.message.reply_text(joke)</div>
<p>REPLACE it with this new function:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
async def joke(update, context):
"""Get random joke from database"""
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
joke = conn.execute("SELECT text FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
conn.close()
if joke:
await update.message.reply_text(joke[0])
else:
await update.message.reply_text("No jokes in database! Use /addjoke to add one.")</div>
</div>
<div class="instruction-block">
<div class="step-number">5</div>
<strong>Add the addjoke function</strong>
<p>Right after your <code>joke</code> function, add this new function:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
async def addjoke(update, context):
"""Initiate joke addition process"""
waiting[update.effective_user.id] = True
await update.message.reply_text("Type your joke (one message):")</div>
<p>This function starts the process when users type <code>/addjoke</code>.</p>
</div>
<div class="nav-container">
<button class="nav-btn" id="prevBtn4">Previous</button>
<button class="nav-btn" id="nextBtn4">Next</button>
</div>
</div>
<!-- Slide 5: Step-by-Step Guide - Part 3 -->
<div class="slide" id="slide5">
<h2>Step-by-Step Upgrade Guide - Part 3</h2>
<div class="instruction-block">
<div class="step-number">6</div>
<strong>Add the text handler function</strong>
<p>Add this function after your <code>addjoke</code> function:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px; margin-bottom: 10px;">
async def handle_text(update, context):
"""Handle text messages for joke addition"""
user_id = update.effective_user.id
if user_id in waiting:
# User is adding a joke
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
# Insert joke with user info
conn.execute("INSERT INTO jokes VALUES (?, ?, ?)",
(update.message.text, user_id, update.effective_user.first_name))
conn.commit()
conn.close()
# Remove from waiting list
del waiting[user_id]
await update.message.reply_text("✅ Joke saved to database!")
else:
# Regular message, not adding joke
await update.message.reply_text("Try /start to see available commands")</div>
<p>This function catches regular messages and saves jokes to the database.</p>
</div>
<div class="instruction-block">
<div class="step-number">7</div>
<strong>Update the main function</strong>
<p>Find your <code>main()</code> function. Change it from this:</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px; margin-bottom: 10px;">
def main():
print("🚀 Starting Joke Bot...")
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("joke", get_random_joke))
print("✅ Bot is running! Press Ctrl+C to stop.")
app.run_polling()</div>
<p>To this (CHANGE the highlighted lines):</p>
<div class="code-block" style="background: #4a5568; font-size: 0.9rem; padding: 10px;">
def main():
print("🚀 Starting Joke Bot...")
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("joke", joke)) # ← CHANGE get_random_joke to joke
app.add_handler(CommandHandler("addjoke", addjoke)) # ← ADD THIS LINE
app.add_handler(MessageHandler(filters.TEXT &amp; ~filters.COMMAND, handle_text)) # ← ADD THIS LINE
print("✅ Bot is running! Press Ctrl+C to stop.")
app.run_polling()</div>
</div>
<div class="nav-container">
<button class="nav-btn" id="prevBtn5">Previous</button>
<button class="nav-btn" id="nextBtn5">Next</button>
</div>
</div>
<!-- Slide 6: SQLite Database Implementation -->
<div class="slide" id="slide6">
<h2>SQLite Database Implementation</h2>
<p><strong>Your Code Should Now Include:</strong></p>
<div class="code-block">import sqlite3 # Added at top
# ... other imports ...
BOT_TOKEN = "YOUR_BOT_TOKEN_HERE"
waiting = {} # Added after token
# ... start function remains the same ...
async def joke(update, context):
# New database-powered joke function
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
joke = conn.execute("SELECT text FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
conn.close()
if joke:
await update.message.reply_text(joke[0])
else:
await update.message.reply_text("No jokes in database! Use /addjoke to add one.")
async def addjoke(update, context):
# New function for adding jokes
waiting[update.effective_user.id] = True
await update.message.reply_text("Type your joke (one message):")
async def handle_text(update, context):
# New function to handle text messages
user_id = update.effective_user.id
if user_id in waiting:
# Save joke to database
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
conn.execute("INSERT INTO jokes VALUES (?, ?, ?)",
(update.message.text, user_id, update.effective_user.first_name))
conn.commit()
conn.close()
del waiting[user_id]
await update.message.reply_text("✅ Joke saved to database!")
else:
await update.message.reply_text("Try /start to see available commands")</div>
<div class="nav-container">
<button class="nav-btn" id="prevBtn6">Previous</button>
<button class="nav-btn" id="nextBtn6">Next</button>
</div>
</div>
<!-- Slide 7: Database Structure & Commands -->
<div class="slide" id="slide7">
<h2>Database Structure &amp; Bot Commands</h2>
<p><strong>SQLite Database Schema:</strong></p>
<div class="db-structure">-- jokes.db SQLite database structure
CREATE TABLE jokes (
text TEXT, -- The joke text
user TEXT, -- User ID for tracking
name TEXT -- User's first name
);
-- Sample data:
INSERT INTO jokes VALUES
('Why did the Python cross the road? To get to the other side!', '12345', 'Alice'),
('What do you call a fake noodle? An impasta!', '67890', 'Bob');</div>
<p><strong>Your Bot Now Has These Commands:</strong></p>
<div class="terminal">/start - Start the bot and see commands
/joke - Get a random joke from database
/addjoke - Add your own joke to database</div>
<p><strong>How It Works:</strong></p>
<ul>
<li>When user types <code>/joke</code> → Bot gets random joke from database</li>
<li>When user types <code>/addjoke</code> → Bot waits for their joke</li>
<li>User types their joke → Bot saves it to SQLite database</li>
<li>Everyone can now access that joke with <code>/joke</code></li>
</ul>
<p><strong>Important Note:</strong> The database file <code>jokes.db</code> will be created automatically the first time you run your bot.</p>
<div class="nav-container">
<button class="nav-btn" id="prevBtn7">Previous</button>
<button class="nav-btn" id="nextBtn7">Next</button>
</div>
</div>
<!-- Slide 8: Complete Implementation -->
<div class="slide" id="slide8">
<h2>Complete Implementation Code</h2>
<div class="code-block">from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters
import sqlite3
# Replace with your actual bot token
TOKEN = "YOUR_BOT_TOKEN_HERE"
# Track users who are currently adding jokes
waiting = {}
async def start(update, context):
"""Handle /start command"""
await update.message.reply_text(
"Welcome to Joke Bot!\n\n"
"Available commands:\n"
"/joke - Get a random joke\n"
"/addjoke - Add your own joke to the database"
)
async def joke(update, context):
"""Handle /joke command - get random joke from database"""
conn = sqlite3.connect('jokes.db')
# Create table if it doesn't exist
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
# Get random joke
joke = conn.execute("SELECT text FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
conn.close()
if joke:
await update.message.reply_text(joke[0])
else:
await update.message.reply_text("No jokes in the database yet! Use /addjoke to add one.")
async def addjoke(update, context):
"""Handle /addjoke command - start joke addition process"""
waiting[update.effective_user.id] = True
await update.message.reply_text("Type your joke (send it in one message):")
async def handle_text(update, context):
"""Handle all text messages"""
user_id = update.effective_user.id
if user_id in waiting:
# User is adding a joke
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
# Save joke with user information
conn.execute(
"INSERT INTO jokes VALUES (?, ?, ?)",
(update.message.text, user_id, update.effective_user.first_name)
)
conn.commit()
conn.close()
# Remove user from waiting list
del waiting[user_id]
await update.message.reply_text("Joke saved to the database! Others can now see it with /joke")
else:
# Regular message (not adding joke)
await update.message.reply_text("I don't understand that. Try /start to see available commands.")
# Main bot setup
app = Application.builder().token(TOKEN).build()
# Add command handlers
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("joke", joke))
app.add_handler(CommandHandler("addjoke", addjoke))
# Add text message handler (for joke input)
app.add_handler(MessageHandler(filters.TEXT &amp; ~filters.COMMAND, handle_text))
print("Joke Bot is running with SQLite database support!")
app.run_polling()</div>
<div class="nav-container">
<button class="nav-btn" id="prevBtn8">Previous</button>
<button class="nav-btn" id="nextBtn8">Next</button>
</div>
</div>
</div>
<script>
const totalSlides = 8;
let currentSlide = 1;
function updateSlideCounter() {
document.getElementById('slide-counter').textContent = `Slide ${currentSlide} of ${totalSlides}`;
}
function showSlide(slideNumber) {
for (let i = 1; i <= totalSlides; i++) {
const slide = document.getElementById(`slide${i}`);
if (slide) slide.classList.remove('active');
}
const slideElement = document.getElementById(`slide${slideNumber}`);
if (slideElement) {
slideElement.classList.add('active');
currentSlide = slideNumber;
updateSlideCounter();
updateButtons();
}
}
function updateButtons() {
for (let i = 1; i <= totalSlides; i++) {
const prevBtn = document.getElementById(`prevBtn${i}`);
const nextBtn = document.getElementById(`nextBtn${i}`);
if (prevBtn) prevBtn.disabled = currentSlide === 1;
if (nextBtn) {
nextBtn.textContent = currentSlide === totalSlides ? 'Finish' : 'Next';
}
}
}
for (let i = 1; i <= totalSlides; i++) {
const nextBtn = document.getElementById(`nextBtn${i}`);
const prevBtn = document.getElementById(`prevBtn${i}`);
if (nextBtn) {
nextBtn.addEventListener('click', () => {
if (currentSlide < totalSlides) {
showSlide(currentSlide + 1);
} else {
alert('Congratulations! You have completed the Joke Bot upgrade tutorial. Your bot now has a SQLite database and can accept user-submitted jokes!');
}
});
}
if (prevBtn) {
prevBtn.addEventListener('click', () => {
if (currentSlide > 1) {
showSlide(currentSlide - 1);
}
});
}
}
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === ' ') {
if (currentSlide < totalSlides) showSlide(currentSlide + 1);
} else if (e.key === 'ArrowLeft') {
if (currentSlide > 1) showSlide(currentSlide - 1);
}
});
updateSlideCounter();
updateButtons();
</script>
</body></html>

View File

@@ -0,0 +1,749 @@
<!DOCTYPE html>
<!-- saved from url=(0063)file:///Users/home/Downloads/deepseek_html_20260120_76fab4.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lesson Slides Template</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: #f8f9fa;
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px;
}
.container {
flex: 1;
display: flex;
flex-direction: column;
max-width: 1000px;
margin: 0 auto;
width: 100%;
height: calc(100vh - 60px);
}
.slide {
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
padding: 30px 40px;
margin: 10px 0;
display: none;
flex: 1;
overflow-y: auto;
max-height: 82vh;
min-height: 400px;
}
.slide.active {
display: flex;
flex-direction: column;
}
h1 {
color: #2c3e50;
font-size: 2.2rem;
margin-bottom: 15px;
text-align: center;
font-weight: 600;
}
h2 {
color: #2c3e50;
font-size: 1.8rem;
margin-bottom: 20px;
text-align: center;
font-weight: 600;
}
h3 {
color: #2c3e50;
font-size: 1.4rem;
margin-bottom: 15px;
}
.lesson-title {
color: #2980b9;
font-size: 1.8rem;
margin-bottom: 10px;
text-align: center;
font-weight: 600;
}
.subject-topic {
color: #27ae60;
font-size: 1.5rem;
margin-bottom: 10px;
text-align: center;
font-weight: 600;
}
.subject-title {
text-align: center;
color: #7f8c8d;
font-size: 1.2rem;
margin-bottom: 30px;
font-style: italic;
}
p {
font-size: 1.1rem;
line-height: 1.6;
margin: 15px 0;
color: #34495e;
}
ul, ol {
margin: 15px 0 20px 30px;
font-size: 1.1rem;
line-height: 1.6;
color: #34495e;
}
li {
margin: 10px 0;
}
.rules-container {
background-color: #f8f9fa;
border-radius: 6px;
padding: 25px;
margin: 20px 0;
border-left: 4px solid #3498db;
}
.outcomes-container {
background-color: #e8f4fd;
border-radius: 6px;
padding: 25px;
margin: 20px 0;
}
.why-container {
background-color: #f0f7ff;
border-radius: 6px;
padding: 25px;
margin: 20px 0;
}
.content-container {
margin: 20px 0;
}
.terminal {
background-color: #2c3e50;
color: #ecf0f1;
padding: 20px;
border-radius: 6px;
font-family: 'Courier New', monospace;
margin: 20px 0;
font-size: 1rem;
line-height: 1.5;
white-space: pre-wrap;
word-wrap: break-word;
}
.terminal-command {
color: #2ecc71;
}
.terminal-comment {
color: #95a5a6;
font-style: italic;
}
.button-container {
display: flex;
justify-content: space-between;
margin-top: auto;
padding-top: 20px;
border-top: 1px solid #eee;
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 10px 20px;
font-size: 1rem;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.2s;
font-weight: 500;
min-width: 120px;
}
button:hover {
background-color: #2980b9;
}
button:disabled {
background-color: #bdc3c7;
cursor: not-allowed;
}
.slide-counter {
text-align: center;
color: #7f8c8d;
font-size: 1rem;
margin-bottom: 10px;
font-weight: 500;
}
.lead {
font-size: 1.2rem;
color: #7f8c8d;
text-align: center;
margin-bottom: 20px;
}
code {
background-color: #f1f2f3;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.95rem;
}
.important-box {
background-color: #fff3cd;
border: 2px solid #ffeaa7;
border-radius: 6px;
padding: 15px;
margin: 20px 0;
}
@media (max-width: 768px) {
body {
padding: 5px;
}
.container {
height: calc(100vh - 40px);
}
.slide {
padding: 20px 25px;
min-height: 300px;
}
h1 {
font-size: 1.8rem;
}
h2 {
font-size: 1.5rem;
}
h3 {
font-size: 1.2rem;
}
.lesson-title {
font-size: 1.5rem;
}
.subject-topic {
font-size: 1.3rem;
}
p, ul, ol {
font-size: 1rem;
}
button {
padding: 8px 16px;
font-size: 0.95rem;
min-width: 100px;
}
}
</style>
</head>
<body>
<div class="slide-counter" id="slide-counter">Slide 7 of 12</div>
<div class="container">
<!-- Slide 1: Title Slide -->
<div class="slide" id="slide1">
<div style="flex: 1; display: flex; flex-direction: column; justify-content: center;">
<div class="lesson-title">Upgrade Your Joke Bot!</div>
<div class="subject-topic">AI6-M3: Database Integration</div>
<div class="subject-title">Digital Technologies / Information Communication Technologies</div>
</div>
<div class="button-container">
<button id="prevBtn1">Previous</button>
<button id="nextBtn1">Next</button>
</div>
</div>
<!-- Slide 2: Rules -->
<div class="slide" id="slide2">
<h2>Classroom Guidelines</h2>
<div class="rules-container">
<h3>How Points Are Earned:</h3>
<p><strong>+2 Points</strong> - You attended class</p>
<p><strong>+1 Point</strong> - You listened quietly during instruction</p>
<p><strong>+1 Point</strong> - You attempted all assigned work</p>
<p><strong>+1 Point</strong> - You completed all assigned work</p>
<p style="margin-top: 25px; font-weight: bold; color: #27ae60;">
Maximum: 5 points per class session
</p>
</div>
<div class="button-container">
<button id="prevBtn2">Previous</button>
<button id="nextBtn2">Next</button>
</div>
</div>
<!-- Slide 3: Learning Outcomes -->
<div class="slide" id="slide3">
<h2>Learning Outcomes</h2>
<p class="subject-title">By the end of this lesson, you will be able to:</p>
<div class="outcomes-container">
<ol>
<li>Download a project from the internet (using Git clone)</li>
<li>Open and understand a Python program (starter_app.py)</li>
<li>Make simple changes to make the program better</li>
<li>Save your work to the internet (using Git push)</li>
</ol>
</div>
<div class="button-container">
<button id="prevBtn3">Previous</button>
<button id="nextBtn3">Next</button>
</div>
</div>
<!-- Slide 4: Why This Matters -->
<div class="slide" id="slide4">
<h2>Why This Matters</h2>
<div class="why-container">
<ul>
<li>Learn how real programmers work together</li>
<li>Understand how apps remember things (using databases)</li>
<li>Practice following step-by-step instructions</li>
<li>Create something that actually works!</li>
<li>These skills help with school projects and future jobs</li>
</ul>
<p style="margin-top: 30px;"><strong>Who uses these skills?</strong></p>
<p>Every app on your phone (Instagram, TikTok, games) needs databases to remember your information!</p>
</div>
<div class="button-container">
<button id="prevBtn4">Previous</button>
<button id="nextBtn4">Next</button>
</div>
</div>
<!-- Slide 5: Our Special Web Address -->
<div class="slide" id="slide5">
<h2>Step 1: Find Our Project Online</h2>
<p class="lead">Every project has a special web address (URL)</p>
<div class="content-container">
<div class="important-box">
<strong>💡 IMPORTANT:</strong> You MUST use this exact address:<br>
<code>https://gitea.techshare.cc/technolyceum/ai6-m3.git</code>
</div>
<p><strong>Think of it like:</strong></p>
<ul>
<li>This is our project's "home" on the internet</li>
<li>Like downloading a game from the App Store</li>
<li>We're getting all the files we need to start</li>
</ul>
<p><strong>What's inside this address?</strong></p>
<div class="terminal">
<span class="terminal-comment"># Inside this address you'll find:</span>
📁 ai6-m3-project/
├── 📄 starter_app.py ← The joke bot you'll upgrade!
├── 📄 requirements.txt ← List of things needed
├── 📄 README.md ← Instructions
└── 📄 .gitignore ← Special settings file
</div>
</div>
<div class="button-container">
<button id="prevBtn5">Previous</button>
<button id="nextBtn5">Next</button>
</div>
</div>
<!-- Slide 6: Download with Git Clone -->
<div class="slide" id="slide6">
<h2>Step 2: Download to Your Computer</h2>
<p class="lead">Using "Git Clone" - like copying a folder from the internet</p>
<div class="content-container">
<p><strong>Open Command Prompt (Windows):</strong></p>
<p>Press <code>Windows Key</code>, type <code>cmd</code>, press <code>Enter</code></p>
<p><strong>Go to Desktop:</strong></p>
<div class="terminal">
<span class="terminal-comment"># Type this to go to your Desktop:</span>
<span class="terminal-command">cd Desktop</span>
<span class="terminal-comment"># Check you're on Desktop:</span>
<span class="terminal-command">dir</span>
<span class="terminal-comment"># You'll see your Desktop files</span>
</div>
<p><strong>DOWNLOAD THE PROJECT:</strong></p>
<div class="terminal">
<span class="terminal-comment"># Copy everything from the internet to your computer:</span>
<span class="terminal-command">git clone https://gitea.techshare.cc/technolyceum/ai6-m3.git</span>
<span class="terminal-comment"># This creates a folder called "ai6-m3" on your Desktop</span>
</div>
<p><strong>Check it worked:</strong></p>
<div class="terminal">
<span class="terminal-command">cd ai6-m3</span>
<span class="terminal-command">dir</span>
<span class="terminal-comment"># You should see "starter_app.py" in the list!</span>
</div>
</div>
<div class="button-container">
<button id="prevBtn6">Previous</button>
<button id="nextBtn6">Next</button>
</div>
</div>
<!-- Slide 7: Open and Look at the Joke Bot -->
<div class="slide active" id="slide7">
<h2>Step 3: Open the Joke Bot Program</h2>
<p class="lead">Let's see what we're working with!</p>
<div class="content-container">
<p><strong>Using VS Code (or any text editor):</strong></p>
<div class="terminal">
<span class="terminal-comment"># Make sure you're in the right folder:</span>
<span class="terminal-command">cd Desktop\ai6-m3</span>
<span class="terminal-comment"># Open the folder in VS Code:</span>
<span class="terminal-command">code .</span>
<span class="terminal-comment"># Or open VS Code and use File → Open Folder</span>
</div>
<p><strong>Look for this file:</strong></p>
<div class="terminal">
📁 ai6-m3/
└── 📄 <strong>starter_app.py</strong> ← DOUBLE CLICK THIS!
</div>
<p><strong>What you'll see:</strong></p>
<ul>
<li>A Python program that tells jokes</li>
<li>Right now, it only has 3 jokes</li>
<li>We're going to make it remember MORE jokes</li>
</ul>
<p><strong>Try running it first:</strong></p>
<div class="terminal">
<span class="terminal-command">python starter_app.py</span>
<span class="terminal-comment"># It should tell you a random joke!</span>
</div>
</div>
<div class="button-container">
<button id="prevBtn7">Previous</button>
<button id="nextBtn8">Next</button>
</div>
</div>
<!-- Slide 8: Make the Joke Bot Better -->
<div class="slide" id="slide8">
<h2>Step 4: Upgrade Your Joke Bot!</h2>
<p class="lead">Make it remember jokes using a database</p>
<div class="content-container">
<p><strong>Your mission:</strong></p>
<ol>
<li>Add at least 5 new jokes to the program</li>
<li>Make it remember jokes even after you close it</li>
<li>Test that it works!</li>
</ol>
<p><strong>Simple changes to make:</strong></p>
<div class="terminal">
<span class="terminal-comment"># In starter_app.py, find this part:</span>
jokes = [
"Why don't scientists trust atoms?...",
"Why did the chicken cross the road?...",
"What do you call fake spaghetti?..."
]
<span class="terminal-comment"># ADD YOUR JOKES HERE!</span>
<span class="terminal-command"> "Your first joke here",</span>
<span class="terminal-command"> "Your second joke here",</span>
<span class="terminal-command"> "Keep adding more!"</span>
<span class="terminal-comment"># Don't forget the comma at the end!</span>
</div>
<p><strong>Database part (teacher will help):</strong></p>
<div class="terminal">
<span class="terminal-comment"># We'll add code to save jokes to a file</span>
<span class="terminal-comment"># So jokes don't disappear when you close the program</span>
</div>
</div>
<div class="button-container">
<button id="prevBtn8">Previous</button>
<button id="nextBtn9">Next</button>
</div>
</div>
<!-- Slide 9: Save Your Work with Git -->
<div class="slide" id="slide9">
<h2>Step 5: Save Your Work Online</h2>
<p class="lead">Using Git - like saving to the cloud</p>
<div class="content-container">
<p><strong>First, check what you changed:</strong></p>
<div class="terminal">
<span class="terminal-comment"># Make sure you're in ai6-m3 folder:</span>
<span class="terminal-command">cd Desktop\ai6-m3</span>
<span class="terminal-comment"># See what files you changed:</span>
<span class="terminal-command">git status</span>
<span class="terminal-comment"># It will show "starter_app.py" in red or green</span>
</div>
<p><strong>Step 1: Tell Git about your changes</strong></p>
<div class="terminal">
<span class="terminal-command">git add .</span>
<span class="terminal-comment"># This means: "Save ALL my changes"</span>
<span class="terminal-comment"># The dot (.) means "everything in this folder"</span>
</div>
<p><strong>Step 2: Give your work a title</strong></p>
<div class="terminal">
<span class="terminal-command">git commit -m "Upgraded app for database implementation"</span>
<span class="terminal-comment"># This is like putting your name on your work</span>
<span class="terminal-comment"># "Upgraded app for database implementation" is your title</span>
</div>
<p><strong>Step 3: Send it online</strong></p>
<div class="terminal">
<span class="terminal-command">git push</span>
<span class="terminal-comment"># This sends your work back to the internet</span>
<span class="terminal-comment"># Now everyone can see your upgraded joke bot!</span>
</div>
</div>
<div class="button-container">
<button id="prevBtn9">Previous</button>
<button id="nextBtn10">Next</button>
</div>
</div>
<!-- Slide 10: What You Learned -->
<div class="slide" id="slide10">
<h2>What You Learned</h2>
<div class="content-container">
<p>In this lesson, you have learned how to:</p>
<ol>
<li>Download a project from the internet using a special address</li>
<li>Open and run a Python program on your computer</li>
<li>Add new jokes to make the program better</li>
<li>Save your work and share it online using Git</li>
</ol>
<p><strong>Key Takeaways:</strong></p>
<p>You now know the basic workflow of real programmers: <strong>Download → Modify → Save → Share</strong>. This is how all apps and games get made!</p>
<div class="important-box">
<strong>🎉 CONGRATULATIONS!</strong><br>
You just completed your first programming project upgrade!
</div>
</div>
<div class="button-container">
<button id="prevBtn10">Previous</button>
<button id="nextBtn11">Next</button>
</div>
</div>
<!-- Slide 11: Questions -->
<div class="slide" id="slide11">
<h2>Questions &amp; Discussion</h2>
<div class="content-container">
<p><strong>Review what we covered:</strong></p>
<ul>
<li>What was the most fun part of upgrading the joke bot?</li>
<li>Did your jokes make your friends laugh?</li>
<li>What other things would you like a bot to remember?</li>
<li>Was Git push confusing? What part?</li>
</ul>
<p><strong>Common Issues:</strong></p>
<ul>
<li>Forgot commas between jokes? → Add them!</li>
<li>Git says "not a git repository"? → Make sure you're in ai6-m3 folder!</li>
<li>Python won't run? → Check for typos in your code</li>
</ul>
<p><strong>Need Additional Help?</strong></p>
<p>Raise your hand! Ask your neighbor! The teacher is here to help!</p>
</div>
<div class="button-container">
<button id="prevBtn11">Previous</button>
<button id="nextBtn12">Next</button>
</div>
</div>
<!-- Slide 12: Thank You -->
<div class="slide" id="slide12">
<div class="content-container">
<h1>Great Job! 🎉</h1>
<p>Thank you for being awesome programmers today!</p>
<p><strong>Your Joke Bot is now upgraded and saved online!</strong></p>
<div class="important-box">
<strong>🌟 YOU DID IT! 🌟</strong><br>
You downloaded code, made it better, and saved it for everyone to see!
</div>
<p><strong>Next Steps:</strong></p>
<ul>
<li>Show your joke bot to family or friends</li>
<li>Think of other cool upgrades (maybe add puns?)</li>
<li>Be proud - you just did real programming!</li>
</ul>
<p style="margin-top: 30px; color: #7f8c8d;">
Digital Technologies / ICT<br>
Grade 5-8 | Beginner Programmers
</p>
</div>
<div class="button-container">
<button id="prevBtn12">Previous</button>
<button id="nextBtn12">Next</button>
</div>
</div>
</div>
<script>
// ==================== CONFIGURATION ====================
// Set total number of slides for this lesson
const totalSlides = 12; // UPDATE THIS NUMBER FOR EACH LESSON
// =======================================================
let currentSlide = 1;
// Update slide counter
function updateSlideCounter() {
document.getElementById('slide-counter').textContent = `Slide ${currentSlide} of ${totalSlides}`;
}
// Slide navigation
function showSlide(slideNumber) {
// Hide all slides
for (let i = 1; i <= totalSlides; i++) {
const slide = document.getElementById(`slide${i}`);
if (slide) {
slide.classList.remove('active');
}
}
// Show current slide
const currentSlideElement = document.getElementById(`slide${slideNumber}`);
if (currentSlideElement) {
currentSlideElement.classList.add('active');
currentSlide = slideNumber;
updateSlideCounter();
// Update button states
updateButtons();
}
}
function updateButtons() {
// Update previous button
const prevButtons = document.querySelectorAll('[id^="prevBtn"]');
prevButtons.forEach(btn => {
btn.disabled = currentSlide === 1;
});
// Update next button text on last slide
const nextButtons = document.querySelectorAll('[id^="nextBtn"]');
nextButtons.forEach(btn => {
if (currentSlide === totalSlides) {
btn.textContent = 'Complete Lesson';
} else {
btn.textContent = 'Next';
}
});
}
// Next button functionality
document.querySelectorAll('[id^="nextBtn"]').forEach(button => {
button.addEventListener('click', () => {
if (currentSlide < totalSlides) {
showSlide(currentSlide + 1);
} else {
// Last slide - completion message
alert('🎉 Lesson completed! You are now a Joke Bot Upgrader! Thank you for participating! 🎉');
}
});
});
// Previous button functionality
document.querySelectorAll('[id^="prevBtn"]').forEach(button => {
button.addEventListener('click', () => {
if (currentSlide > 1) {
showSlide(currentSlide - 1);
}
});
});
// Initialize the presentation
updateSlideCounter();
updateButtons();
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === ' ' || e.key === 'PageDown') {
if (currentSlide < totalSlides) {
showSlide(currentSlide + 1);
}
} else if (e.key === 'ArrowLeft' || e.key === 'PageUp') {
if (currentSlide > 1) {
showSlide(currentSlide - 1);
}
}
});
// Initialize to first slide
showSlide(1);
</script>
</body></html>

344
jokes_bot/v3.0/README.md Normal file
View File

@@ -0,0 +1,344 @@
Step-by-Step Complete Setup Guide
📋 Before We Start - Check Your Python Installation
1. Open PowerShell:
Press Windows + R
Type powershell
Press Enter
2. Check Python Version:
powershell
python --version
# Should show: Python 3.x.x
# If that doesn't work, try:
python3 --version
# Or on some systems:
py --version
📁 Create Your Project Folder
3. Navigate to Documents and Create Folder:
powershell
# Go to Documents folder
cd Documents
# Create a new folder using format: [firstname]_[surname initial]
# Example if your name is Ivan Lim:
mkdir ivan_l
# Go into your new folder
cd ivan_l
# Verify location
pwd
🎯 Get the Template Repository
4. Access the Template Repository:
Go to: https://gitea.techshare.cc/technolyceum/ai6-m3
Find the template named: [firstname]_[surname initial]_ai6-m3
Click on the template
Click the "Clone" button and copy the URL
5. Clone the Repository:
powershell
# Clone using the copied URL
git clone https://gitea.techshare.cc/technolyceum/ai6-m3/[firstname]_[surname initial]_ai6-m3.git
# Go into the cloned folder
cd [firstname]_[surname initial]_ai6-m3
🐍 Set Up Virtual Environment
6. Create and Activate Virtual Environment:
powershell
# Create virtual environment
python -m venv venv
# Activate it
.\venv\Scripts\Activate.ps1
# If you see a security warning:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.\venv\Scripts\Activate.ps1
✅ Success: You should see (venv) at the start of your command line!
📝 Type Your Bot Code
7. Open Python IDLE:
powershell
# Open IDLE from PowerShell
python -m idlelib
8. Create app.py in IDLE:
In IDLE: Click File → New File
TYPE the following code line by line:
python
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters
import sqlite3
TOKEN = "TEACHER_WILL_PROVIDE_THIS"
waiting = {}
async def start(update, context):
await update.message.reply_text("🤣 Joke Bot!\n/joke - get joke\n/addjoke - add joke")
async def joke(update, context):
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
joke = conn.execute("SELECT text FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
conn.close()
await update.message.reply_text(joke[0] if joke else "No jokes! /addjoke to add one")
async def addjoke(update, context):
waiting[update.effective_user.id] = True
await update.message.reply_text("📝 Type your joke:")
async def handle_text(update, context):
user_id = update.effective_user.id
if user_id in waiting:
conn = sqlite3.connect('jokes.db')
conn.execute('CREATE TABLE IF NOT EXISTS jokes (text TEXT, user TEXT, name TEXT)')
conn.execute("INSERT INTO jokes VALUES (?, ?, ?)",
(update.message.text, user_id, update.effective_user.first_name))
conn.commit()
conn.close()
del waiting[user_id]
await update.message.reply_text("✅ Saved!")
else:
await update.message.reply_text("Try /start")
app = Application.builder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("joke", joke))
app.add_handler(CommandHandler("addjoke", addjoke))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_text))
print("Bot running!")
app.run_polling()
Click File → Save As
Navigate to your project folder
Save as: app.py
Click Save
📦 Install Dependencies
9. Install Required Package:
powershell
# Make sure venv is activated
pip install python-telegram-bot
# Check installation
pip show python-telegram-bot
10. Create requirements.txt:
powershell
pip freeze > requirements.txt
Get-Content requirements.txt
🗄️ Explore SQLite Database Using GUI
11. First, Create the Database File:
powershell
# Run your bot once to create the database
python app.py
# You'll see an error about the token - that's OK
# Press Ctrl+C to stop it after 2 seconds
12. Install DB Browser for SQLite:
Go to: https://sqlitebrowser.org/dl/
Download the standard installer for Windows
Run the installer
Follow installation steps (just click Next)
Keep all default options
13. Open Your Database in DB Browser:
Open File Explorer (Windows key + E)
Navigate to your project folder:
text
C:\Users\YourName\Documents\[firstname]_[surname initial]\[firstname]_[surname initial]_ai6-m3
Find jokes.db file
Double-click jokes.db
It should open in DB Browser for SQLite
If it doesn't, open DB Browser first, then click "Open Database"
14. Explore Database in DB Browser:
Tab 1: Database Structure
See the jokes table
See the 3 columns: text, user, name
Check data types: TEXT, TEXT, TEXT
Tab 2: Browse Data
Click "Browse Data" tab
Select table: jokes
See any jokes already in the table
Table will be empty at first
15. Add Jokes Using DB Browser:
Click "Browse Data" tab
Click New Record button (or press Insert key)
Fill in the fields:
text: Your joke (e.g., "Why did the chicken cross the road?")
user: Your user ID number (e.g., 12345)
name: Your name (e.g., "Ivan")
Click Apply button to save
Add 2-3 jokes this way
16. Edit Jokes Using DB Browser:
Click on a joke in the table
Click inside any field
Change the text
Click Apply to save changes
17. Delete Jokes Using DB Browser:
Click on a joke row
Click Delete Record button (or press Delete key)
Click Apply to confirm
18. Run SQL Queries in DB Browser:
Click "Execute SQL" tab
Type SQL commands:
sql
-- See all jokes
SELECT * FROM jokes;
-- Count jokes
SELECT COUNT(*) FROM jokes;
-- See specific user's jokes
SELECT * FROM jokes WHERE name = 'Ivan';
-- Add a joke via SQL
INSERT INTO jokes VALUES ('What do you call a bear with no teeth? A gummy bear!', 999, 'SQLUser');
Click Execute (play button) to run
Click Write Changes to save
🔍 Quick Database Exploration Tasks
Task 1: View Empty Database
Open DB Browser
Open jokes.db
Check "Browse Data" tab
Table should be empty
Task 2: Add Jokes via GUI
Click "New Record"
Add 3 different jokes
Use different names for each
Save all with "Apply"
Task 3: View What You Added
Stay in "Browse Data" tab
Scroll to see all jokes
Notice each row has a rowid (automatic number)
Task 4: Edit a Joke
Click on any joke
Change the text
Click "Apply"
Task 5: Delete a Joke
Click on a joke row
Click "Delete Record"
Click "Apply"
Task 6: Use SQL Tab
Go to "Execute SQL" tab
Type: SELECT COUNT(*) FROM jokes;
Click "Execute"
See result in bottom pane
🎯 What You Should See in DB Browser
Database Structure:
Tables: 1 table (jokes)
Columns: text, user, name (all TEXT type)
Row count: Shows at bottom
After Adding Jokes:
Each row shows in table
Can sort by clicking column headers
Can filter using "Filter" box
File Size Growth:
Each joke adds to file size
File updates instantly when you click "Apply"
💡 Tips for DB Browser
Always click "Apply" after changes
"Write Changes" saves to disk
"Revert Changes" undoes unsaved changes
Use filter to find specific jokes
Export data if you want to backup
🔧 If Something Goes Wrong
Database won't open:
powershell
# Delete and recreate
Remove-Item jokes.db -ErrorAction SilentlyContinue
# Run bot to create fresh
python app.py
# Press Ctrl+C after error
# Now open in DB Browser
DB Browser not installed:
Go to https://sqlitebrowser.org/dl/
Download and install
Or use online SQLite viewer
Remember: DB Browser is the easiest way to see your database. No coding needed!
Note: Teacher will provide the Telegram bot token later. For now, practice adding and viewing jokes in DB Browser.

View File

@@ -0,0 +1,12 @@
import sqlite3
conn = sqlite3.connect('jokes.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS jokes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
joke TEXT NOT NULL,
contributor TEXT NOT NULL,
published TEXT NOT NULL
)''')
conn.commit()
print("✅ Database and table created successfully!")
conn.close()

BIN
jokes_bot/v3.0/jokes.db Normal file

Binary file not shown.

33
jokes_bot/v3.0/jokes.py Normal file
View File

@@ -0,0 +1,33 @@
# simple_joke_menu.py
import sqlite3
import random
db = sqlite3.connect('jokes.db')
while True:
print("\n1. Get joke")
print("2. Add joke")
print("3. Quit")
choice = input("Your choice: ")
if choice == "1":
joke = db.execute("SELECT joke FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
if joke:
print(f"\n🤣 {joke[0]}")
else:
print("No jokes yet!")
elif choice == "2":
new = input("Your joke: ")
if new:
name = input("Your name: ") or "Friend"
db.execute("INSERT INTO jokes (joke, contributor) VALUES (?, ?)", (new, name))
db.commit()
print("Saved!")
elif choice == "3":
break
db.close()
print("Bye!")

View File

@@ -0,0 +1 @@
python-telegram-bot

View File

@@ -0,0 +1,42 @@
-- jokes_database_fixed.sql
-- Create and populate jokes table with column name 'joke'
-- Step 1: Create the jokes table
CREATE TABLE IF NOT EXISTS jokes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
joke TEXT NOT NULL, -- CHANGED FROM 'joke_text' TO 'joke'
contributor TEXT,
published DATE DEFAULT CURRENT_DATE
);
-- Step 2: Insert 25 sample jokes
INSERT INTO jokes (joke, contributor, published) VALUES -- CHANGED COLUMN NAME HERE
('Why don''t scientists trust atoms? Because they make up everything!', 'Science Fan', '2024-01-15'),
('Why did the scarecrow win an award? He was outstanding in his field!', 'Farm Humor', '2024-01-16'),
('What do you call a fake noodle? An impasta!', 'Italian Chef', '2024-01-17'),
('Why did the bicycle fall over? Because it was two-tired!', 'Bike Enthusiast', '2024-01-18'),
('What do you call a bear with no teeth? A gummy bear!', 'Animal Lover', '2024-01-19'),
('Why don''t eggs tell jokes? They''d crack each other up!', 'Breakfast Club', '2024-01-20'),
('What do you call cheese that isn''t yours? Nacho cheese!', 'Cheese Master', '2024-01-21'),
('Why did the math book look so sad? Because it had too many problems!', 'Math Teacher', '2024-01-22'),
('What do you get when you cross a snowman with a vampire? Frostbite!', 'Winter Joker', '2024-01-23'),
('Why don''t skeletons fight each other? They don''t have the guts!', 'Bone Collector', '2024-01-24'),
('Why did the Python programmer quit? He didn''t get arrays!', 'Python Dev', '2024-01-25'),
('What do computers eat for a snack? Microchips!', 'Tech Guru', '2024-01-26'),
('Why do programmers prefer dark mode? Because light attracts bugs!', 'Code Master', '2024-01-27'),
('How many programmers does it take to change a light bulb? None, that''s a hardware issue!', 'IT Department', '2024-01-28'),
('Why did the database administrator leave his wife? She had one-to-many relationships!', 'SQL Expert', '2024-01-29'),
('What''s a programmer''s favorite hangout place? Foo Bar!', 'Coder Club', '2024-01-30'),
('Why don''t web developers go outside? They prefer the indoors network!', 'Web Dev', '2024-01-31'),
('What do you call a programmer from Finland? Nerdic!', 'International Joker', '2024-02-01'),
('Why did the developer go broke? Because he used up all his cache!', 'Finance Guy', '2024-02-02'),
('What''s the object-oriented way to become wealthy? Inheritance!', 'OOP Fan', '2024-02-03'),
('Why do Java developers wear glasses? Because they don''t C#!', 'Language Wars', '2024-02-04'),
('What''s a programmer''s favorite animal? The Python!', 'Snake Charmer', '2024-02-05'),
('Why did the computer go to the doctor? Because it had a virus!', 'IT Support', '2024-02-06'),
('What do you call a computer that sings? A Dell!', 'Musical Tech', '2024-02-07'),
('Why did the smartphone go to school? To improve its connection!', 'Mobile Guru', '2024-02-08');
-- Step 3: Verify the data was inserted
SELECT '✅ Database created successfully!' as message;
SELECT '📊 Total jokes inserted: ' || COUNT(*) as joke_count FROM jokes;