From 46231333922eab62701cd1af98f4781c8e6b5eb9 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Wed, 10 Oct 2018 09:33:01 +0100 Subject: [PATCH] Tidy loading facts and haikus. --- plugin/facts/facts.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/plugin/facts/facts.py b/plugin/facts/facts.py index 3a3528d..00da32b 100644 --- a/plugin/facts/facts.py +++ b/plugin/facts/facts.py @@ -1,25 +1,24 @@ import asyncio +import os import random from plugins import PluginCommand import bot - class Facts(object): def __init__(self): - fFacts = open("catfacts.txt", "r") - self.catFacts = fFacts.readlines() - fFacts.close() - fHaiku = open("cat_haiku.txt", "r") - self.haikus = [] - haiku = [] - for line in fHaiku.readlines(): - if line != "\n": - haiku.append(line) - else: - self.haikus.append(haiku) - haiku = [] - fHaiku.close() + self.path = os.path.dirname(__file__)[(len(os.getcwd()) + 1):] + with open(os.sep.join([self.path, 'catfacts.txt']), 'r') as fd: + self.catFacts = fd.readlines() + with open(os.sep.join([self.path, 'cat_haiku.txt']), 'r') as fd: + self.haikus = [] + haiku = [] + for line in fd.readlines(): + if line != "\n": + haiku.append(line.strip()) + else: + self.haikus.append(haiku) + haiku = [] def description(self): return 'Generates Cat Facts and Haikus' -- 2.7.4