Scratchbook



In [2]:
import bs4 as bsoup
import requests
import base64
from glob import glob
import re
import os
from datetime import datetime
import subprocess
import shutil
from yaml import load as ymload
from yaml import dump as ymdump
import argparse
from collections import defaultdict
from collections import OrderedDict

In [3]:
text_dir = "/home/dinesh/Projects/auto-quotidian/automatic-labnote-updater/text"

In [14]:
md_list = sorted(glob(os.path.join(text_dir, '*.md')))
mds_dict = defaultdict(list)
for md_file in md_list:
    md_date = re.findall('(\d\d\d\d-\d\d-\d\d)',
                         os.path.basename(md_file))
    mds_dict[md_date[0]].append(md_file)
    
sorted_mds = OrderedDict(
    [(key, mds_dict[key]) for key in sorted(mds_dict.keys())])
text_tag = []

In [12]:
sorted_mds


Out[12]:
OrderedDict([('2018-09-04',
              ['/home/dinesh/Projects/auto-quotidian/automatic-labnote-updater/text/2018-09-04.md']),
             ('2018-09-05',
              ['/home/dinesh/Projects/auto-quotidian/automatic-labnote-updater/text/2018-09-05.md']),
             ('2018-09-06',
              ['/home/dinesh/Projects/auto-quotidian/automatic-labnote-updater/text/2018-09-06.md'])])

In [16]:
md = sorted_mds['2018-09-04'][0]
with open(md, 'r') as f:
    text_data = f.read()

# Append it to blog data
text_tag.append(text_data)
text_tag


Out[16]:
['# Test\nA\nB\nC\n\n', '# Test\nA\nB\nC\n\n']

In [17]:



Out[17]:
'# Test\nA\nB\nC\n\n'