diff --git a/2 ksu scrape/ksu_scrape.py b/2 ksu scrape/ksu_scrape.py deleted file mode 100644 index 4d4ba23..0000000 --- a/2 ksu scrape/ksu_scrape.py +++ /dev/null @@ -1,58 +0,0 @@ -''' -TO use this code, you will first need to install the three packages being imported below using pip or a manual install method. -''' -from bs4 import BeautifulSoup -import requests -import csv -from datetime import datetime -page = "1" - -source = requests.get('https://www.kennesaw.edu/news/news-releases/index.php?&p='&page).text - -soup = BeautifulSoup(source, 'lxml') - -ksu_news_csv = open("ksu_news "+"{:%B %d, %Y}".format(datetime.now())+".csv","w") -csv_writer = csv.writer(ksu_news_csv) - -csv_writer.writerow(["Number","Title","Source","URL","Date"]) - -#print(soup.prettify()) - -#blog_post = soup.find('ul',class_='blog_listing') -blog_posts = soup.find('ul',class_='blog_listing') - -blog_posts = blog_posts.find_all('li') - -#print(type(blog_posts)) -#blog_posts = blog_posts.split("
  • ") -#print(blog_posts.prettify()) - -i = 1 -for blog_post in blog_posts: - - #print(i) - title = blog_post.a.text - title = title.split("(") - justtitle = title[0] - #print(title[0]) - if len(title)>1: - source = title[1].strip(")") - #print(source) - else: - source = "No Source" - #print(source) - - URL = blog_post.find('a')['href'] - #print(URL) - - date = blog_post.find("span").text - date = date.strip() - date = date.strip("–") - date = date.strip() - #print(date) - csv_writer.writerow([i,justtitle,source,URL,date]) - - i += 1 - print() - -ksu_news_csv.close() \ No newline at end of file diff --git a/2 ksu scrape/ksu_scrape_new.py b/2 ksu scrape/ksu_scrape_new.py index 147ecdb..a9caeb9 100644 --- a/2 ksu scrape/ksu_scrape_new.py +++ b/2 ksu scrape/ksu_scrape_new.py @@ -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 diff --git a/4 DB in Python/SQLite Demo/newdb.py b/4 DB in Python/SQLite Demo/newdb.py index eba20ab..0019790 100644 --- a/4 DB in Python/SQLite Demo/newdb.py +++ b/4 DB in Python/SQLite Demo/newdb.py @@ -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) \ No newline at end of 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() \ No newline at end of file diff --git a/4 DB in Python/SQLite Demomyinventory.db b/4 DB in Python/SQLite Demomyinventory.db deleted file mode 100644 index e69de29..0000000 diff --git a/6 Web Page with Flask/basic page/script1.py b/6 Web Page with Flask/basic page/script1.py index 0966353..6171753 100644 --- a/6 Web Page with Flask/basic page/script1.py +++ b/6 Web Page with Flask/basic page/script1.py @@ -1,5 +1,15 @@ +''' +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'] @@ -7,9 +17,9 @@ def greet(): #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/')