88from glob import glob
99
1010import cson
11-
11+ import subprocess
1212from .test import git_update
1313
1414home = os .path .expanduser ("~" )
@@ -21,7 +21,7 @@ def initialize(config):
2121 - Make directory for storing notes.
2222 - Create History
2323 # ! - Initialize the git repo.
24- ------------------------------------
24+ -----------------s -------------------
2525 called:
2626 - Is called upon using --initialize flag of the CLI
2727 '''
@@ -120,22 +120,22 @@ def ultimate(config):
120120 - updates the .md files, which require it.
121121 -----------------------------------------------
122122 '''
123- print ("Searching for BOOSTNOTE_PATH" , end = '\r ' )
124- sys .stdout .flush ()
123+ # print("Searching for BOOSTNOTE_PATH", end='\r')
124+ # sys.stdout.flush()
125125 if not os .path .isfile (os .path .join (config ['BOOSTNOTE_PATH' ], 'history.json' )):
126126
127127 # Create the History json again.
128128 create_history (config ['BOOSTNOTE_PATH' ])
129129 if boostnote_exists (config ['BOOSTNOTE_PATH' ]):
130130
131131 # Creating History again, as this will track if new files have been added.
132- sys .stdout .flush ()
133- print ("Creating History.json file" , end = '\r ' )
132+ # sys.stdout.flush()
133+ # print("Creating History.json file", end='\r')
134134
135135 create_history (config ['BOOSTNOTE_PATH' ])
136136
137- sys .stdout .flush ()
138- print ("Creation done!" , end = '\r ' )
137+ # sys.stdout.flush()
138+ # print("Creation done!", end='\r')
139139
140140 history_json = json .load (open (os .path .join (
141141 config ['BOOSTNOTE_PATH' ], 'history.json' ), 'r' ))
@@ -175,7 +175,8 @@ def cson_reader(location):
175175 data = cson .load (open (location , 'r' ))
176176 return data
177177 else :
178- raise FileNotFoundError (f'The cson file at { location } was not found' )
178+ return 0
179+ # raise FileNotFoundError(f'The cson file at {location} was not found')
179180
180181
181182def customshield (
@@ -210,67 +211,67 @@ def markdown_writer(things, location, shields=True,
210211 The dict{} which contains shit that was read via the cson
211212
212213 '''
214+ if things :
215+ embels = ['isStarred' , 'isTrashed' ,
216+ 'updatedAt' , 'type' , 'folder' , 'tags' ]
217+ shelds = []
218+ if shields :
219+ for key in embels :
220+ x = None
221+ if things [key ]:
222+ if key == 'isStarred' :
223+ shelds .append (customshield (
224+ key , '⭐' , color = 'black' , style = options ['style' ]))
213225
214- embels = ['isStarred' , 'isTrashed' ,
215- 'updatedAt' , 'type' , 'folder' , 'tags' ]
216- shelds = []
217- if shields :
218- for key in embels :
219- x = None
220- if things [key ]:
221- if key == 'isStarred' :
222- shelds .append (customshield (
223- key , '⭐' , color = 'black' , style = options ['style' ]))
224-
225- if key == 'isTrashed' :
226- shelds .append (customshield (
227- key , '🗑' , color = 'black' , style = options ['style' ]))
228-
229- elif key == 'updatedAt' :
230- shelds .append (customshield (
231- key , things [key ].split (':' )[0 ][:- 3 ].replace ('-' , '/' ), color = 'green' , style = options ['style' ]))
232-
233- elif key in ['type' , 'folder' ]:
234- shelds .append (customshield (
235- key , things [key ], color = 'blue' , style = options ['style' ]))
236-
237- elif key == 'tags' :
238- if options ['option' ]:
239- # OPTION 1: {tag| gay} {tag| notgay}
240- for tag in things [key ]:
241- shelds .append (
242- customshield (label = 'tag' , message = tag ,
243- color = 'purple' , style = options ['style' ])
244- )
245- else :
246- # OPTION 2: {tag| gay, notgay}
247- tags = []
248- for tag in things [key ]:
249- tags .append (tag )
226+ if key == 'isTrashed' :
250227 shelds .append (customshield (
251- label = 'tags' , message = '_' . join ( tags ) , color = 'blueviolet ' , style = options ['style' ]))
228+ key , '🗑' , color = 'black ' , style = options ['style' ]))
252229
253- file = open (os .path .join (location ,
254- f"{ things ['title' ]} .md" ), 'w+' )
230+ elif key == 'updatedAt' :
231+ shelds .append (customshield (
232+ key , things [key ].split (':' )[0 ][:- 3 ].replace ('-' , '/' ), color = 'green' , style = options ['style' ]))
255233
256- for count , shield in enumerate (shelds ):
257- if count != len (shelds ) - 1 :
258- file .write (shield )
259- file .write (' ' )
260- else :
261- file .write (shield )
262- file .write ('\n ' )
234+ elif key in ['type' , 'folder' ]:
235+ shelds .append (customshield (
236+ key , things [key ], color = 'blue' , style = options ['style' ]))
237+
238+ elif key == 'tags' :
239+ if options ['option' ]:
240+ # OPTION 1: {tag| gay} {tag| notgay}
241+ for tag in things [key ]:
242+ shelds .append (
243+ customshield (label = 'tag' , message = tag ,
244+ color = 'purple' , style = options ['style' ])
245+ )
246+ else :
247+ # OPTION 2: {tag| gay, notgay}
248+ tags = []
249+ for tag in things [key ]:
250+ tags .append (tag )
251+ shelds .append (customshield (
252+ label = 'tags' , message = '_' .join (tags ), color = 'blueviolet' , style = options ['style' ]))
253+
254+ file = open (os .path .join (location ,
255+ f"{ things ['title' ]} .md" ), 'w+' )
256+
257+ for count , shield in enumerate (shelds ):
258+ if count != len (shelds ) - 1 :
259+ file .write (shield )
260+ file .write (' ' )
261+ else :
262+ file .write (shield )
263+ file .write ('\n ' )
263264
264- try :
265- file .write (things ['content' ])
265+ try :
266+ file .write (things ['content' ])
266267
267- except :
268- pass
269- try :
270- file .write (things ['snippets' ])
268+ except :
269+ pass
270+ try :
271+ file .write (things ['snippets' ])
271272
272- except :
273- pass
273+ except :
274+ pass
274275
275276
276277def get_changes (
@@ -289,7 +290,7 @@ def get_changes(
289290 files = []
290291 os .chdir (location )
291292 p = subprocess .Popen (
292- git_commands . status , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
293+ "git status" , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
293294 for line in p .stdout .readlines ():
294295 # Putting checks to see if any rendered file is deleted.
295296 if '.md' in line .decode ("utf-8" ):
@@ -309,7 +310,7 @@ def get_changes(
309310def update_changes (
310311 location = os .path .join (home , 'Boostnote' )
311312):
312- create_history (location )
313+ # create_history(location)
313314 changed_files = get_changes ()
314315 history_json = json .load (open (os .path .join (
315316 location , 'history.json' ), 'r' ))
@@ -352,16 +353,25 @@ def update_changes(
352353def create_history (
353354 location = os .path .join (home , 'Boostnote' )
354355):
355- files = {}
356- for note in get_notes ():
357- files [note .split ('/' )[- 1 ]] = {
358- 'title' : cson .load (open (note , 'r' ))['title' ],
359- 'updated' : False
360- }
361- json .dump (
362- files ,
363- open (os .path .join (location , 'history.json' ), 'w+' )
364- )
356+ if os .path .isfile (
357+ os .path .join (location , 'history.json' )
358+ ):
359+ # FIle already exists, check for changes.
360+ update_changes ()
361+ print (1 )
362+
363+ else :
364+ print (3 )
365+ files = {}
366+ for note in get_notes ():
367+ files [note .split ('/' )[- 1 ]] = {
368+ 'title' : cson .load (open (note , 'r' ))['title' ],
369+ 'updated' : False
370+ }
371+ json .dump (
372+ files ,
373+ open (os .path .join (location , 'history.json' ), 'w+' )
374+ )
365375
366376
367377def create_readme (config ):
0 commit comments