Skip to content

Commit cedba42

Browse files
committed
Tidying up the demo projects and adding clarity
1 parent b3e2460 commit cedba42

File tree

5 files changed

+37
-63
lines changed

5 files changed

+37
-63
lines changed

2 ksu scrape/ksu_scrape.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

2 ksu scrape/ksu_scrape_new.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'''
2-
TO use this code, you will first need to install the three packages being imported below using pip or a manual install method.
2+
To use this code, you will first need to install the three packages being imported below using pip or a manual install method.
3+
This code was updated in August 2021 to use the new KSU news feed design.
34
'''
45
from bs4 import BeautifulSoup
56
import requests
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
'''
2+
This code is a demo of how to create a database with a schema structure in Python using SQL Lite.
3+
For more information, see: https://datatofish.com/create-database-python-using-sqlite3/
4+
'''
15
import sqlite3
2-
6+
#we can name the file antyhing we want, but it is common to use .db
37
db_file = "new.db"
48

5-
connection = sqlite3.connect(db_file)
9+
#the connection is the database file itself represented in python
10+
connection = sqlite3.connect(db_file)
11+
12+
#the cursor is the object that will allow us to execute SQL commands
13+
cursor = connection.cursor()
14+
15+
#execute runs the SQL command but does not save it, the results are just in memory for now
16+
cursor.execute('''
17+
CREATE TABLE IF NOT EXISTS products
18+
([product_id] INTEGER PRIMARY KEY, [product_name] TEXT)
19+
''')
20+
21+
cursor.execute('''
22+
CREATE TABLE IF NOT EXISTS prices
23+
([product_id] INTEGER PRIMARY KEY, [price] INTEGER)
24+
''')
25+
#commit is when we actually save the changes we made to the database
26+
connection.commit()

4 DB in Python/SQLite Demomyinventory.db

Whitespace-only changes.

6 Web Page with Flask/basic page/script1.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
'''
2+
This is a basic web page running with Flask.
3+
'''
4+
15
from flask import Flask, render_template, request
6+
#This is the Flask object, we are creating an instance of the Flask class and storing it in the variable app
7+
#__name__ is a special variable in Python that is the name of the module, which is this file's name without the .py extension
28
app=Flask(__name__)
9+
10+
#This is a decorator, it is a function that takes a function as a parameter!
11+
#A decorator is a function that wraps another function
12+
#This decorator is saying that when someone goes to the URL /greet, run the greet function
313
@app.route('/greet', methods=['POST'])
414
def greet():
515
inputName = request.form['myName']
616
ip = request.remote_addr
717
#write data to file or to DB
818
inputName = inputName.upper()+" hi! Visiting from " + str(ip)
919
return render_template("home.html",myName=inputName)
20+
1021
@app.route('/')
11-
def home():
12-
22+
def home():
1323
return render_template("home.html",myName="Type your name in the box and click submit!")
1424

1525
@app.route('/about/')

0 commit comments

Comments
 (0)