summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorrusinthread <rusinthread@cock.li>2017-01-06 19:56:51 +0300
committerrusinthread <rusinthread@cock.li>2017-01-06 19:56:51 +0300
commit4732bbbbd4d14a45d166781fde435e8b509e5a3e (patch)
treec00d8ea44c24b446c5801b8a18b8ae59e8948f50 /main.py
parente71e7160fd8104814758bab0e306f5b74a8f2402 (diff)
test data.md generation
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py65
1 files changed, 64 insertions, 1 deletions
diff --git a/main.py b/main.py
index cc42093..8139a9b 100755
--- a/main.py
+++ b/main.py
@@ -1,6 +1,14 @@
#!/usr/bin/env python3
-import argparse, sys, json, os, re
+import argparse
+import sys
+import json
+import os
+import re
+import time
+import datetime
+from pprint import pprint
+
try:
from termcolor import cprint
colors_supported = True
@@ -190,6 +198,9 @@ def decode3(s):
return buf
+
+
+
# s: source
# t: type
def decode_auto(s, t, reverse_decoded=False, remove_junk=True):
@@ -209,6 +220,10 @@ def decode_auto(s, t, reverse_decoded=False, remove_junk=True):
return result
+
+def sort_data_by_date(item):
+ return int(time.mktime(datetime.datetime.strptime(item['date'], '%d/%m/%y').timetuple()))
+
def main():
parser = argparse.ArgumentParser()
@@ -220,6 +235,7 @@ def main():
parser.add_argument('--is-url', action='store_true')
parser.add_argument('--type', type=int, choices=[1, 2, 3], default=1)
parser.add_argument('--reverse-decoded', action='store_true')
+ parser.add_argument('--gen-page', action='store_true')
args = parser.parse_args()
data = load_data()
@@ -273,5 +289,52 @@ def main():
count = len(data)
print("Total texts: %s" % count)
+ elif args.gen_page:
+ # sort by date
+ data = sorted(data, key=sort_data_by_date)
+ #pprint(data)
+
+ buf = []
+ for post in data:
+ cipher_type = post['type'] if 'type' in post else 1
+ decoded_text = decode_auto(post['text'], cipher_type)
+
+ post_buf = ''
+ post_buf += '**Дата**: %s\n' % post['date']
+
+ if 'pic' in post and post['pic']:
+ # make sure it is a list
+ pic = post['pic'] if isinstance(post['pic'], list) else [post['pic']]
+
+ pic_buf = []
+ for p in pic:
+ pic_buf.append('![](./img/%s =300x)' % p)
+ post_buf += '**Пикрилейтед:** %s\n' % ''.join(pic_buf)
+
+ if 'link' in post:
+ # make sure it is a list
+ link = post['link'] if isinstance(post['link'], list) else [post['link']]
+
+ link_buf = []
+ for l in link:
+ link_buf.append('[%s](%s)' % (l, l))
+ post_buf += '**Ссылки:** %s\n' % ', '.join(link_buf)
+
+ if 'source' in post:
+ post_buf += '**Источник:** %s' % post['source']
+ if 'source_link' in post:
+ post_buf += ', [%s](%s)\n' % (post['source_link'], post['source_link'])
+ else:
+ post_buf += '\n'
+
+ post_buf += '**Шифровка (тип %d)**: \n```\n%s\n```\n' % (cipher_type, post['text'])
+ post_buf += '**Расшифровка:** \n```\n%s\n```' % decoded_text
+
+ buf.append(post_buf)
+
+ md = "\n---\n".join(buf)
+ with open(os.path.join(CWD, 'data.md'), 'w') as f:
+ f.write(md)
+
if __name__ == '__main__':
sys.exit(main())