Пример #1
0
def main():
    user_input = InputClass
    ans = user_input.choose_event()
    while ans != "4":
        if ans == "1":
            publ = content.News()
        elif ans == "2":
            publ = content.Advert()
        elif ans == "3":
            publ = content.UserComment()
        publ.create_publication_body()
        file_pub = WriteContentToTxt(publ)
        file_pub.write_content()
        ans = user_input.choose_event()
Пример #2
0
source_of_input = user_input.read_correct_char(
    ("0", "1"), "choose source of import: 0 for file, 1 for console: ")

if source_of_input == "0":  # new part of 'main' code for handling input from file
    source_file = ReadContentFromTxt(
        handling_types=("1", "2", "3"))  # create object to read file input
    list_of_draft_publications = source_file.read_content(
    )  # read file content, clean data, normalize 'text' field, return list to a variable
    for draft_publication in list_of_draft_publications:  # loop through a list of data suitable for publication creating
        if draft_publication[0] == "1":
            publ = content.News(
                draft_publication
            )  # if choice = 1 => create News content from 'draft_publication'
        elif draft_publication[0] == "2":
            publ = content.Advert(
                draft_publication
            )  # if choice = 2 => create Adv content from 'draft_publication'
            if publ.mistakes_flag == 1:  # if we find an incorrect date while 'publ' is created
                source_file.set_successful_processing(
                )  # set flag 'file successful processing' to false (default value for procedure)
                continue  # skip this publication
        elif draft_publication[0] == "3":
            publ = content.UserComment(
                draft_publication
            )  # if choice = 3 => create UserComment content from 'draft_publication'
        publ.create_publication_body(
        )  # form publication body for each content type
        publ.write_content()  # write publication to a file
    del source_file  # call destructor for file deleting

elif source_of_input == "1":  # user has chose input from console
Пример #3
0
import content
from input_class import InputClass

user_input = InputClass  # create object to read user choice
ans = user_input.choose_event()  # ask for first input
while ans != "4":  # loop until user has not choose 4
    if ans == "1":
        publ = content.News()  # if choice = 1 => create News content
    elif ans == "2":
        publ = content.Advert()  # if choice = 2 => create Adv content
    elif ans == "3":
        publ = content.UserComment(
        )  # if choice = 3 => create User Comment content
    publ.create_publication_body()  # use method to  create publication body
    publ.write_content()  # and  write it to a file
    ans = user_input.choose_event()  # ask user for new choice