Skip to content

Commit

Permalink
Tidying up the demo projects and adding clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
dominict committed May 10, 2023
1 parent b3e2460 commit cedba42
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 63 deletions.
58 changes: 0 additions & 58 deletions 2 ksu scrape/ksu_scrape.py

This file was deleted.

3 changes: 2 additions & 1 deletion 2 ksu scrape/ksu_scrape_new.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'''
TO use this code, you will first need to install the three packages being imported below using pip or a manual install method.
To use this code, you will first need to install the three packages being imported below using pip or a manual install method.
This code was updated in August 2021 to use the new KSU news feed design.
'''
from bs4 import BeautifulSoup
import requests
Expand Down
25 changes: 23 additions & 2 deletions 4 DB in Python/SQLite Demo/newdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
'''
This code is a demo of how to create a database with a schema structure in Python using SQL Lite.
For more information, see: https://datatofish.com/create-database-python-using-sqlite3/
'''
import sqlite3

#we can name the file antyhing we want, but it is common to use .db
db_file = "new.db"

connection = sqlite3.connect(db_file)
#the connection is the database file itself represented in python
connection = sqlite3.connect(db_file)

#the cursor is the object that will allow us to execute SQL commands
cursor = connection.cursor()

#execute runs the SQL command but does not save it, the results are just in memory for now
cursor.execute('''
CREATE TABLE IF NOT EXISTS products
([product_id] INTEGER PRIMARY KEY, [product_name] TEXT)
''')

cursor.execute('''
CREATE TABLE IF NOT EXISTS prices
([product_id] INTEGER PRIMARY KEY, [price] INTEGER)
''')
#commit is when we actually save the changes we made to the database
connection.commit()
Empty file.
14 changes: 12 additions & 2 deletions 6 Web Page with Flask/basic page/script1.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
'''
This is a basic web page running with Flask.
'''

from flask import Flask, render_template, request
#This is the Flask object, we are creating an instance of the Flask class and storing it in the variable app
#__name__ is a special variable in Python that is the name of the module, which is this file's name without the .py extension
app=Flask(__name__)

#This is a decorator, it is a function that takes a function as a parameter!
#A decorator is a function that wraps another function
#This decorator is saying that when someone goes to the URL /greet, run the greet function
@app.route('/greet', methods=['POST'])
def greet():
inputName = request.form['myName']
ip = request.remote_addr
#write data to file or to DB
inputName = inputName.upper()+" hi! Visiting from " + str(ip)
return render_template("home.html",myName=inputName)

@app.route('/')
def home():

def home():
return render_template("home.html",myName="Type your name in the box and click submit!")

@app.route('/about/')
Expand Down

0 comments on commit cedba42

Please sign in to comment.