fix linting issues

This commit is contained in:
Anish Lakhwara 2022-02-26 21:57:34 +10:00
parent def2c82a56
commit 55094a3367

View file

@ -1,8 +1,12 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
# Various methods of grabbing files from Kitaab based on their ctags as generated by vimwiki
# Various methods of grabbing files from Kitaab
# based on their ctags as generated by vimwiki
# censor - burn all mentions of this word wherever it appears in Kitaab # censor - burn all mentions of this word wherever it appears in Kitaab
# filter - leave names in tact but do not link to relevant documents # filter - leave names in tact but do not link to relevant documents
# create - list in an index file for website # create - list in an index file for website
from shared.censor import privateList
from shared import TagHelper, config
from os import listdir, mkdir, path, remove from os import listdir, mkdir, path, remove
import shutil import shutil
import random import random
@ -11,29 +15,32 @@ from . import convert
import os import os
import sys import sys
sys.path.append("../") sys.path.append("../")
from shared.censor import privateList
from shared import TagHelper, config
## TODO: generalize based on headings(?) in index.wiki # TODO: generalize based on headings(?) in index.wiki
censor = privateList censor = privateList
# TODO put this in config too... # TODO put this in config too...
filter = ["dream", "gratitude", "review", "jrnl", "work", "job", "debt", "people", "priv", "threatdefence", "info"] filter = ["dream", "gratitude", "review", "jrnl", "work", "job", "debt",
"people", "priv", "threatdefence", "info"]
# TODO create = ... # TODO create = ...
def loadNetwork(path='network.json'): def loadNetwork(path='network.json'):
# Loads the network.json file # Loads the network.json file
with open(path, 'r') as f: with open(path, 'r') as f:
everything = json.load(f) everything = json.load(f)
return everything return everything
def setNetwork(everything): def setNetwork(everything):
# Everything is loaded from the network.json file # Everything is loaded from the network.json file
keys = set(everything.network()) # keys = set(everything.network())
network = ""
values = set(everything.values()) values = set(everything.values())
everything = network + values everything = network + values
return everything return everything
def filterFiles(AllFileList): def filterFiles(AllFileList):
toFilter = filter + censor toFilter = filter + censor
tagList = TagHelper.getAllTags() tagList = TagHelper.getAllTags()
@ -45,6 +52,7 @@ def filterFiles(AllFileList):
print("Key not found: {}".format(mask)) print("Key not found: {}".format(mask))
return AllFileList - doNotTakeFiles return AllFileList - doNotTakeFiles
def untaggedFiles(AllFileList=TagHelper.getAllFiles()): def untaggedFiles(AllFileList=TagHelper.getAllFiles()):
toFilter = filter + censor toFilter = filter + censor
tagList = TagHelper.getAllTags() tagList = TagHelper.getAllTags()
@ -56,6 +64,7 @@ def untaggedFiles(AllFileList=TagHelper.getAllFiles()):
print("Key not found: {}".format(mask)) print("Key not found: {}".format(mask))
return set.difference(AllFileList, doNotTakeFiles) return set.difference(AllFileList, doNotTakeFiles)
def censorNetwork(network): def censorNetwork(network):
# Takes network as a set # Takes network as a set
for c in censor: for c in censor:
@ -64,9 +73,11 @@ def censorNetwork(network):
network.remove(c) network.remove(c)
return network return network
def generateBlocks(size=1): def generateBlocks(size=1):
# Generates a length size unicode string that is formed from blocks: # Generates a length size unicode string that is formed from blocks
charList = ['', '', '', '', '', '', '▖▗', '▘▙', '', '', '', '', '', ''] charList = ['', '', '', '', '', '', '▖▗',
'▘▙', '', '', '', '', '', '']
ret = "" ret = ""
while size > 0: while size > 0:
size = size - 1 size = size - 1
@ -74,9 +85,11 @@ def generateBlocks(size=1):
ret = ret + charList[rand] ret = ret + charList[rand]
return ret return ret
def createIndexNode(network): def createIndexNode(network):
pass pass
def copyFiles(fileList): def copyFiles(fileList):
baseFilePath = '/home/anish/vimwiki/' baseFilePath = '/home/anish/vimwiki/'
outputFilePath = '../raw/' # TODO relative path.... outputFilePath = '../raw/' # TODO relative path....
@ -88,7 +101,9 @@ def copyFiles(fileList):
try: try:
shutil.copy(baseFilePath + f, outputFilePath + f) shutil.copy(baseFilePath + f, outputFilePath + f)
except FileNotFoundError: except FileNotFoundError:
print("Could not copy file {} to {}".format(baseFilePath + f, outputFilePath + f)) print("Could not copy file {} to {}".format(baseFilePath+f,
outputFilePath+f))
def censorFiles(outputBasePath='../raw/'): def censorFiles(outputBasePath='../raw/'):
for fileName in listdir(outputBasePath): for fileName in listdir(outputBasePath):
@ -105,6 +120,7 @@ def censorFiles(outputBasePath='../raw/'):
for line in newFile: for line in newFile:
f.write(line) f.write(line)
def convertFiles(outputBasePath='../raw/'): def convertFiles(outputBasePath='../raw/'):
for filename in listdir(outputBasePath): for filename in listdir(outputBasePath):
if not path.isfile(outputBasePath + filename): if not path.isfile(outputBasePath + filename):
@ -116,7 +132,8 @@ def convertFiles(outputBasePath='../raw/'):
convert.convert_file(outputBasePath + filename) convert.convert_file(outputBasePath + filename)
remove(outputBasePath + filename) remove(outputBasePath + filename)
except RuntimeError as e: except RuntimeError as e:
print(f"Could not convert file {outputBasePath + filename} because {e}") print(f"Could not convert file {outputBasePath+filename}: {e}")
def deleteOldRaw(): def deleteOldRaw():
if os.path.exists(config.raw_folder): if os.path.exists(config.raw_folder):
@ -124,7 +141,6 @@ def deleteOldRaw():
if __name__ == '__main__': if __name__ == '__main__':
# network = loadNetwork() # network = loadNetwork()
# network = censorNetwork(network) # network = censorNetwork(network)
deleteOldRaw() deleteOldRaw()