Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding five files #199

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8039f73
adding mailroom 4 /session06 assignment
VincentAquila Nov 20, 2018
bc0f70e
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 20, 2018
5d26ef9
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 21, 2018
c1ada6d
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 22, 2018
9040240
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 24, 2018
f54ea8b
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 24, 2018
8f01e38
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 25, 2018
d9dedea
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 25, 2018
4526618
Adding html_render and its test file test_html_render. Work is part …
VincentAquila Nov 27, 2018
547c09c
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Nov 28, 2018
53d8707
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 1, 2018
818cc28
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 2, 2018
3048a9d
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 3, 2018
9e0da32
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 4, 2018
1fa90ae
commit number 164, trying to remove erroneous file, plus resubmit fil…
VincentAquila Dec 4, 2018
6db0762
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 5, 2018
bb76336
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 5, 2018
a1f1ff0
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 5, 2018
54d508e
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 7, 2018
6b0e948
Adding five files: trigrams (originally submitted 6Nov), html render …
VincentAquila Dec 8, 2018
dd4e618
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 10, 2018
0a3d967
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 11, 2018
d278655
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 12, 2018
aa2bc2c
adding final mailroom in OOP format with three files
VincentAquila Dec 15, 2018
bb0869e
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 15, 2018
0b67f61
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
VincentAquila Dec 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions students/Vincent_Aquila/session04/trigrams.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""
Python210A Vincent Aquila Fall2018
using Python 3.7.0
Trigrams Assignment in Session 4 - needs further work, but functions with the sherlock text file and a string of text
--- please disregard items that are commented out, this is still in progress ---
Trigrams Assignment in Session 4

Note - Some items are commented out. Depending on what input is requested - a line of text
from def make_trigrams, or an entire an entire document from sherlocktest.txt can be run
"""



#test with trigrams
"""
words = "I wish I may I wish I might".split()
Expand All @@ -27,22 +30,40 @@ def make_trigrams(words):
tris = make_trigrams(words)

"""
#opens a text file called sherlock, which is located in the same directory as this python file
def file_to_word_list(text_file): #this function can any argument, in this case it is being called text_file
with open(text_file, 'r') as f: #opens the text file in read (r) mode and assigns txt file to variable called f (white font is argument)
word_list = [] #this is an empty list, the "container" which will hold the text
for line in f.readlines(): #find all the lines in the file, and go line by line, to build up a larger list
words = line.split() #words is a new container temporary container; splitting each line on the white space
word_list.extend(words) #"appending" - actually "extending" words to container word list; extend is like append, except extend adds in everything
return word_list


#f_contents = f.readlines() #opens the text file
#print(f_contents) #prints the sherlock file

"""
opens a text file called sherlock, which is located in the same directory as
this python file; disregard comments, they serve to remind me what the code does
"""
#this function can any argument, in this case it is being called text_file
def file_to_word_list(text_file):
#opens the text file in read (r) mode and assigns txt file to variable called f (white font
#is argument)
with open(text_file, 'r') as f:
#this is an empty list, the "container" which will hold the text
word_list = []
#find all the lines in the file, and go line by line, to build up a larger list
for line in f.readlines():
#words is a new container temporary container; splitting each line on the white space
words = line.split()
#"appending" - actually "extending" words to container word list; extend is like append,
#except extend adds in everything
word_list.extend(words)
return word_list

#opens the text file
#f_contents = f.readlines()
#prints the sherlock file
#print(f_contents)

#f_contents.split()

def make_trigrams_sherlock(word_list): #f_contents is the sherlock.txt file


#f_contents is the sherlock.txt file
def make_trigrams_sherlock(word_list):
tris = {}
for w1, w2, w3 in zip(word_list[:-2], word_list[1:-1], word_list[2:]):
#print(w1, w2, w3)
Expand All @@ -58,10 +79,12 @@ def make_trigrams_sherlock(word_list): #f_contents is the sherlock.txt file
#tris = make_trigrams_sherlock(word_list)



if __name__ == "__main__":
word_list = file_to_word_list('sherlocktest.txt')# inside the () is where the actual name of the text files goes
# inside the () is where the actual name of the text files goes
word_list = file_to_word_list('sherlocktest.txt')
tris = make_trigrams_sherlock(word_list)
print(tris)

#this returns a dictionary


140 changes: 140 additions & 0 deletions students/Vincent_Aquila/session07/html_render2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Python210A Vincent Aquila Fall2018
using Python 3.7.0
Session 7 HTML Render - A class-based system for rendering html
"""


# This is the framework for the base class
class Element(object):
indent = " "
tag = "html"

def __init__(self, content=None, **kwargs):
if content is None:
self.content = []
else:
self.content = [content]
self.attrs = dict(**kwargs)

def append(self, new_content):
self.content.append(new_content)

def _open_tag(self):
if self.attrs is None:
return f"<{self.tag}>\n"
else:
open_tag = f"<{self.tag}"
for tag, attribute in self.attrs.items():
open_tag += f' {tag}="{attribute}"'
open_tag += ">\n"
return open_tag

def _close_tag(self):
return f"</{self.tag}>\n"

def render(self, out_file, cur_ind=""):
out_file.write(cur_ind + self._open_tag())

for content in self.content:
try:
content.render(out_file, cur_ind + self.indent)
except AttributeError:
out_file.write(f"{cur_ind + self.indent}{content}\n")
out_file.write(cur_ind + self._close_tag())


class Html(Element):
tag = "html"

def render(self, out_file, cur_ind=""):
out_file.write(cur_ind + "<!DOCTYPE html>\n")
super().render(out_file, cur_ind)


class Body(Element):
tag = "body"


class P(Element):
tag = "p"


class Head(Element):
tag = "head"


class Ul(Element):
tag = "ul"


class Li(Element):
tag = "li"


# OneLineTag
class OneLineTag(Element):
def render(self, out_file, cur_ind=""):
if self.attrs is None:
out_file.write(f"{cur_ind}<{self.tag}>{self.content[0]}</{self.tag}>\n")
else:
out_file.write(f"{cur_ind}<{self.tag}")
for tag, attribute in self.attrs.items():
out_file.write(f' {tag}="{attribute}"')
out_file.write(f">{self.content[0]}</{self.tag}>\n")

def append(self, new_content):
raise NotImplementedError("You cannot add content to a OneLineTag")


class Title(OneLineTag):
tag = "title"


class A(OneLineTag):
tag = "a"

def __init__(self, link, content=None, **kwargs):
kwargs['href'] = link
super().__init__(content, **kwargs)


class H(OneLineTag):
def __init__(self, num, content=None, **kwargs):
header_tag = "h" + str(num)

super().__init__(content, **kwargs)
self.tag = header_tag


# SelfClosingTag
class SelfClosingTag(Element):
def __init__(self, content=None, **kwargs):
if content:
raise TypeError("SelfClosingTag can not contain any content.")
super().__init__(content, **kwargs)

def append(self, new_content):
if new_content:
raise TypeError("You can not add content to a SelfClosingTag")

def render(self, out_file, cur_ind=""):
if self.attrs is None:
out_file.write(f"{cur_ind}<{self.tag} />\n")
else:
out_file.write(f"{cur_ind}<{self.tag}")
for tag, attribute in self.attrs.items():
out_file.write(f' {tag}="{attribute}"')
out_file.write(" />\n")


class Hr(SelfClosingTag):
tag = "hr"


class Br(SelfClosingTag):
tag = "br"


class Meta(SelfClosingTag):
tag = "meta"
Loading