Preparing git repo for final project

This commit is contained in:
2023-07-09 11:19:26 +02:00
parent 6a38966eef
commit 63d06d6b35
67 changed files with 1587 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import os
import sys
def main():
try:
file_name = sys.argv[1]
except IndexError:
print("Provide a file name from command line!")
sys.exit(1)
if len(sys.argv) > 2:
print("Too many command-line arguments")
sys.exit(1)
if not os.path.isfile(file_name): # Or try opening and catch FileNotFoundError
print(f"The file `{file_name}` does not exist!")
sys.exit(1)
if not file_name.endswith('.py'):
print(f"The file `{file_name}` is not a python script (does not end with the proper suffix)!")
sys.exit(1)
line_count = count_lines(file_name)
print(line_count)
def count_lines(file_name: str) -> int:
line_count = 0
with open(file_name, 'r') as file_object:
for line in file_object:
if len(line.strip()) > 0 and not line.strip().startswith('#'):
line_count += 1
return line_count
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,13 @@
from lines import count_lines
def main():
test_count_lines()
def test_count_lines():
assert count_lines('lines.py') == 28
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,39 @@
import csv
import os
import sys
import tabulate
def main():
try:
file_name = sys.argv[1]
except IndexError:
print("Too few command-line arguments")
sys.exit(1)
if len(sys.argv) > 2:
print("Too many command-line arguments")
sys.exit(1)
if not os.path.isfile(file_name): # Or try opening and catch FileNotFoundError
print(f"File does not exist")
sys.exit(1)
if not file_name.endswith('.csv'):
print(f"Not a CSV file")
sys.exit(1)
grid = get_grid_from_csv(file_name)
print(grid)
def get_grid_from_csv(file_name: str) -> str:
headers = None
table = []
with open(file_name, 'r') as file_object:
reader = csv.DictReader(file_object)
for row in reader:
if headers is None:
headers = list(row.keys())
table.append(tuple(row[field] for field in row))
return tabulate.tabulate(table, headers, tablefmt="grid")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,6 @@
Regular Pizza,Small,Large
Cheese,$13.50,$18.95
1 topping,$14.75,$20.95
2 toppings,$15.95,$22.95
3 toppings,$16.95,$24.95
Special,$18.50,$26.95
1 Regular Pizza Small Large
2 Cheese $13.50 $18.95
3 1 topping $14.75 $20.95
4 2 toppings $15.95 $22.95
5 3 toppings $16.95 $24.95
6 Special $18.50 $26.95

View File

