Esempio n. 1
0
def get_story_groups():
    groups = []
    with open(file_utils.do_resources_path(CSV_STORY_GROUPS),
              "rt") as csv_file:
        reader = csv.DictReader(csv_file, delimiter=',')
        for line in reader:
            groups.append(Group(line["Name"]))
    return groups
Esempio n. 2
0
def get_source_lines(sources):
    with open(file_utils.do_resources_path(CSV_SOURCES),
              "rt",
              encoding="ISO-8859-1") as csv_file:
        reader = csv.DictReader(csv_file, delimiter=',')
        return [
            line for csv_index, line in enumerate(reader)
            if str(csv_index) in sources
        ]
Esempio n. 3
0
 def get_page_contents(self, page, per_page):
     page_contents = []
     with open(file_utils.do_resources_path(CSV_POKES), "rt") as csv_file:
         reader = csv.DictReader(csv_file, delimiter=',')
         for index, line in enumerate(reader):
             if index >= (page + 1) * per_page:
                 break
             if index >= page * per_page:
                 page_contents.append(line)
         return page_contents
Esempio n. 4
0
def get_all_in_group(line):
    other_stories = []
    with open(file_utils.do_resources_path(CSV_STORIES), "rt") as csv_file:
        reader = csv.DictReader(csv_file, delimiter=',')
        for other_line in reader:
            # The group must be the same in the fetched page and the provided one
            # and the name of the story different to the name of the provided one
            if other_line["Group"] == line[
                    "Group"] and other_line["Name"] != line["Name"]:
                other_stories.append(other_line)
    return other_stories
Esempio n. 5
0
def get_story_part(line, part):
    with open(file_utils.do_resources_path(line["File"]),
              "rt",
              encoding="utf8") as story:
        return story.read().split("|")[part]
Esempio n. 6
0
def get_stories_into_groups(groups):
    with open(file_utils.do_resources_path(CSV_STORIES), "rt") as csv_file:
        reader = csv.DictReader(csv_file, delimiter=',')
        for line in reader:
            groups[int(line["Group"])].stories.append(line)