0% found this document useful (0 votes)
10 views

Lab 11

The document contains Python code to define functions for interacting with an SQLite database to manage employee records. It defines functions to create a table, add, retrieve, update and delete employee records.

Uploaded by

strikec71
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lab 11

The document contains Python code to define functions for interacting with an SQLite database to manage employee records. It defines functions to create a table, add, retrieve, update and delete employee records.

Uploaded by

strikec71
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import sqlite3

# 1
# def create_employee_table():
# conn = sqlite3.connect('employees.db')
# cursor = conn.cursor()
#
# create_table_sql = '''
# CREATE TABLE IF NOT EXISTS employees (
# id INTEGER PRIMARY KEY,
# name TEXT NOT NULL,
# age INTEGER,
# position TEXT
# );
# '''
#
# cursor.execute(create_table_sql)
# conn.commit()
# conn.close()

# 2
# def add_employee(name, age, position):
# conn = sqlite3.connect('employees.db')
# cursor = conn.cursor()
#
# insert_sql = '''
# INSERT INTO employees (name, age, position)
# VALUES (?, ?, ?);
# '''
#
# cursor.execute(insert_sql, (name, age, position))
# conn.commit()
# conn.close()

# 3
# def get_all_employees():
# conn = sqlite3.connect('employees.db')
# cursor = conn.cursor()
#
# query = '''
# SELECT * FROM employees;
# '''
#
# cursor.execute(query)
# rows = cursor.fetchall()
#
# conn.close()
# return rows

# 4
# def update_employee_position(employee_id, new_position):
# conn = sqlite3.connect('employees.db')
# cursor = conn.cursor()
#
# update_sql = '''
# UPDATE employees
# SET position = ?
# WHERE id = ?;
# '''
#
# cursor.execute(update_sql, (new_position, employee_id))
# conn.commit()
# conn.close()

# 5
# def delete_employee(employee_id):
# conn = sqlite3.connect('employees.db')
# cursor = conn.cursor()
#
# delete_sql = '''
# DELETE FROM employees
# WHERE id = ?;
# '''
#
# cursor.execute(delete_sql, (employee_id,))
# conn.commit()
# conn.close()

# def usage:
# create_employee_table()
# add_employee("John Doe", 30, "Manager")
# update_employee_position(1, "Senior Manager")
# delete_employee(1)
#
# employees = get_all_employees()
# for employee in employees:
# print(employee)

# discord-bot-raw-version
'''
import discord
from discord.ext import commands

bot = commands.Bot(command_prefix=".", help_command = None, intents =


discord.Intents.all())

censored_words = ["nigga"]
@bot.event
async def on_ready():
print(f"{bot.user} is ready to work!")

@bot.event
async def on_member_join(member):
role = await discord.utils.get(member.guild.roles, id=1231637764424863764)
channel = member.guild.system_channel

embed = discord.Embed(
title="New member!",
description=f"{member.mention}#{member.discriminator} has joined the server!",
color = 0xffffff)

await member.add_roles(role)
await channel.send(embed=embed)

@bot.event
async def on_message(message):
await bot.process_commands(message)

for content in message.content.split():


for censored_word in censored_words:
if content.lower() == censored_word:
await message.delete()
await message.channel.send(f"{message.author.menton} nuh uh, that's a bad
word!")

@bot.command()
@commands.has_permissions(kick_members=True, administrator = True)
async def kick(ctx, member: discord.Member, *, reason = "you've been kicked!"):
await ctx.channel.purge(limit = 1)
await ctx.send(f'{member.mention} was kicked!')
await member.kick(reason=reason)

@bot.command()
@commands.has_permissions(ban_members=True , administrator = True)
async def ban(ctx, member: discord.Member, *, reason="you've been banned!"):
await ctx.channel.purge(limit = 1)
await ctx.send(f'{member.mention} has been banned!')
await member.ban(reason=reason)

bot.run("MTIzMTYwNzY1ODMxOTA1MjkwMA.GXi4dV.BXYUqj_hNVSVHU1SQGgqKAsi_0KcRPGZAtJ6PI")
'''

You might also like