@@ -0,0 +1,54 @@
first,last,house
Hannah,Abbott,Hufflepuff
Katie,Bell,Gryffindor
Susan,Bones,Hufflepuff
Terry,Boot,Ravenclaw
Lavender,Brown,Gryffindor
Millicent,Bulstrode,Slytherin
Cho,Chang,Ravenclaw
Penelope,Clearwater,Ravenclaw
Vincent,Crabbe,Slytherin
Colin,Creevey,Gryffindor
Dennis,Creevey,Gryffindor
Cedric,Diggory,Hufflepuff
Marietta,Edgecombe,Ravenclaw
Justin,Finch-Fletchley,Hufflepuff
Seamus,Finnigan,Gryffindor
Anthony,Goldstein,Ravenclaw
Gregory,Goyle,Slytherin
Hermione,Granger,Gryffindor
Angelina,Johnson,Gryffindor
Lee,Jordan,Gryffindor
Neville,Longbottom,Gryffindor
Luna,Lovegood,Ravenclaw
Remus,Lupin,Gryffindor
Draco,Malfoy,Slytherin
Scorpius,Malfoy,Slytherin
Ernie,Macmillan,Hufflepuff
Minerva,McGonagall,Gryffindor
Eloise,Midgen,Gryffindor
Cormac,McLaggen,Gryffindor
Graham,Montague,Slytherin
Theodore,Nott,Slytherin
Pansy,Parkinson,Slytherin
Padma,Patil,Gryffindor
Parvati,Patil,Gryffindor
Harry,Potter,Gryffindor
Tom,Riddle,Slytherin
Demelza,Robins,Gryffindor
Newt,Scamander,Hufflepuff
Horace,Slughorn,Slytherin
Zacharias,Smith,Hufflepuff
Severus,Snape,Slytherin
Alicia,Spinnet,Gryffindor
Pomona,Sprout,Hufflepuff
Dean,Thomas,Gryffindor
Romilda,Vane,Gryffindor
Myrtle,Warren,Ravenclaw
Fred,Weasley,Gryffindor
George,Weasley,Gryffindor
Ginny,Weasley,Gryffindor
Percy,Weasley,Gryffindor
Ron,Weasley,Gryffindor
Oliver,Wood,Gryffindor
Blaise,Zabini,Slytherin
1 first last house
2 Hannah Abbott Hufflepuff
3 Katie Bell Gryffindor
4 Susan Bones Hufflepuff
5 Terry Boot Ravenclaw
6 Lavender Brown Gryffindor
7 Millicent Bulstrode Slytherin
8 Cho Chang Ravenclaw
9 Penelope Clearwater Ravenclaw
10 Vincent Crabbe Slytherin
11 Colin Creevey Gryffindor
12 Dennis Creevey Gryffindor
13 Cedric Diggory Hufflepuff
14 Marietta Edgecombe Ravenclaw
15 Justin Finch-Fletchley Hufflepuff
16 Seamus Finnigan Gryffindor
17 Anthony Goldstein Ravenclaw
18 Gregory Goyle Slytherin
19 Hermione Granger Gryffindor
20 Angelina Johnson Gryffindor
21 Lee Jordan Gryffindor
22 Neville Longbottom Gryffindor
23 Luna Lovegood Ravenclaw
24 Remus Lupin Gryffindor
25 Draco Malfoy Slytherin
26 Scorpius Malfoy Slytherin
27 Ernie Macmillan Hufflepuff
28 Minerva McGonagall Gryffindor
29 Eloise Midgen Gryffindor
30 Cormac McLaggen Gryffindor
31 Graham Montague Slytherin
32 Theodore Nott Slytherin
33 Pansy Parkinson Slytherin
34 Padma Patil Gryffindor
35 Parvati Patil Gryffindor
36 Harry Potter Gryffindor
37 Tom Riddle Slytherin
38 Demelza Robins Gryffindor
39 Newt Scamander Hufflepuff
40 Horace Slughorn Slytherin
41 Zacharias Smith Hufflepuff
42 Severus Snape Slytherin
43 Alicia Spinnet Gryffindor
44 Pomona Sprout Hufflepuff
45 Dean Thomas Gryffindor
46 Romilda Vane Gryffindor
47 Myrtle Warren Ravenclaw
48 Fred Weasley Gryffindor
49 George Weasley Gryffindor
50 Ginny Weasley Gryffindor
51 Percy Weasley Gryffindor
52 Ron Weasley Gryffindor
53 Oliver Wood Gryffindor
54 Blaise Zabini Slytherin

View File

