summaryrefslogtreecommitdiff
path: root/data_lib.py
diff options
context:
space:
mode:
Diffstat (limited to 'data_lib.py')
-rw-r--r--data_lib.py32
1 files changed, 28 insertions, 4 deletions
diff --git a/data_lib.py b/data_lib.py
index fea488f..5c830c7 100644
--- a/data_lib.py
+++ b/data_lib.py
@@ -3,6 +3,7 @@ import json
import re
import datetime
import time
+from util import split_sen, rot_ru
CWD = os.path.dirname(os.path.realpath(__file__))
@@ -17,6 +18,13 @@ def load_data(sort='len', sort_reverse=False, date=None, type=None):
with open(os.path.join(CWD, "data.json")) as f:
data = json.loads(f.read())
+ # stringify all types
+ for k, v in enumerate(data):
+ if 'type' in data[k]:
+ data[k]['type'] = str(data[k]['type'])
+ else:
+ data[k]['type'] = '1'
+
# ignore placeholders
data = list(filter(lambda i: i['text'] != '', data))
@@ -35,7 +43,7 @@ def load_data(sort='len', sort_reverse=False, date=None, type=None):
data = list(filter(lambda i: 'date' in i and i['date'] == date, data))
if type:
- data = list(filter(lambda i: 'type' in i and i['type'] == type, data))
+ data = list(filter(lambda i: 'type' in i and i['type'] == str(type), data))
return data
@@ -213,22 +221,38 @@ def decode3(s):
return buf
+def decode_2char_rot_minus3(s):
+ lines = split_sen(s)
+ buf = ''
+ for line in lines:
+ line = line.replace(' ', '')
+ if line in ('3', '4', '7/5'):
+ buf += line
+ continue
+ buf += line[1]
+
+ rots = rot_ru(buf, return_list=True)
+ return rots[len(rots)-2]
+
# s: source
# t: type
def decode_auto(s, t, reverse_decoded=False, remove_junk=True):
- if t == 1:
+ if t == '1':
s = clean_string(s, remove_junk=remove_junk)
result = decode(s)
- elif t == 2:
+ elif t == '2':
result = decode2(s)
- elif t == 3:
+ elif t == '3':
result = decode3(s)
+ elif t == '2char_rot-3':
+ result = decode_2char_rot_minus3(s)
+
if reverse_decoded:
# reverse string
result = result[::-1]