Skip to content

Commit da7a41b

Browse files
committed
Updating with various little changes.
1 parent f25332f commit da7a41b

File tree

12 files changed

+145
-251
lines changed

12 files changed

+145
-251
lines changed

Diff for: .gitignore

+2-11
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105-
4 DB in Python/.DS_Store
106-
4 DB in Python/.DS_Store
107-
.vscode/settings.json
108-
4 DB in Python/.DS_Store
109-
.DS_Store
110-
.DS_Store
111-
.DS_Store
105+
# MacOS DS_Store
112106
.DS_Store
113-
.DS_Store
114-
.DS_Store
115-
.DS_Store
116-
4 DB in Python/.DS_Store
107+
.vscode/settings.json

Diff for: 1 gradetracker/GradeTracker.py

+51-30
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
11
'''
2-
grade tracking program - think through the goal up front- what is the task and design?
3-
needs to enable several basic functions for teachers
4-
needs to have login to protect the student data
2+
This is a grade tracking program - think through the goal up front- what is the task and design?
3+
needs to enable several basic functions for faculty members.
4+
This comment in triple quotes is called a docstring.
5+
It is text that explains what a code file (aka module) or function does.
6+
See https://www.geeksforgeeks.org/python-docstrings/
57
'''
6-
#import libraries first
8+
#import libraries (aka module) first
79
import statistics as s
810

911
#add constants next
10-
admins = {'Faculty1':'ABC123','Faculty2':'ABC123'}
12+
admins = {'Dominic':'Thomas','Faculty2':'ABC123','Dominic':'Thomas'}
1113

12-
#Like the admins above is a dictionary but of students. Dictionaries use curly brackets with colons to associate keys with values. In this case, each student's first name is a key. The values are lists of grades.
13-
#Lists are denoted with square brackets. Values are indexed within starting with 0 for the first one. Each value is separated by commas.
14+
# Like the admins above is a dictionary but of students.
15+
# Dictionaries use curly brackets with colons to associate keys with values.
16+
# In this case, each student's first name is a key. The values are lists of grades.
17+
# Lists are denoted with square brackets.
18+
# Values are indexed within starting with 0 for the first one.
19+
# Each value is separated by commas.
1420
students = {'Alex':[87,88,98],
1521
'Sally':[88,67,93],
1622
'Nboke':[90,88,78]}
1723

18-
#Now we define functions. Functions encapsulate logic into reusable recipes that can be executed whenever we need them by calling their name with parentheses.
19-
def enterGrades():
20-
nameToEnter = input('Student name: ')
21-
gradeToEnter = input('Grade: ')
22-
#This checks through the keys of the students dictionary to see if the name entered exactly matches any one in there.
23-
if nameToEnter in students:
24-
print('Adding grade for'+nameToEnter)
25-
students[nameToEnter].append(float(gradeToEnter)) #float will have a .0
26-
print(str(nameToEnter)+' now has these grades:')
27-
print(students[nameToEnter])
24+
# Now we define functions. Functions encapsulate logic into reusable recipes that can be
25+
# executed whenever we need them by calling their name with parentheses.
26+
def enter_grades():
27+
'''
28+
Function to input a grade for a given student.
29+
'''
30+
name_to_enter = input('Student name: ')
31+
grade_to_enter = input('Grade: ')
32+
# This checks through the keys of the students dictionary to see if the name entered
33+
# exactly matches any one in there.
34+
if name_to_enter in students:
35+
print('Adding grade for'+name_to_enter)
36+
students[name_to_enter].append(float(grade_to_enter)) #float will have a .0
37+
print(str(name_to_enter)+' now has these grades:')
38+
print(students[name_to_enter])
2839
else:
2940
print('Student not found. Please check your spelling or go back and add if new.')
3041

31-
def removeStudent():
32-
nameToRemove = input('Who do you want to remove? ')
33-
if nameToRemove in students:
34-
print('Removing '+nameToRemove)
35-
del students[nameToRemove]
42+
def remove_student():
43+
'''
44+
Function to remove a specific student.
45+
'''
46+
name_to_remove = input('Who do you want to remove? ')
47+
if name_to_remove in students:
48+
print('Removing '+name_to_remove)
49+
del students[name_to_remove]
3650
print(students)
3751
else:
3852
print('Student not found.')
3953

40-
def averageStudents():
54+
def average_students():
55+
'''
56+
Function to average all students' grades.
57+
'''
4158
for student in students:
4259
grades = students[student]
43-
average = s.mean(grades) #notice the s? we imported the statistuics module as s. Thus, we are using a fucntion called "mean()" from the statistics module.
60+
average = s.mean(grades) #notice the s? we imported the statistics module as s.
61+
#Thus, we are using a fucntion called "mean()" from the statistics module.
4462
print(student,' average ',average)
4563