@@ -0,0 +1,54 @@
name,house
"Abbott, Hannah",Hufflepuff
"Bell, Katie",Gryffindor
"Bones, Susan",Hufflepuff
"Boot, Terry",Ravenclaw
"Brown, Lavender",Gryffindor
"Bulstrode, Millicent",Slytherin
"Chang, Cho",Ravenclaw
"Clearwater, Penelope",Ravenclaw
"Crabbe, Vincent",Slytherin
"Creevey, Colin",Gryffindor
"Creevey, Dennis",Gryffindor
"Diggory, Cedric",Hufflepuff
"Edgecombe, Marietta",Ravenclaw
"Finch-Fletchley, Justin",Hufflepuff
"Finnigan, Seamus",Gryffindor
"Goldstein, Anthony",Ravenclaw
"Goyle, Gregory",Slytherin
"Granger, Hermione",Gryffindor
"Johnson, Angelina",Gryffindor
"Jordan, Lee",Gryffindor
"Longbottom, Neville",Gryffindor
"Lovegood, Luna",Ravenclaw
"Lupin, Remus",Gryffindor
"Malfoy, Draco",Slytherin
"Malfoy, Scorpius",Slytherin
"Macmillan, Ernie",Hufflepuff
"McGonagall, Minerva",Gryffindor
"Midgen, Eloise",Gryffindor
"McLaggen, Cormac",Gryffindor
"Montague, Graham",Slytherin
"Nott, Theodore",Slytherin
"Parkinson, Pansy",Slytherin
"Patil, Padma",Gryffindor
"Patil, Parvati",Gryffindor
"Potter, Harry",Gryffindor
"Riddle, Tom",Slytherin
"Robins, Demelza",Gryffindor
"Scamander, Newt",Hufflepuff
"Slughorn, Horace",Slytherin
"Smith, Zacharias",Hufflepuff
"Snape, Severus",Slytherin
"Spinnet, Alicia",Gryffindor
"Sprout, Pomona",Hufflepuff
"Thomas, Dean",Gryffindor
"Vane, Romilda",Gryffindor
"Warren, Myrtle",Ravenclaw
"Weasley, Fred",Gryffindor
"Weasley, George",Gryffindor
"Weasley, Ginny",Gryffindor
"Weasley, Percy",Gryffindor
"Weasley, Ron",Gryffindor
"Wood, Oliver",Gryffindor
"Zabini, Blaise",Slytherin
1 name house
2 Abbott, Hannah Hufflepuff
3 Bell, Katie Gryffindor
4 Bones, Susan Hufflepuff
5 Boot, Terry Ravenclaw
6 Brown, Lavender Gryffindor
7 Bulstrode, Millicent Slytherin
8 Chang, Cho Ravenclaw
9 Clearwater, Penelope Ravenclaw
10 Crabbe, Vincent Slytherin
11 Creevey, Colin Gryffindor
12 Creevey, Dennis Gryffindor
13 Diggory, Cedric Hufflepuff
14 Edgecombe, Marietta Ravenclaw
15 Finch-Fletchley, Justin Hufflepuff
16 Finnigan, Seamus Gryffindor
17 Goldstein, Anthony Ravenclaw
18 Goyle, Gregory Slytherin
19 Granger, Hermione Gryffindor
20 Johnson, Angelina Gryffindor
21 Jordan, Lee Gryffindor
22 Longbottom, Neville Gryffindor
23 Lovegood, Luna Ravenclaw
24 Lupin, Remus Gryffindor
25 Malfoy, Draco Slytherin
26 Malfoy, Scorpius Slytherin
27 Macmillan, Ernie Hufflepuff
28 McGonagall, Minerva Gryffindor
29 Midgen, Eloise Gryffindor
30 McLaggen, Cormac Gryffindor
31 Montague, Graham Slytherin
32 Nott, Theodore Slytherin
33 Parkinson, Pansy Slytherin
34 Patil, Padma Gryffindor
35 Patil, Parvati Gryffindor
36 Potter, Harry Gryffindor
37 Riddle, Tom Slytherin
38 Robins, Demelza Gryffindor
39 Scamander, Newt Hufflepuff
40 Slughorn, Horace Slytherin
41 Smith, Zacharias Hufflepuff
42 Snape, Severus Slytherin
43 Spinnet, Alicia Gryffindor
44 Sprout, Pomona Hufflepuff
45 Thomas, Dean Gryffindor
46 Vane, Romilda Gryffindor
47 Warren, Myrtle Ravenclaw
48 Weasley, Fred Gryffindor
49 Weasley, George Gryffindor
50 Weasley, Ginny Gryffindor
51 Weasley, Percy Gryffindor
52 Weasley, Ron Gryffindor
53 Wood, Oliver Gryffindor
54 Zabini, Blaise Slytherin

