def droid_build(serial_num, conveyor): """ Build a singular droid :param serial_num: serial number of droid :param conveyor: queue :return: a droid with correct serial number, and a head, body, arms, and legs """ print("Building a new droid with the serial number", serial_num) new_droid = Droid(False, False, False, False, serial_num) while new_droid.arms is not True or new_droid.body is not True or new_droid.head is not True or new_droid.legs is not True: if conveyor.front.value == 'arms' and new_droid.arms == False: print("attaching arms...") new_droid.arms = True dequeue(conveyor) elif conveyor.front.value == 'legs' and new_droid.legs == False: print("attaching legs...") new_droid.legs = True dequeue(conveyor) elif conveyor.front.value == 'body' and new_droid.body == False: print("attaching body...") new_droid.body = True dequeue(conveyor) elif conveyor.front.value == 'head' and new_droid.head == False: print("attaching head...") new_droid.head = True dequeue(conveyor) else: front_elem = dequeue(conveyor) print("placing unneeded part back on belt: ", front_elem) enqueue(conveyor, front_elem) print("Droid ", serial_num, " hase been assembled!")
def web_doctype(html_parts): """ Adds the !DOCTYPE html tag to html_parts (queue). :param html_parts: queue of each line of the html text file :return: None """ que.enqueue(html_parts, "<!DOCTYPE html>\n")
def web_title(html_parts, title): """ Adds the title of the website to html_parts (queue). :param html_parts: queue of each line of the html text file :param title: the title of the website :return: None """ que.enqueue(html_parts, "<h1>" + title.strip() + "</h1>\n")
def wizard_body(html_parts): """ Adds the body html tag and its components in-between it (paragraph & paragraph title) to html_parts (queue). :param html_parts: queue of each line of the html text file :return: None """ que.enqueue(html_parts, "<body>\n") wizard_paragraph(html_parts) que.enqueue(html_parts, "</body>\n")
def web_image(html_parts, paragraph_image): """ Creates an image tag and adds it to html_parts (queue). :param html_parts: queue of each line of the html text file :param paragraph_image: name of the image inputted by the user :return: None """ que.enqueue(html_parts, "<img src=\"" + paragraph_image + "\" class=center>\n")
def web_paragraph(html_parts, paragraph_title, paragraph_content): """ Creates a paragraph using a header html tag for the title and paragraph tag for the paragraph content and adds it to html_parts (queue). :param html_parts: queue of each line of the html text file :param paragraph_title: the title of the paragraph :param paragraph_content: the content of the paragraph :return: None """ que.enqueue(html_parts, "<h2>" + str(paragraph_title) + "</h2>\n") que.enqueue(html_parts, "<p>" + str(paragraph_content) + "</p>\n")
def read_file(filename): """ read the file and create a queue, each line is another element in the queue :param filename: file inputted by the user :return: the queue created by the file contents """ file = open(filename) conveyor = make_empty_queue() for line in file: line = line.strip("\n") enqueue(conveyor, line) file.close() return conveyor
def link_queue(): """ Returns a queue of links of website titles that were inputted by the user through command line. :return: (queue_of_links) a queue that contains the links of each text file inputted by the user """ # Make New Queue for Links queue_of_links = que.make_empty_queue() count = len(sys.argv) - 1 while count >= 1: que.enqueue( queue_of_links, "<a href=\"" + get_title(sys.argv[count]) + ".html\">" + get_title(sys.argv[count]) + "</a>\n") count -= 1 return queue_of_links
def wizard_html(html_parts, website_title, background_color, font_style, paragraph_color, heading_color): """ Adds the html html tag and its components in-between it (head and body) to html_parts (queue). :param html_parts: queue of each line of the html text file :param website_title: the website title :param background_color: the background color inputted by the user :param font_style: the font style inputted by the user :param paragraph_color: the paragraph text color inputted by the user :param heading_color: the heading color inputted by the user :return: None """ que.enqueue(html_parts, "<html>\n") wizard_head(html_parts, website_title, background_color, font_style, paragraph_color, heading_color) wizard_body(html_parts) que.enqueue(html_parts, "</html>\n")
def web_style(html_parts, background_color, font_style, paragraph_color, heading_color): """ Reads the style template and stores each line within html_parts. Replaces the variables in the template with colors inputted by the user. :param html_parts: queue of each line of the html text file :param background_color: the background color inputted by the user :param font_style: the font style inputted by the user :param paragraph_color: the paragraph text color inputted by the user :param heading_color: the heading color inputted by the user :return: None """ que.enqueue(html_parts, "<style>\n") with open(style_template) as file: count = 1 line = file.readline() while line: count += 1 if count == 28: break line = file.readline() line = line.replace("@BACKCOLOR", background_color) line = line.replace("@FONTSTYLE", font_style) line = line.replace("@FONTCOLOR", paragraph_color) line = line.replace("@HEADCOLOR", heading_color) que.enqueue(html_parts, line) que.enqueue(html_parts, "</style>\n")
def web_head(html_parts, website_title, background_color, font_style, paragraph_color, heading_color, input_file, queue_of_links): """ Adds the head html tag and its components in-between it (title & style) to html_parts (queue). :param html_parts: queue of each line of the html text file :param website_title: the website title :param background_color: the background color inputted by the user :param font_style: the font style inputted by the user :param paragraph_color: the paragraph text color inputted by the user :param heading_color: the heading color inputted by the user :param input_file: the name of the text file inputted by the user (command line) :param queue_of_links: a queue that contains the links of each text file inputted by the user :return: None """ que.enqueue(html_parts, "<head>\n") web_title(html_parts, website_title) if queue_of_links is not que.make_empty_queue(): while que.is_empty(queue_of_links) is False: que.enqueue(html_parts, que.dequeue(queue_of_links)) web_style(html_parts, background_color, font_style, paragraph_color, heading_color) que.enqueue(html_parts, "</head>\n")
def input_text_file(html_parts, input_file, background_color, font_style, paragraph_color, heading_color, queue_of_links): """ Creates the body of the html file. Reads through the input_text_file and adds "commands" to html_parts (queue). :param html_parts: queue of each line of the html text file :param input_file: the name of the text file inputted by the user (command line) :param background_color: the background color inputted by the user :param font_style: the font style inputted by the user :param paragraph_color: the paragraph text color inputted by the user :param heading_color: the heading color inputted by the user :param queue_of_links: a queue that contains the links of each text file inputted by the user :return: (html_parts) queue of each line of the html text file """ with open(input_file) as file: line = file.readline() count = 1 while line: if count == 1: web_doctype(html_parts) que.enqueue(html_parts, "<html>\n") web_head(html_parts, line, background_color, font_style, paragraph_color, heading_color, input_file, queue_of_links) que.enqueue(html_parts, "<body>\n") line = file.readline().strip() count += 1 split_line = line.split() if line == "": line = file.readline().strip() split_line = line.split() if line == "!new_paragraph": paragraph_line = file.readline() paragraph_split_line = paragraph_line.split() paragraph_title = " ".join(paragraph_split_line[1:]) que.enqueue(html_parts, "<h2>" + paragraph_title + "</h2>\n") que.enqueue(html_parts, "<p>\n") while paragraph_line: paragraph_line = file.readline() paragraph_split_line = paragraph_line.split() if paragraph_line == "": break if paragraph_line == "\n": line = paragraph_line split_line = paragraph_line.split() break elif paragraph_split_line[0] == "!image": split_line = paragraph_split_line break que.enqueue(html_parts, paragraph_line) que.enqueue(html_parts, "</p>\n") if len(split_line) > 0 and split_line[0] == "!image": if len(split_line) == 2: web_image(html_parts, split_line[1]) elif len(split_line) == 3: web_image_percentage(html_parts, split_line[1], split_line[2]) else: raise Exception("Incorrect format for image command.") que.enqueue(html_parts, "</body>\n") que.enqueue(html_parts, "</html>\n") return html_parts