Track your progress and earn rewards for active participation
-
-
-
-
-
-
✅
-
+2 You Came to Class!
-
Great job! Just by being in class, you get 2 points. Yay!
-
-
-
-
👂
-
+1 You Listened Quietly!
-
You didn't talk when the teacher was talking. Good listening!
-
-
-
-
✏️
-
+1 You Tried Your Work!
-
You didn't finish everything? That's OK! If you tried, you still get a point.
-
-
-
-
🎉
-
+1 You Finished ALL Your Work!
-
Wow! You did every single part — even the last task! You get a big high-five!
-
-
-
-
-
📊 Points Legend:
-
H = You were here! Points depend on what you did.
-
— = You were absent → 0 points
-
-
-
-
- Today's Goal:
-
Complete ALL steps of the joke bot upgrade to earn the full 5 points! 🎯
-
Follow along, ask questions, and help your classmates to maximize your learning!
-
-
-
-
-
-
Learning Outcomes
-
By the end of this session, you will be able to:
-
-
-
-
✓
-
-
1. Understand SQLite Database Basics
-
Explain what SQLite is and why it's perfect for small Python projects
-
-
-
-
-
✓
-
-
2. Design Database Tables
-
Create tables with proper columns, data types, and relationships
-
-
-
-
-
✓
-
-
3. Implement CRUD Operations
-
Write Python code to Create, Read, Update, and Delete database records
-
-
-
-
-
✓
-
-
4. Integrate Database with Telegram Bot
-
Connect your existing joke bot to a persistent database
-
-
-
-
-
✓
-
-
5. Add User Interaction Features
-
Implement joke submission, rating system, and statistics
-
-
-
-
-
✓
-
-
6. Use Virtual Environments
-
Set up and manage Python dependencies using venv
-
-
-
-
-
-
Why These Skills Matter:
-
-
💼
-
Industry Standard: Databases are used in 99% of real-world applications
-
-
-
-
🚀
-
Career Boost: Database skills are highly sought after by employers
-
-
-
-
🧠
-
Problem Solving: Learn to structure and manage complex data
-
-
-
-
📱
-
App Development: Build apps that remember user data between sessions
-
-
-
-
-
-
-
Why Databases Matter
-
Moving beyond simple lists to persistent storage
-
-
- The Problem with Lists:
-
Our current joke bot stores jokes in a Python list:
-
-JOKE_LIST = [
- "Why did the robot go to school? To recharge his brain! 🔋",
- "Knock knock!\nWho's there?\nLettuce!\nLettuce who?\nLettuce in!",
- "Why don't eggs tell jokes? They'd crack each other up! 🥚"
-]
-
Problems:
-
• Jokes are lost when bot restarts
-
• No way for users to add jokes
-
• Can't track ratings or popularity
-
• Hard to search or organize jokes
-
-
-
-
Database Advantages:
-
-
💾
-
Persistence: Data survives bot restarts and crashes
-
-
-
-
👥
-
User Contributions: Community can add content
-
-
-
-
📊
-
Analytics: Track what jokes are popular
-
-
-
-
🔍
-
Searchability: Find jokes by keywords or ratings
-
-
-
-
⚡
-
Scalability: Handle thousands of jokes efficiently
-
-
-
-
-
Real-World Examples:
-
Reddit: Database stores posts, votes, comments, user profiles
3. Run installer (CHECK "Add Python to PATH" option!)
-
4. Restart your computer, then try again
-
-
-
-
Verify Installation:
-
Open Python IDLE to test:
-
- python
- # You should see Python interactive shell:
- Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) ...
- Type "help", "copyright", "credits" or "license" for more information.
- >>> print("Hello, World!")
- Hello, World!
- >>> exit()
- # Type exit() to leave Python shell
-
-
-
-
-
-
-
Create Your Project Folder
-
Organize your files properly from the start
-
-
-
- 1
- Open PowerShell or Command Prompt:
-
Make sure you're not in the Python shell (should see C:\> or PS C:\>)
-
-
-
- 2
- Navigate to Desktop or Documents:
-
Let's create a folder on your Desktop for easy access:
-
-
-
-
- # Go to Desktop (Windows)
- cd Desktop
-
- # Create a new folder for your joke bot
- mkdir joke_bot_upgrade
-
- # Go into your new folder
- cd joke_bot_upgrade
-
- # Verify you're in the right place
- pwd
- # Should show: C:\Users\YourName\Desktop\joke_bot_upgrade
- # Or use 'dir' to see files (should be empty)
- dir
-
-
- # Check if venv folder was created
- dir
- # You should see a 'venv' folder in the list
-
-
-
- What Happened?
-
The venv command created a complete Python installation in the venv folder:
-
• Python interpreter copy
-
• pip (package installer)
-
• Standard library
-
• Empty site-packages for our libraries
-
-
-
-
Activate Virtual Environment:
-
Windows PowerShell:
-
- venv\Scripts\Activate.ps1
- # If you get an error about execution policy, run this first:
- Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- venv\Scripts\Activate.ps1
-
-
-
Windows Command Prompt:
-
- venv\Scripts\activate.bat
-
-
-
Mac/Linux Terminal:
-
- source venv/bin/activate
-
-
-
Success Indicator: You should see (venv) at the start of your command line!
-
-
-
-
-
-
Install Required Libraries
-
Get the Python packages we need for our upgraded bot
-
-
-
- 1
- First, activate your venv:
-
Make sure you see (venv) before the prompt
-
-
-
- 2
- Install python-telegram-bot:
-
This is the main library for creating Telegram bots
+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.")
+
+
+
+
5
+ Add the addjoke function
+
Right after your joke function, add this new function:
This function starts the process when users type /addjoke.
+
+
+
+
+
+
+
+
+
+
+
Step-by-Step Upgrade Guide - Part 3
+
+
+
6
+ Add the text handler function
+
Add this function after your addjoke function:
+
+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")
+
This function catches regular messages and saves jokes to the database.
+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 & ~filters.COMMAND, handle_text)) # ← ADD THIS LINE
+ print("✅ Bot is running! Press Ctrl+C to stop.")
+ app.run_polling()
+
+
+
+
+
+
+
+
+
+
+
SQLite Database Implementation
+
+
Your Code Should Now Include:
+
+
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")
+
+
+
+
+
+
+
+
+
+
Database Structure & Bot Commands
+
+
SQLite Database Schema:
+
-- 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');
+
+
Your Bot Now Has These Commands:
+
/start - Start the bot and see commands
+/joke - Get a random joke from database
+/addjoke - Add your own joke to database
+
+
How It Works:
+
+
When user types /joke → Bot gets random joke from database
+
When user types /addjoke → Bot waits for their joke
+
User types their joke → Bot saves it to SQLite database
+
Everyone can now access that joke with /joke
+
+
+
Important Note: The database file jokes.db will be created automatically the first time you run your bot.
+
+
+
+
+
+
+
+
+
+
Complete Implementation Code
+
+
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 & ~filters.COMMAND, handle_text))
+
+print("Joke Bot is running with SQLite database support!")
+app.run_polling()
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Lesson Slides Template.html b/Lesson Slides Template.html
new file mode 100644
index 0000000..c1e63da
--- /dev/null
+++ b/Lesson Slides Template.html
@@ -0,0 +1,749 @@
+
+
+
+
+
+ Lesson Slides Template
+
+
+
+
Slide 7 of 12
+
+
+
+
+
+
Upgrade Your Joke Bot!
+
AI6-M3: Database Integration
+
Digital Technologies / Information Communication Technologies
+
+
+
+
+
+
+
+
+
+
+
Classroom Guidelines
+
+
+
How Points Are Earned:
+
+
+2 Points - You attended class
+
+1 Point - You listened quietly during instruction
+
+1 Point - You attempted all assigned work
+
+1 Point - You completed all assigned work
+
+
+ Maximum: 5 points per class session
+
+
+
+
+
+
+
+
+
+
+
+
Learning Outcomes
+
By the end of this lesson, you will be able to:
+
+
+
+
Download a project from the internet (using Git clone)
+
Open and understand a Python program (starter_app.py)
+
Make simple changes to make the program better
+
Save your work to the internet (using Git push)
+
+
+
+
+
+
+
+
+
+
+
+
Why This Matters
+
+
+
+
Learn how real programmers work together
+
Understand how apps remember things (using databases)
+
Practice following step-by-step instructions
+
Create something that actually works!
+
These skills help with school projects and future jobs
+
+
+
Who uses these skills?
+
Every app on your phone (Instagram, TikTok, games) needs databases to remember your information!
+
+
+
+
+
+
+
+
+
+
+
Step 1: Find Our Project Online
+
Every project has a special web address (URL)
+
+
+
+ 💡 IMPORTANT: You MUST use this exact address:
+ https://gitea.techshare.cc/technolyceum/ai6-m3.git
+
+
+
Think of it like:
+
+
This is our project's "home" on the internet
+
Like downloading a game from the App Store
+
We're getting all the files we need to start
+
+
+
What's inside this address?
+
+# Inside this address you'll find:
+📁 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
+
+
+
+
+
+
+
+
+
+
+
+
Step 2: Download to Your Computer
+
Using "Git Clone" - like copying a folder from the internet
+
+
+
Open Command Prompt (Windows):
+
Press Windows Key, type cmd, press Enter
+
+
Go to Desktop:
+
+# Type this to go to your Desktop:
+cd Desktop
+
+# Check you're on Desktop:
+dir
+# You'll see your Desktop files
+
+
+
DOWNLOAD THE PROJECT:
+
+# Copy everything from the internet to your computer:
+git clone https://gitea.techshare.cc/technolyceum/ai6-m3.git
+
+# This creates a folder called "ai6-m3" on your Desktop
+
+
+
Check it worked:
+
+cd ai6-m3
+dir
+# You should see "starter_app.py" in the list!
+
+
+
+
+
+
+
+
+
+
+
+
Step 3: Open the Joke Bot Program
+
Let's see what we're working with!
+
+
+
Using VS Code (or any text editor):
+
+
+# Make sure you're in the right folder:
+cd Desktop\ai6-m3
+
+# Open the folder in VS Code:
+code .
+# Or open VS Code and use File → Open Folder
+
+python starter_app.py
+# It should tell you a random joke!
+
+
+
+
+
+
+
+
+
+
+
+
Step 4: Upgrade Your Joke Bot!
+
Make it remember jokes using a database
+
+
+
Your mission:
+
+
Add at least 5 new jokes to the program
+
Make it remember jokes even after you close it
+
Test that it works!
+
+
+
Simple changes to make:
+
+# In starter_app.py, find this part:
+jokes = [
+ "Why don't scientists trust atoms?...",
+ "Why did the chicken cross the road?...",
+ "What do you call fake spaghetti?..."
+]
+
+# ADD YOUR JOKES HERE!
+ "Your first joke here",
+ "Your second joke here",
+ "Keep adding more!"
+# Don't forget the comma at the end!
+
+
+
Database part (teacher will help):
+
+# We'll add code to save jokes to a file
+# So jokes don't disappear when you close the program
+
+
+
+
+
+
+
+
+
+
+
+
Step 5: Save Your Work Online
+
Using Git - like saving to the cloud
+
+
+
First, check what you changed:
+
+# Make sure you're in ai6-m3 folder:
+cd Desktop\ai6-m3
+
+# See what files you changed:
+git status
+# It will show "starter_app.py" in red or green
+
+
+
Step 1: Tell Git about your changes
+
+git add .
+# This means: "Save ALL my changes"
+# The dot (.) means "everything in this folder"
+
+
+
Step 2: Give your work a title
+
+git commit -m "Upgraded app for database implementation"
+# This is like putting your name on your work
+# "Upgraded app for database implementation" is your title
+
+
+
Step 3: Send it online
+
+git push
+# This sends your work back to the internet
+# Now everyone can see your upgraded joke bot!
+
+
+
+
+
+
+
+
+
+
+
+
What You Learned
+
+
+
In this lesson, you have learned how to:
+
+
+
Download a project from the internet using a special address
+
Open and run a Python program on your computer
+
Add new jokes to make the program better
+
Save your work and share it online using Git
+
+
+
Key Takeaways:
+
You now know the basic workflow of real programmers: Download → Modify → Save → Share. This is how all apps and games get made!
+
+
+ 🎉 CONGRATULATIONS!
+ You just completed your first programming project upgrade!
+
+
+
+
+
+
+
+
+
+
+
+
Questions & Discussion
+
+
+
Review what we covered:
+
+
What was the most fun part of upgrading the joke bot?
+
Did your jokes make your friends laugh?
+
What other things would you like a bot to remember?
+
Was Git push confusing? What part?
+
+
+
Common Issues:
+
+
Forgot commas between jokes? → Add them!
+
Git says "not a git repository"? → Make sure you're in ai6-m3 folder!
+
Python won't run? → Check for typos in your code
+
+
+
Need Additional Help?
+
Raise your hand! Ask your neighbor! The teacher is here to help!
+
+
+
+
+
+
+
+
+
+
+
+
Great Job! 🎉
+
+
Thank you for being awesome programmers today!
+
+
Your Joke Bot is now upgraded and saved online!
+
+
+ 🌟 YOU DID IT! 🌟
+ You downloaded code, made it better, and saved it for everyone to see!
+
+
+HTTPX is a fully featured HTTP client library for Python 3. It includes **an integrated
+command line client**, has support for both **HTTP/1.1 and HTTP/2**, and provides both **sync
+and async APIs**.
+
+---
+
+Install HTTPX using pip:
+
+```shell
+$ pip install httpx
+```
+
+Now, let's get started:
+
+```pycon
+>>> import httpx
+>>> r = httpx.get('https://www.example.org/')
+>>> r
+
+>>> r.status_code
+200
+>>> r.headers['content-type']
+'text/html; charset=UTF-8'
+>>> r.text
+'\n\n\nExample Domain...'
+```
+
+Or, using the command-line client.
+
+```shell
+$ pip install 'httpx[cli]' # The command line client is an optional dependency.
+```
+
+Which now allows us to use HTTPX directly from the command-line...
+
+
+
+
+
+Sending a request...
+
+
+
+
+
+## Features
+
+HTTPX builds on the well-established usability of `requests`, and gives you:
+
+* A broadly [requests-compatible API](https://www.python-httpx.org/compatibility/).
+* An integrated command-line client.
+* HTTP/1.1 [and HTTP/2 support](https://www.python-httpx.org/http2/).
+* Standard synchronous interface, but with [async support if you need it](https://www.python-httpx.org/async/).
+* Ability to make requests directly to [WSGI applications](https://www.python-httpx.org/advanced/#calling-into-python-web-apps) or [ASGI applications](https://www.python-httpx.org/async/#calling-into-python-web-apps).
+* Strict timeouts everywhere.
+* Fully type annotated.
+* 100% test coverage.
+
+Plus all the standard features of `requests`...
+
+* International Domains and URLs
+* Keep-Alive & Connection Pooling
+* Sessions with Cookie Persistence
+* Browser-style SSL Verification
+* Basic/Digest Authentication
+* Elegant Key/Value Cookies
+* Automatic Decompression
+* Automatic Content Decoding
+* Unicode Response Bodies
+* Multipart File Uploads
+* HTTP(S) Proxy Support
+* Connection Timeouts
+* Streaming Downloads
+* .netrc Support
+* Chunked Requests
+
+## Installation
+
+Install with pip:
+
+```shell
+$ pip install httpx
+```
+
+Or, to include the optional HTTP/2 support, use:
+
+```shell
+$ pip install httpx[http2]
+```
+
+HTTPX requires Python 3.7+.
+
+## Documentation
+
+Project documentation is available at [https://www.python-httpx.org/](https://www.python-httpx.org/).
+
+For a run-through of all the basics, head over to the [QuickStart](https://www.python-httpx.org/quickstart/).
+
+For more advanced topics, see the [Advanced Usage](https://www.python-httpx.org/advanced/) section, the [async support](https://www.python-httpx.org/async/) section, or the [HTTP/2](https://www.python-httpx.org/http2/) section.
+
+The [Developer Interface](https://www.python-httpx.org/api/) provides a comprehensive API reference.
+
+To find out about tools that integrate with HTTPX, see [Third Party Packages](https://www.python-httpx.org/third_party_packages/).
+
+## Contribute
+
+If you want to contribute with HTTPX check out the [Contributing Guide](https://www.python-httpx.org/contributing/) to learn how to start.
+
+## Dependencies
+
+The HTTPX project relies on these excellent libraries:
+
+* `httpcore` - The underlying transport implementation for `httpx`.
+ * `h11` - HTTP/1.1 support.
+* `certifi` - SSL certificates.
+* `idna` - Internationalized domain name support.
+* `sniffio` - Async library autodetection.
+
+As well as these optional installs:
+
+* `h2` - HTTP/2 support. *(Optional, with `httpx[http2]`)*
+* `socksio` - SOCKS proxy support. *(Optional, with `httpx[socks]`)*
+* `rich` - Rich terminal support. *(Optional, with `httpx[cli]`)*
+* `click` - Command line client support. *(Optional, with `httpx[cli]`)*
+* `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx[brotli]`)*
+
+A huge amount of credit is due to `requests` for the API layout that
+much of this work follows, as well as to `urllib3` for plenty of design
+inspiration around the lower-level networking details.
+
+---
+
+
HTTPX is BSD licensed code. Designed & crafted with care. — 🦋 —