Пример #1
0
 def load_users(c):
     global users
     if not users:
         try:
             with open('users', 'r') as f:
                 users = cPickle.load(f)
         except:
             users = {}
     return users
Пример #2
0
def get_dictionary():
    global dictionary
    if dictionary is None:
        dictionary = set()
        with open("dictionary", "r") as dictionary_file:
            for line in dictionary_file:
                word = line[:-1]
                if len(word) > 4 and len(word) < 8:
                    dictionary.add(word)
    return dictionary
Пример #3
0
def load_sessions_from_file(files=DEFAULT_FILES):
    sessions = set()
    corruptions = set()
    try:
        with open('data/corruptions', 'r') as f:
            for line in f:
                corruptions.add(line[:-1])
    except:
        pass
    for record in utilities.glob(files):
        if record not in corruptions:
            with open(record, 'r') as f:
                try:
                    sessions.add(cPickle.load(f))
                except:
                    corruptions.add(record)
    if corruptions:
        print("Warning! Failed to pickle {} sessions stored locally.".format(
            len(corruptions)
        ))
    with open('data/corruptions', 'w') as f:
        for s in corruptions:
            f.write("{}\n".format(s))
    return sessions
Пример #4
0
 def save(self):
     with open(self.filename(), 'w') as f:
         cPickle.dump(self, f)
Пример #5
0
def save_interpretation_rules():
    with open('interpretation_rules', 'w') as f:
        for p in interpretation_rules:
            for rule in interpretation_rules[p]:
                f.write("{} {} {} {}\n".format(p, rule['question'], rule['answer'], rule['result']))
Пример #6
0
def load_interpretation_rules():
    with open('interpretation_rules', 'r') as f:
        for line in f:
            (p, question, answer, result) = line.split()
            interpretation_rules[p].append({'question':question, 'answer':answer, 'result':result})
Пример #7
0
 def save_users(c, users):
     try:
         with open('users', 'w') as f:
             cPickle.dump(users, f)
     except:
         pass