View File

@@ -0,0 +1,7 @@
name,house
"Abbott, Hannah",Hufflepuff
"Bell, Katie",Gryffindor
"Bones, Susan",Hufflepuff
"Boot, Terry",Ravenclaw
"Brown, Lavender",Gryffindor
"Bulstrode, Millicent",Slytherin
1 name house
2 Abbott, Hannah Hufflepuff
3 Bell, Katie Gryffindor
4 Bones, Susan Hufflepuff
5 Boot, Terry Ravenclaw
6 Brown, Lavender Gryffindor
7 Bulstrode, Millicent Slytherin

View File

@@ -0,0 +1,5 @@
first,last,house
Susan,Bones,Hufflepuff
Terry,Boot,Ravenclaw
Lavender,Brown,Gryffindor
Millicent,Bulstrode,Slytherin
1 first last house
2 Susan Bones Hufflepuff
3 Terry Boot Ravenclaw
4 Lavender Brown Gryffindor
5 Millicent Bulstrode Slytherin

View File

@@ -0,0 +1,42 @@
import csv
import os
import sys
def main():
try:
input_file_name, output_file_name = sys.argv[1:3]
except IndexError:
print("Too few command-line arguments")
sys.exit(1)
if len(sys.argv) > 3:
print("Too many command-line arguments")
sys.exit(1)
if not os.path.isfile(input_file_name): # Or try opening and catch FileNotFoundError
print(f"Could not read {input_file_name}")
sys.exit(1)
if not input_file_name.endswith('.csv'):
print(f"Not a CSV file")
sys.exit(1)
write_names_to_csv_file(read_names_from_csv_file(input_file_name), output_file_name)
def read_names_from_csv_file(input_file_name):
with open(input_file_name, 'r') as input_file:
reader = csv.DictReader(input_file)
for row in reader:
yield row
def write_names_to_csv_file(input_data, output_file_name):
with open(output_file_name, 'w') as output_file:
writer = csv.DictWriter(output_file, fieldnames=['first', 'last', 'house'])
writer.writeheader()
for row in input_data:
row['last'], row['first'] = row['name'].split(', ')
del row['name']
writer.writerow(row)
if __name__ == "__main__":
main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@@ -0,0 +1,43 @@
import os
import sys
import PIL
from PIL import Image
def main():
try:
input_file_name, output_file_name = sys.argv[1:3]
except (IndexError, ValueError):
print("Too few command-line arguments")
sys.exit(1)
if len(sys.argv) > 3:
print("Too many command-line arguments")
sys.exit(1)
if not os.path.isfile(input_file_name): # Or try opening and catch FileNotFoundError
print(f"Input does not exist")
sys.exit(1)
if not (any(input_file_name.lower().endswith(format) for format in (".jpg", ".jpeg", ".png")) and any(output_file_name.lower().endswith(format) for format in (".jpg", ".jpeg", ".png"))):
print(f"Invalid input")
sys.exit(1)
if (input_file_name[-4] == '.' and input_file_name[-4:] != output_file_name[-4:]) or (input_file_name[-3] == '.' and input_file_name[-3:] != output_file_name[-3:]):
print(f"Input and output have different extensions")
sys.exit(1)
overlap_t_shirt(input_file_name, output_file_name)
"""Open the input with Image.open, per pillow.
resize and crop the input with ImageOps.fit, per pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.fit,
using default values for method, bleed, and centering, overlay the shirt with Image.paste,
per pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.paste,
and save the result with Image.save, per pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.save."""
def overlap_t_shirt(input_file_name, output_file_name):
image = Image.open(input_file_name)
shirt = Image.open('shirt.png')
image = PIL.ImageOps.fit(image, size=shirt.size)
image.paste(shirt, mask=shirt)
image.save(output_file_name)
if __name__ == "__main__":
main()