-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathword_cloud_generator.py
More file actions
56 lines (38 loc) · 1.5 KB
/
Copy pathword_cloud_generator.py
File metadata and controls
56 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! python3 # noqa: E265
# ############################################################################
# ########## Libraries #############
# ##################################
# standard lib
import logging
from collections import Counter
from pathlib import Path
# 3rd party
import matplotlib.pyplot as plt
from mkdocs.utils.meta import get_data
from wordcloud import WordCloud
# ###########################################################################
# ########## Global ################
# ##################################
logger = logging.getLogger("mkdocs")
content_types: tuple[str] = ("articles", "rdp")
content_tags: list[str] = []
# ###########################################################################
# ########## Main ##################
# ##################################
for content_type in content_types:
for content in Path(f"content/{content_type}/").glob("**/*.md"):
if content.parent.is_dir() and content.parent.name == "templates":
continue
with content.open(encoding="utf-8-sig", errors="strict") as f:
source = f.read()
page_meta = get_data(source)[1]
if page_tags := page_meta.get("tags"):
content_tags.extend(page_tags)
tags_freq = Counter(content_tags)
wordcloud = WordCloud(width=1000, height=500).generate_from_frequencies(tags_freq)
plt.figure(figsize=(15, 8))
# display and show "wc"
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.title("Mots-clés sur Geotribu", fontsize=13)
plt.show()