wikilinksgraph 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wikilinksgraph/__init__.py +0 -0
- wikilinksgraph/main.py +65 -0
- wikilinksgraph-0.1.0.dist-info/METADATA +10 -0
- wikilinksgraph-0.1.0.dist-info/RECORD +7 -0
- wikilinksgraph-0.1.0.dist-info/WHEEL +5 -0
- wikilinksgraph-0.1.0.dist-info/entry_points.txt +3 -0
- wikilinksgraph-0.1.0.dist-info/top_level.txt +1 -0
|
File without changes
|
wikilinksgraph/main.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import tempfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from pyvis.network import Network
|
|
5
|
+
|
|
6
|
+
class File_Reader:
|
|
7
|
+
def __init__(self, path):
|
|
8
|
+
self.path = path
|
|
9
|
+
self.md_files = [[str(p), []] for p in Path(self.path).rglob("*.md")]
|
|
10
|
+
# Reads all Files in CWD
|
|
11
|
+
|
|
12
|
+
def Read_file(self, file):
|
|
13
|
+
if isinstance(file, int):
|
|
14
|
+
file_index = file
|
|
15
|
+
elif isinstance(file, str):
|
|
16
|
+
try:
|
|
17
|
+
file_index = next(i for i, v in enumerate(self.md_files) if v[0] == file)
|
|
18
|
+
except StopIteration:
|
|
19
|
+
raise ValueError(f"File '{file}' not found in md_files")
|
|
20
|
+
else:
|
|
21
|
+
raise TypeError("file parameter must be an int (index) or str (path)")
|
|
22
|
+
|
|
23
|
+
with open(self.md_files[file_index][0], 'r') as f:
|
|
24
|
+
a = f.read()
|
|
25
|
+
|
|
26
|
+
links = re.findall(r'\[\[(.*?)\]\]', a)
|
|
27
|
+
self.md_files[file_index][1] = links
|
|
28
|
+
|
|
29
|
+
def Make_Graph(self):
|
|
30
|
+
net = Network(directed=False, cdn_resources='remote')
|
|
31
|
+
|
|
32
|
+
for file_info in self.md_files:
|
|
33
|
+
file_path = file_info[0]
|
|
34
|
+
node_id = Path(file_path).stem
|
|
35
|
+
file_name = Path(file_path).name
|
|
36
|
+
net.add_node(node_id, label=file_name, title=file_name)
|
|
37
|
+
|
|
38
|
+
for file_info in self.md_files:
|
|
39
|
+
file_path = file_info[0]
|
|
40
|
+
links = file_info[1]
|
|
41
|
+
source_id = Path(file_path).stem
|
|
42
|
+
|
|
43
|
+
for link in links:
|
|
44
|
+
target_id = link.split("|")[0].strip()
|
|
45
|
+
if target_id not in net.get_nodes():
|
|
46
|
+
net.add_node(target_id, label=f"{target_id}.md", title=f"{target_id}.md", color="red")
|
|
47
|
+
net.add_edge(source_id, target_id)
|
|
48
|
+
|
|
49
|
+
temp_path = str(Path(tempfile.gettempdir()) / 'wiki_graph.html')
|
|
50
|
+
net.show(temp_path, notebook=False)
|
|
51
|
+
return temp_path
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
import sys
|
|
55
|
+
path = sys.argv[1] if len(sys.argv) > 1 else "."
|
|
56
|
+
reader = File_Reader(path)
|
|
57
|
+
|
|
58
|
+
for i in range(len(reader.md_files)):
|
|
59
|
+
reader.Read_file(i)
|
|
60
|
+
|
|
61
|
+
out_path = reader.Make_Graph()
|
|
62
|
+
print(out_path)
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
main()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wikilinksgraph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pyvis
|
|
8
|
+
|
|
9
|
+
# Wiki-Links-Tree
|
|
10
|
+
Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
wikilinksgraph/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
wikilinksgraph/main.py,sha256=DlA8DAfQvWRatC_q9cRdabMXY_tW89V7HCKbPDOIRrM,2167
|
|
3
|
+
wikilinksgraph-0.1.0.dist-info/METADATA,sha256=cZyOKnBeA0qyLBsxUOw9VC0cfyLvQHcSSEG56HLHE-I,450
|
|
4
|
+
wikilinksgraph-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
wikilinksgraph-0.1.0.dist-info/entry_points.txt,sha256=hF11_MsY29xdsSmhD8vrgekLyIsQS1jdTvJoluncT4k,91
|
|
6
|
+
wikilinksgraph-0.1.0.dist-info/top_level.txt,sha256=i_aqigGFXTH5c4s7yf5Y6dl3rHChenUODioz5kRmuic,15
|
|
7
|
+
wikilinksgraph-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wikilinksgraph
|