4664
def main():
65+
'''
66+
Function to show user main menu and process option selections.
67+
'''
4768
print("User: " + login)
48-
#Here we present our main menu options once a person logs in successfully.
69+
# Here we present our main menu options once a person logs in successfully.
4970
print("""
5071
Welcome to the Grade Tracker
5172
@@ -59,20 +80,20 @@ def main():
5980
#Here we process their choice of what they want to do.
6081
if action == '1':
6182
#print('1 selected')
62-
enterGrades()
83+
enter_grades()
6384
elif action == '2':
6485
#print('2 selected')
65-
removeStudent()
86+
remove_student()
6687
elif action == '3':
6788
#print('3 selected')
68-
averageStudents()
89+
average_students()
6990
elif action == '4':
7091
#print('4 selected')
7192
exit()
7293
else:
7394
print('Valid option not selected.') #need to cause it to reprompt
7495

75-
login = input('User: ')
96+
login = input('Faculty account name: ')
7697

7798
if login in admins:
7899
password = input('Password: ')
@@ -84,4 +105,4 @@ def main():
84105
else:
85106
print('Invalid password.')
86107
else:
87-
print('Invalid user.')
108+
print('Invalid user.')

Diff for: 2 ksu scrape/cms_scrape.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
source = requests.get('http://coreyms.com').text
99
soup = BeautifulSoup(source, 'lxml')
1010
#print(soup.prettify())
11-
#article = soup.find('article')
11+
article = soup.find('article')
12+
#print(article)
1213
#method to get all
1314
articles = soup.find_all('article')
1415
#print(article.prettify())
1516
for article in articles:
1617
headline = article.h2.a.text
1718
print(headline)
1819
summary = article.find('div', class_='entry-content').p.text
19-
print(summary)
20+
#print(summary)
2021
#This try/except block handles the situation when a video is
2122
try:
2223
vid_src = article.find('iframe', class_='youtube-player')['src']
@@ -28,5 +29,5 @@
2829
yt_link = f'https://youtube.com/watch?v={vid_id}'
2930
except Exception as e:
3031
yt_link = None
31-
print(yt_link)
32-
print()
32+
#print(yt_link)
33+
#print()

Diff for: 2 ksu scrape/ksu_scrape.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import requests
66
import csv
77
from datetime import datetime
8+
page = "1"
89

9-
10-
source = requests.get('https://news.kennesaw.edu/news-releases/?&categories=news%20releases&year=2021').text
10+
source = requests.get('https://www.kennesaw.edu/news/news-releases/index.php?&p='&page).text
1111

1212
soup = BeautifulSoup(source, 'lxml')
1313

Diff for: 2 ksu scrape/ksu_scrape_new.py

+49-40
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,57 @@
66
import csv
77
from datetime import datetime
88

9-
#grab the basic content from a web page
10-
source = requests.get('https://www.kennesaw.edu/news/news-releases/index.php?&p=1').text
11-
#using the lxml parser to process the web page text content
12-
soup = BeautifulSoup(source, 'lxml')
13-
#create a csv file in "w" write mode so we can add content to it.
14-
ksu_news_csv = open("ksu_news "+"{:%B %d, %Y}".format(datetime.now())+".csv","w")
15-
csv_writer = csv.writer(ksu_news_csv)
16-
#write the header row into our csv file
17-
csv_writer.writerow(["Number","Title","URL","Date"])
18-
#show the content of the website we retrieved so that we can find the unique tags around the content we want
19-
#print(soup.prettify())
20-
21-
#blog_post = soup.find('ul',class_='two_col has_gap is_30')
22-
#blog_post = soup.find('div',{"id":"main"})
23-
blog_list = soup.find('ul',class_='blog_listing')
24-
#print(blog_list.prettify())
25-
blog_posts = blog_list.find_all('li')
26-
27-
#print(type(blog_posts))
28-
#blog_posts = blog_posts.split("<li>")
9+
def scrape_ksu(ksu_url,page):
10+
'''
11+
This function is made for scraping the KSU news feed as of its redesign in August 2022.
12+
'''
13+
#grab the basic content from a web page
14+
source = requests.get(ksu_url+page).text
15+
#using the lxml parser to process the web page text content
16+
soup = BeautifulSoup(source, 'lxml')
17+
#create a csv file in "w" write mode so we can add content to it.
18+
ksu_news_csv = open("ksu_news_"+"{:%m_%d_%Y}".format(datetime.now())+"_p"+page+".csv","w")
19+
csv_writer = csv.writer(ksu_news_csv)
20+
#write the header row into our csv file
21+
csv_writer.writerow(["Number","Title","URL","Date"])
22+
#show the content of the website we retrieved so that we can find the unique tags around the content we want
23+
#print(soup.prettify())
2924

30-
i = 1
31-
for blog_post in blog_posts:
32-
33-
#print(i)
34-
title = blog_post.h3.text
35-
#print(title)
36-
37-
date = blog_post.p.text
38-
date = date.strip()
39-
date = date.strip('"')
40-
date = date.strip()
41-
#print(date)
42-
43-
44-
URL = blog_post.find('a')['href']
45-
#print(URL)
25+
#blog_post = soup.find('ul',class_='two_col has_gap is_30')
26+
#blog_post = soup.find('div',{"id":"main"})
27+
blog_list = soup.find('ul',class_='blog_listing')
28+
#print(blog_list.prettify())
29+
blog_posts = blog_list.find_all('li')
4630

47-
48-
csv_writer.writerow([i,title,URL,date])
31+
#print(type(blog_posts))
32+
#blog_posts = blog_posts.split("<li>")
4933

50-
i += 1
34+
i = 1
35+
for blog_post in blog_posts:
36+
37+
#print(i)
38+
title = blog_post.h3.text
39+
#print(title)
5140

41+
date = blog_post.p.text
42+
date = date.strip()
43+
date = date.strip('"')
44+
date = date.strip()
45+
#print(date)
46+
47+
48+
URL = blog_post.find('a')['href']
49+
#print(URL)
5250

53-
ksu_news_csv.close()
51+
52+
csv_writer.writerow([i,title,URL,date])
53+
54+
i += 1
55+
56+
57+
ksu_news_csv.close()
58+
59+
i = 1
60+
while i < 10:
61+
scrape_ksu('https://www.kennesaw.edu/news/news-releases/index.php?&p=',str(i))
62+
i += 1

Diff for: 4 DB in Python/MySQL Demo/DBconnectgrades.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#root password is something you set when you install mysql on your system
55
#the default may be blank; I used python123 for testing
66
#BE SURE to match your password to the password you set when installing MySQL. If in doubt, try a blank password
7-
dbconn = my.connect (host='127.0.0.1',port=33067,user='root', password='', db='students')
7+
#dbconn = my.connect (host='127.0.0.1',port=33067,user='root', password='', db='students')
8+
dbconn = my.connect (host='127.0.0.1',port=3306,user='root', password='', db='students')
89

910
#print(dbconn) #This is a testing stub to make sure the connection worked. Uncomment it to use it.
1011
cursor = dbconn.cursor()

Diff for: 4 DB in Python/SQLite Demo/vinventory.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#if you code is not connecting to the DB, uncomment the next three lines and read the comments. Also, you may need \ instead of / before the DB file name in windows
1111
import os
1212
path_root = os.path.dirname(os.path.abspath(__file__)) #grab the file system path to the current script file
13-
print("Here is the PATH_ROOT",path_root)
13+
#print("Here is the PATH_ROOT",path_root)
1414
database_file_path = str(path_root)+"/myinventory.db" #construct the path to the database file (only necessary if the current working directory is not the same as the folder where this Python file is located.)
15+
print("HERE is the database file:", database_file_path)
1516
#if you uncomment the three lines above, be sure to comment out this next line
1617
#database_file_path = "myinventory.db"
1718
def create_connection(db_file):

Diff for: 6 Web Page with Flask/basic page/static/css/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ header h1.logo:hover {
4141

4242
div.home {
4343
padding: 10px 0 30px 0;
44-
background-color: rgb(253, 239, 11);
44+
background-color: rgb(21, 252, 11);
4545
-webkit-border-radius: 6px;
4646
-moz-border-radius: 6px;
4747
border-radius: 6px;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def calculate_tx(item,price,tax_rate):
3+
'''Function to calculate item tax.
4+
price needs to be float
5+
tax_rate needs to be float
6+
returns the item capitalized and the final price'''
7+
if item == "alcohol":
8+
tax_rate += .25
9+
elif item == "cigarette":
10+
tax_rate += .35
11+
12+
final_price = price + (price * tax_rate)
13+
return item.capitalize(), final_price
14+
15+
16+
purchase = "frog"
17+
item, price = calculate_tx(purchase,3.99,.08)
18+
print("Here is the result:",item, round(price,2))
19+
purchase = "alcohol"
20+
item, price = calculate_tx(purchase,3.99,.08)
21+
print("Here is the result:",item, round(price,2))
22+
purchase = "cigarette"
23+
item, price = calculate_tx(purchase,3.99,.08)
24+
print("Here is the result:",item, round(price,2))

Diff for: Python Absolute Beginner/req_code_file_ex.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
print("Hello World!")
2+
3+
message="hello programmer!"
4+
5+
print(message)

Diff for: Python Fundamentals/bad_curl.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#guess what? this will not work in a regular python code file. So, how to fix?
2+
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem1.txt -o poem1.doc

0 commit comments

Comments
 (0)