From d5af5d1de5f90ef2ef9b23765008e633d41a9743 Mon Sep 17 00:00:00 2001 From: DumbMachine Date: Tue, 25 Jun 2019 10:38:11 +0530 Subject: [PATCH 1/3] yea boi --- README.md | 7 ++ SyncBoostNote/bns.yaml | 5 ++ SyncBoostNote/cli.py | 105 ++++++++++++++++++++++ SyncBoostNote/config.py | 71 +++++++++++++++ SyncBoostNote/config.yaml | 7 ++ SyncBoostNote/history.json | 38 ++++++++ SyncBoostNote/test.py | 180 +++++++++++++++++++++++++++++-------- SyncBoostNote/utils.py | 0 8 files changed, 378 insertions(+), 35 deletions(-) create mode 100644 SyncBoostNote/bns.yaml create mode 100644 SyncBoostNote/cli.py create mode 100644 SyncBoostNote/config.py create mode 100644 SyncBoostNote/config.yaml create mode 100644 SyncBoostNote/history.json create mode 100644 SyncBoostNote/utils.py diff --git a/README.md b/README.md index b90ef5b..d3cf180 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # SyncBoostNote Python script to sync your Notes from BoostNote into a github repo. + +TODOS: +- [ ] Have tags at a newline together and seperate from other shields. +- [ ] MAke syncboostnotes directory. +- [ ] Make Python Package. +- [ ] Make this repo Pulic. +- [ ] Sick boi. \ No newline at end of file diff --git a/SyncBoostNote/bns.yaml b/SyncBoostNote/bns.yaml new file mode 100644 index 0000000..a3946be --- /dev/null +++ b/SyncBoostNote/bns.yaml @@ -0,0 +1,5 @@ +BOOSTNOTE_PATH: ~/BoostNotes +FREQUENCY: hourly +SHIELDS: true +SHIELDS_TYPE: for-the-badge +TIME: 1200 diff --git a/SyncBoostNote/cli.py b/SyncBoostNote/cli.py new file mode 100644 index 0000000..49d29e8 --- /dev/null +++ b/SyncBoostNote/cli.py @@ -0,0 +1,105 @@ +import argparse +import json +import os +import shutil +import site +import sys +import textwrap +import time +import warnings + +from colorama import Fore, init + +from config import Config, interactive, config_reader +from test import ultimate + +init(autoreset=True) + + +def options(): + ''' + Parsing the Arguments here + ''' + ap = argparse.ArgumentParser( + prog="projectpy", + usage="%(prog)s [options]", + formatter_class=argparse.RawDescriptionHelpFormatter, + description=textwrap.dedent('''SyncBoostNotes + ======================================= + - A CLI to Sync your BoostNotes Notes - + ======================================= + ''')) + + ap.add_argument("-l", "--location", required=True, + help="Location of the BoostNotes local storage.") + + ap.add_argument( + "-c", + "--config", + required=False, + help="Location of the config.yaml/config.yml file", + default=True) + + ap.add_argument( + "-col", + "--color", + required=False, + help="Toggle Colors on the print", + default=True) + + ap.add_argument( + "-g", + "--generate", + required=False, + help="Generate config.yaml file for ya", + default=True) + + ap.add_argument( + "-i", + "--interactive", + required=False, + help="Get an Interactive prompt to fill the forms.", + default=False) + + return vars(ap.parse_args()) + + +def initialize(args): + ''' + Sets the Config for the installation + ''' + if args['interactive']: + print('>>> Interactive <<<') + return interactive() + + elif args['config']: + print('>>> CUSTOM <<<') + ultimate(config_reader('./config.yaml')) + + else: + # ! Weird + raise Exception('Weird') + + +def main(): + args = options() + initialize(args) + + +def run_as_command(): + main() + + +run_as_command() +# print( +# ''' +# _________________________________ +# | | +# | Generation was successful | +# | Below is the generated config: | +# | ------------------------- | +# | $ cd repo_name | +# | $ python setup.py install | +# ------------------------------ +# ''' +# ) diff --git a/SyncBoostNote/config.py b/SyncBoostNote/config.py new file mode 100644 index 0000000..0e9f822 --- /dev/null +++ b/SyncBoostNote/config.py @@ -0,0 +1,71 @@ +import yaml +import sys +import os +import readline +import json + +home = os.path.expanduser("~") + + +class git_commands: + add = "git add -A" + commit = "git commit -m {}" + status = "git status" + push = "git push origin master" + + +Config = { + "BOOSTNOTE_PATH": "~/BoostNotes", + "SHIELDS": True, + "SHIELDS_TYPE": "for-the-badge", + "FREQUENCY": "hourly", + "TIME": 1200 +} + + +def interactive(): + conf = {} + questions = [ + ['BOOSTNOTE_PATH: ', ' ~/BoostNotes', 'BOOSTNOTE_PATH'], + ['SHIELDS: ', ' True', 'SHIELDS'], + ['SHIELDS_TYPE: ', 'for-the-badge', 'SHIELDS_TYPE'], + # ["hourly", "daily", "weekly", "monthly"] + ['FREQUENCY: ', 'hourly', 'FREQUENCY'], + ['TIME: ', '1200', 'TIME'], # 24 gour format for now + + ] + for question in questions: + conf[question[2]] = input_with_prefill(question[0], question[1]) + print(json.dumps( + conf, indent=2 + )) + return conf + + +def config_reader(location): + config = yaml.load(open(location), Loader=yaml.Loader) + print(json.dumps(config, indent=2)) + return config + + +def input_with_prefill(prompt, text): + def hook(): + readline.insert_text(text) + readline.redisplay() + readline.set_pre_input_hook(hook) + result = input(prompt) + readline.set_pre_input_hook() + return result + + +def create_config(location='.'): + ''' + Creates a default config for users to see. + ''' + yaml.dump( + Config, + open(os.path.join(location, 'bns.yaml'), 'w+') + ) + + +create_config() diff --git a/SyncBoostNote/config.yaml b/SyncBoostNote/config.yaml new file mode 100644 index 0000000..b00223c --- /dev/null +++ b/SyncBoostNote/config.yaml @@ -0,0 +1,7 @@ +BOOSTNOTE_PATH: ~/BoostNotes + +SHIELDS: True +SHIELDS_TYPE: "for-the-badge" + +FREQUENCY: hourly # ["hourly", "daily", "weekly", "monthly"] +TIME: 1200 # 24 Hour format for now diff --git a/SyncBoostNote/history.json b/SyncBoostNote/history.json new file mode 100644 index 0000000..e2d36c0 --- /dev/null +++ b/SyncBoostNote/history.json @@ -0,0 +1,38 @@ +{ + "48b6616e-2dae-4a4e-a86e-e8133bcdbe05.cson": { + "title": "Snippet note example", + "updated": false + }, + "a0681b02-531d-4212-b35e-3bab8b60beea.cson": { + "title": "create-python-project", + "updated": false + }, + "b8b2dcb5-8c0e-43bf-84ab-0a7605bf31c1.cson": { + "title": "\ud83d\udd34 THIS DOCUMENTATION IS WIP and will be completed soon.", + "updated": false + }, + "2a3fd7c0-8c21-472a-bf95-05ea84d0d41e.cson": { + "title": "Day: Monday", + "updated": false + }, + "a7469891-2c80-41e0-b7be-e1c6f05f92a5.cson": { + "title": "TEST", + "updated": false + }, + "cc0c17cb-25bb-45f6-bdf0-fc8b54e88bb2.cson": { + "title": "Day: Tuesday Date: June 18", + "updated": false + }, + "43cbad10-3808-42c2-8439-1478b45b6293.cson": { + "title": "DAY: SUNDAY", + "updated": false + }, + "b008ef56-e95c-4a09-9268-349bd4fbf77d.cson": { + "title": "", + "updated": false + }, + "8d91b880-2462-4a8b-a914-1712b8579bc1.cson": { + "title": "Welcome to Boostnote!", + "updated": false + } +} \ No newline at end of file diff --git a/SyncBoostNote/test.py b/SyncBoostNote/test.py index c4389f5..b4417bd 100644 --- a/SyncBoostNote/test.py +++ b/SyncBoostNote/test.py @@ -1,16 +1,23 @@ # ! TODO: Add Highligthing shit -import os import json +import os +import subprocess +from collections import deque from glob import glob + import cson +from config import git_commands + home = os.path.expanduser("~") BOOSTNOTE_PATH = os.path.join(home, 'Boostnote') BOOSTNOTE_NOTES_PATH = os.path.join(home, 'Boostnote/notes') +BOOSTNOTE_SYNCNOTES_PATH = os.path.join( + home, 'Boostnote/notes/syncboostnote') -def boostnote_exists(): +def boostnote_exists(location=os.path.join(home, 'Boostnote')): if os.path.isdir(BOOSTNOTE_PATH): return 1 else: @@ -19,7 +26,7 @@ def boostnote_exists(): # raise NotADirectoryError("BoostNode Base Directory doesn't exist. Either make sure BoostNote is installed or add PATH to it in syncboostnote.yaml")\ -def boostnote_notes_exist(): +def boostnote_notes_exist(location=os.path.join(home, 'notes')): if os.path.isdir(BOOSTNOTE_NOTES_PATH): return 1 else: @@ -67,45 +74,51 @@ def customshield( return f".. image:: https://img.shields.io/badge/{label}-{message}-{color}.svg?style={style} :alt: {name}" -def markdown_writer(things, shields=True): +def markdown_writer(things, location, shields=True, + options={ + 'style': 'for-the-badge', + 'option': 2 + }): embels = ['isStarred', 'isTrashed', 'updatedAt', 'type', 'folder', 'tags'] shelds = [] if shields: for key in embels: x = None - # print(things[key]) - # if key in ['isStarred', 'isTrashed']: if things[key]: if key == 'isStarred': - shelds.append(customshield(key, '⭐', color='black')) + shelds.append(customshield( + key, '⭐', color='black', style=options['style'])) if key == 'isTrashed': - shelds.append(customshield(key, '🗑', color='black')) + shelds.append(customshield( + key, '🗑', color='black', style=options['style'])) elif key == 'updatedAt': shelds.append(customshield( - key, things[key].split(':')[0][:-3].replace('-', '/'), color='green')) + key, things[key].split(':')[0][:-3].replace('-', '/'), color='green', style=options['style'])) elif key in ['type', 'folder']: - shelds.append(customshield(key, things[key], color='blue')) - - elif key == 'tags': - # OPTION 1: {tag| gay} {tag| notgay} - # for tag in things[key]: - # shelds.append( - # customshield(label='tag', message=tag, - # color='purple') - # ) - - # OPTION 2: {tag| gay, notgay} - tags = [] - for tag in things[key]: - tags.append(tag) shelds.append(customshield( - label='tags', message='_'.join(tags), color='blueviolet', style='for-the-badge')) + key, things[key], color='blue', style=options['style'])) - file = open(os.path.join(BOOSTNOTE_NOTES_PATH, + elif key == 'tags': + if options['option']: + # OPTION 1: {tag| gay} {tag| notgay} + for tag in things[key]: + shelds.append( + customshield(label='tag', message=tag, + color='purple', style=options['style']) + ) + else: + # OPTION 2: {tag| gay, notgay} + tags = [] + for tag in things[key]: + tags.append(tag) + shelds.append(customshield( + label='tags', message='_'.join(tags), color='blueviolet', style=options['style'])) + + file = open(os.path.join(location, f"{things['title']}.md"), 'w+') for count, shield in enumerate(shelds): @@ -127,18 +140,115 @@ def markdown_writer(things, shields=True): except: pass -# markdown_writer( -# cson_reader(get_notes()[4]) -# ) - -for note in get_notes(): - markdown_writer( - cson_reader( - note - ) - ) +# for note in get_notes(): +# markdown_writer( +# cson_reader(note), +# options={ +# 'style': 'for-the-badge', +# 'option': 2 +# } +# ) # boostnote_exists() # boostnote_notes_exist() # cson_reader() # cson_reader() + +def get_changes(): + ''' + uses git status to find the files which have changes. + ------------------------------------------------------ + + Returns: + list: + A List containing all the files names which have changed. + >>> get_changes() + >>> ['test.py', 'cli.py', 'config.py', 'utils.py'] + ''' + files = [] + os.chdir(BOOSTNOTE_NOTES_PATH) + p = subprocess.Popen( + git_commands.status, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + for line in p.stdout.readlines(): + if '.cson' in line.decode("utf-8"): + files.append(line.decode( + "utf-8").replace('modified:', '').strip()) + retval = p.wait() + return files + + +def update_changes(): + changed_files = get_changes() + history_json = json.load(open(os.path.join( + BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'r')) + for file in changed_files: + history_json[file]['updated'] = False + json.dump( + history_json, + open(os.path.join(BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'w+') + ) + + +def history(): + ''' + This method will keep track of the files saved and pushed to git. + + ''' + raise NotImplementedError + + +def create_history(): + files = {} + for note in get_notes(): + files[note.split('/')[-1]] = { + 'title': cson.load(open(note, 'r'))['title'], + 'updated': True + } + json.dump( + files, + open(os.path.join(BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'w+') + ) + + +def ultimate(config): + if not os.path.isfile(os.path.join(config['BOOSTNOTE_PATH'], 'notes', 'syncboostnote', 'history.json')): + # Create the History json again. + print( + os.path.join(config['BOOSTNOTE_PATH'], 'notes', + 'syncboostnote', 'history.json') + ) + raise FileNotFoundError("History.json Doesn't exist") + if boostnote_exists(config['BOOSTNOTE_PATH']): + print() + print('[PASSED] BOOSTNOTE_EXISTS ') + if boostnote_notes_exist(os.path.join(config['BOOSTNOTE_PATH'], 'notes')): + print('[PASSED] BOOSTNOTE_NOTES_EXISTS ') + history_json = json.load(open(os.path.join( + BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'r')) + for file in history_json.keys(): + if not history_json[file]['updated']: + # If not updated, re render the file + markdown_writer( + cson_reader( + os.path.join( + config['BOOSTNOTE_PATH'], 'notes', file) + ), + location=BOOSTNOTE_SYNCNOTES_PATH, + options={ + 'style': config['SHIELDS_TYPE'], + 'option': 2 + } + ) + # print(config) + + else: + print("FUCKKK") + + +ultimate({ + "BOOSTNOTE_PATH": os.path.join(home, 'Boostnote'), + "SHIELDS": True, + "SHIELDS_TYPE": "for-the-badge", + "FREQUENCY": "hourly", + "TIME": 1200 +}) diff --git a/SyncBoostNote/utils.py b/SyncBoostNote/utils.py new file mode 100644 index 0000000..e69de29 From 35f90cb8d710c704ecb90aa4e4e9765873cf1872 Mon Sep 17 00:00:00 2001 From: DumbMachine Date: Tue, 25 Jun 2019 12:30:03 +0530 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++ SyncBoostNote/config.py | 4 +- SyncBoostNote/config.yaml | 2 +- SyncBoostNote/test.py | 128 ++++++++++++++++++++++++++++++++++---- 4 files changed, 122 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d3cf180..cea6c0f 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,8 @@ TODOS: - [ ] MAke syncboostnotes directory. - [ ] Make Python Package. - [ ] Make this repo Pulic. +- [ ] Generate README + - [ ] Sort the names by tag. + - [ ] Sort the names by date. + - [ ] sort the names by name (alphabetically) - [ ] Sick boi. \ No newline at end of file diff --git a/SyncBoostNote/config.py b/SyncBoostNote/config.py index 0e9f822..0e99157 100644 --- a/SyncBoostNote/config.py +++ b/SyncBoostNote/config.py @@ -29,7 +29,7 @@ def interactive(): ['BOOSTNOTE_PATH: ', ' ~/BoostNotes', 'BOOSTNOTE_PATH'], ['SHIELDS: ', ' True', 'SHIELDS'], ['SHIELDS_TYPE: ', 'for-the-badge', 'SHIELDS_TYPE'], - # ["hourly", "daily", "weekly", "monthly"] + # ["hourly", "daily", "weekly", "monthly", "onchange"] ['FREQUENCY: ', 'hourly', 'FREQUENCY'], ['TIME: ', '1200', 'TIME'], # 24 gour format for now @@ -68,4 +68,4 @@ def create_config(location='.'): ) -create_config() +# create_config() diff --git a/SyncBoostNote/config.yaml b/SyncBoostNote/config.yaml index b00223c..2883286 100644 --- a/SyncBoostNote/config.yaml +++ b/SyncBoostNote/config.yaml @@ -4,4 +4,4 @@ SHIELDS: True SHIELDS_TYPE: "for-the-badge" FREQUENCY: hourly # ["hourly", "daily", "weekly", "monthly"] -TIME: 1200 # 24 Hour format for now +TIME: 12 # 24 Hour format for now diff --git a/SyncBoostNote/test.py b/SyncBoostNote/test.py index b4417bd..7283770 100644 --- a/SyncBoostNote/test.py +++ b/SyncBoostNote/test.py @@ -3,7 +3,9 @@ import json import os import subprocess +import time from collections import deque +from datetime import datetime from glob import glob import cson @@ -189,42 +191,34 @@ def update_changes(): ) -def history(): - ''' - This method will keep track of the files saved and pushed to git. - - ''' - raise NotImplementedError - - def create_history(): files = {} for note in get_notes(): files[note.split('/')[-1]] = { 'title': cson.load(open(note, 'r'))['title'], - 'updated': True + 'updated': False } json.dump( files, - open(os.path.join(BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'w+') + open(os.path.join(BOOSTNOTE_PATH, 'history.json'), 'w+') ) def ultimate(config): - if not os.path.isfile(os.path.join(config['BOOSTNOTE_PATH'], 'notes', 'syncboostnote', 'history.json')): + if not os.path.isfile(os.path.join(config['BOOSTNOTE_PATH'], 'history.json')): # Create the History json again. print( os.path.join(config['BOOSTNOTE_PATH'], 'notes', 'syncboostnote', 'history.json') ) - raise FileNotFoundError("History.json Doesn't exist") + create_history() if boostnote_exists(config['BOOSTNOTE_PATH']): print() print('[PASSED] BOOSTNOTE_EXISTS ') if boostnote_notes_exist(os.path.join(config['BOOSTNOTE_PATH'], 'notes')): print('[PASSED] BOOSTNOTE_NOTES_EXISTS ') history_json = json.load(open(os.path.join( - BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'r')) + BOOSTNOTE_PATH, 'history.json'), 'r')) for file in history_json.keys(): if not history_json[file]['updated']: # If not updated, re render the file @@ -252,3 +246,111 @@ def ultimate(config): "FREQUENCY": "hourly", "TIME": 1200 }) + + +# def timely_check(config): +# time_check = config['TIME'] +# frequency = config['FREQUENCY'] + +# if frequency == 'onchange': +# raise NotImplementedError('This THING is not implemented currently') +# else: +# if datetime.now().hour == time_check: +# print("ITS HIGH NOON") +# else: +# time.sleep(2) +# print("Has the time come yet?") + + +# # timely_check( +# # { +# # "BOOSTNOTE_PATH": os.path.join(home, 'Boostnote'), +# # "SHIELDS": True, +# # "SHIELDS_TYPE": "for-the-badge", +# # "FREQUENCY": "hourly", +# # "TIME": 11 +# # } +# # ) + + +# def watch_file(filename, time_limit=3600, check_interval=60): +# ''' +# use get changes to see changes +# ''' +# now = time.time() +# last_time = now + time_limit + +# while time.time() <= last_time: +# if os.path.exists(filename): +# print('yes') +# else: +# # Wait for check interval seconds, then check again. +# time.sleep(check_interval) + +# print('no') + + +# def create_readme(): +# raise NotImplementedError + +def create_readme(config): + + notes = get_notes() + # data = {} + file = open(os.path.join(config['BOOSTNOTE_PATH'], 'README.md'), 'w+') + file.write( + '''# SnycBoostNotes +### This repo consists of two directories: +```bash +$ tree +. +├── boostnote.json +├── history.json +└── notes + ├── ....cson + ├── ....cson + └── syncboostnote + ├── ....md + ├── ....md +``` +- Directory `base`: + - boostnote.json ``Created by boostnote`` + - history.json ``Created by SyncBoostnote`` + - Directory `notes`: + - Raw `.cson` files used by BoostNote. + - Directory `syncboostnote`: + - `.md` files used display content on Github. + +# Index: +## This following are the documents: + + ''' + ) + for note in get_notes(): + data = cson_reader(note) + # data[note.split("/")[-1]] = { + # 'title': cson_reader(note)['title'], + # 'createdAt': cson_reader(note)['createdAt'], + # 'tags': cson_reader(note)['tags'], + # } + # ! Generate Github link here + file.write( + f"- [{data['title']}](./notes/syncboostnote/{data['title']})") + file.write("\n") + # return data + + awesome = 'https://img.shields.io/badge/made--with--%E2%99%A5--by-ProjectPy-blueviolet.svg' + + file.write( + f"\n---\nThis README was generated with ❤ by [SyncBoostnote](https://github.com/DumbMachine/SyncBoostNote) ") + + +create_readme( + { + "BOOSTNOTE_PATH": os.path.join(home, 'Boostnote'), + "SHIELDS": True, + "SHIELDS_TYPE": "for-the-badge", + "FREQUENCY": "hourly", + "TIME": 11 + } +) From c155472cc4ad1b452477659d1eda455f8cb75437 Mon Sep 17 00:00:00 2001 From: DumbMachine Date: Tue, 25 Jun 2019 13:28:07 +0530 Subject: [PATCH 3/3] =?UTF-8?q?change=20watcher=20is=20much=20smarter=20no?= =?UTF-8?q?w=E2=9C=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +- SyncBoostNote/test.py | 177 +++++++++++++++++++++++++----------------- 2 files changed, 113 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index cea6c0f..50b00eb 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,10 @@ TODOS: - [ ] Sort the names by tag. - [ ] Sort the names by date. - [ ] sort the names by name (alphabetically) -- [ ] Sick boi. \ No newline at end of file +- [ ] Sick boi. +- [ ] Puts checks for, if the ".md" is somehow deleted, put it back in. +- [ ] Brings in Opps. + +## Thanks to this repo: +- pycson + - This reduced alot of the load. \ No newline at end of file diff --git a/SyncBoostNote/test.py b/SyncBoostNote/test.py index 7283770..1dbb49e 100644 --- a/SyncBoostNote/test.py +++ b/SyncBoostNote/test.py @@ -81,6 +81,15 @@ def markdown_writer(things, location, shields=True, 'style': 'for-the-badge', 'option': 2 }): + ''' + Used to write the markdown files + -------------------------------- + PARAMETERS: + things: dict, cson_reader(fp): + The dict{} which contains shit that was read via the cson + + ''' + embels = ['isStarred', 'isTrashed', 'updatedAt', 'type', 'folder', 'tags'] shelds = [] @@ -172,9 +181,17 @@ def get_changes(): p = subprocess.Popen( git_commands.status, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in p.stdout.readlines(): + # Putting checks to see if any rendered file is deleted. + if '.md' in line.decode("utf-8"): + files.append( + line.decode( + "utf-8").replace('modified:', '').strip().split('/')[-1] + ) + # Checking if the diff file is .cson if '.cson' in line.decode("utf-8"): files.append(line.decode( - "utf-8").replace('modified:', '').strip()) + "utf-8").replace('modified:', '').strip().split('/')[-1] + ) retval = p.wait() return files @@ -182,12 +199,34 @@ def get_changes(): def update_changes(): changed_files = get_changes() history_json = json.load(open(os.path.join( - BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'r')) + BOOSTNOTE_PATH, 'history.json'), 'r')) for file in changed_files: - history_json[file]['updated'] = False + if '.md' in file: + # These files have been deleted or changed without telling us 😢😢😢 + # Thus we will re render them + # 1. get the filename + history_json = json.load(open(os.path.join( + BOOSTNOTE_PATH, 'history.json'), 'r')) + for filename in history_json.keys(): + if history_json[filename]['title'] == file.replace('.md', ''): + # 2. Rendering the missing files. + markdown_writer( + cson_reader( + os.path.join( + BOOSTNOTE_PATH, 'notes', filename) + ), + location=BOOSTNOTE_SYNCNOTES_PATH, + options={ + 'style': 'for-the-badge', + 'option': 2 + } + ) + pass + else: + history_json[file]['updated'] = False json.dump( history_json, - open(os.path.join(BOOSTNOTE_SYNCNOTES_PATH, 'history.json'), 'w+') + open(os.path.join(BOOSTNOTE_PATH, 'history.json'), 'w+') ) @@ -204,13 +243,61 @@ def create_history(): ) +def create_readme(config): + + notes = get_notes() + # data = {} + file = open(os.path.join(config['BOOSTNOTE_PATH'], 'README.md'), 'w+') + file.write( + '''# SnycBoostNotes +# This repo consists of two directories: +```bash +$ tree +. +├── boostnote.json +├── history.json +└── notes + ├── ....cson + ├── ....cson + └── syncboostnote + ├── ....md + ├── ....md +``` +- Directory `base`: + - boostnote.json ``Created by boostnote`` + - history.json ``Created by SyncBoostnote`` + - Directory `notes`: + - Raw `.cson` files used by BoostNote. + - Directory `syncboostnote`: + - `.md` files used display content on Github. + +# Index: +# This following are the documents: + + ''' + ) + for note in get_notes(): + data = cson_reader(note) + # data[note.split("/")[-1]] = { + # 'title': cson_reader(note)['title'], + # 'createdAt': cson_reader(note)['createdAt'], + # 'tags': cson_reader(note)['tags'], + # } + # ! Generate Github link here + file.write( + f"- [{data['title']}](https://github.com/DumbMachine/temp/blob/master/notes/syncboostnote/{data['title'].replace(' ','%20')}.md)") + file.write("\n") + # return data + + awesome = 'https://img.shields.io/badge/made--with--%E2%99%A5--by-ProjectPy-blueviolet.svg' + + file.write( + f"\n---\nThis README was generated with ❤ by [SyncBoostnote](https://github.com/DumbMachine/SyncBoostNote) ") + + def ultimate(config): if not os.path.isfile(os.path.join(config['BOOSTNOTE_PATH'], 'history.json')): # Create the History json again. - print( - os.path.join(config['BOOSTNOTE_PATH'], 'notes', - 'syncboostnote', 'history.json') - ) create_history() if boostnote_exists(config['BOOSTNOTE_PATH']): print() @@ -220,6 +307,7 @@ def ultimate(config): history_json = json.load(open(os.path.join( BOOSTNOTE_PATH, 'history.json'), 'r')) for file in history_json.keys(): + print(file, history_json[file]['updated']) if not history_json[file]['updated']: # If not updated, re render the file markdown_writer( @@ -233,7 +321,16 @@ def ultimate(config): 'option': 2 } ) - # print(config) + # Update the file render + history_json[file]['updated'] = True + + create_readme(config) + # Writing the changes of render. + json.dump( + history_json, + open(os.path.join(BOOSTNOTE_PATH, 'history.json'), 'w+') + ) + print('[PASSED] README_GEN ') else: print("FUCKKK") @@ -292,65 +389,3 @@ def ultimate(config): # def create_readme(): # raise NotImplementedError - -def create_readme(config): - - notes = get_notes() - # data = {} - file = open(os.path.join(config['BOOSTNOTE_PATH'], 'README.md'), 'w+') - file.write( - '''# SnycBoostNotes -### This repo consists of two directories: -```bash -$ tree -. -├── boostnote.json -├── history.json -└── notes - ├── ....cson - ├── ....cson - └── syncboostnote - ├── ....md - ├── ....md -``` -- Directory `base`: - - boostnote.json ``Created by boostnote`` - - history.json ``Created by SyncBoostnote`` - - Directory `notes`: - - Raw `.cson` files used by BoostNote. - - Directory `syncboostnote`: - - `.md` files used display content on Github. - -# Index: -## This following are the documents: - - ''' - ) - for note in get_notes(): - data = cson_reader(note) - # data[note.split("/")[-1]] = { - # 'title': cson_reader(note)['title'], - # 'createdAt': cson_reader(note)['createdAt'], - # 'tags': cson_reader(note)['tags'], - # } - # ! Generate Github link here - file.write( - f"- [{data['title']}](./notes/syncboostnote/{data['title']})") - file.write("\n") - # return data - - awesome = 'https://img.shields.io/badge/made--with--%E2%99%A5--by-ProjectPy-blueviolet.svg' - - file.write( - f"\n---\nThis README was generated with ❤ by [SyncBoostnote](https://github.com/DumbMachine/SyncBoostNote) ") - - -create_readme( - { - "BOOSTNOTE_PATH": os.path.join(home, 'Boostnote'), - "SHIELDS": True, - "SHIELDS_TYPE": "for-the-badge", - "FREQUENCY": "hourly", - "TIME": 11 - } -)