Commit 3da9abf4d5

3da9abf4d5c2f7f1421ae654ddfa780bf0d35275

parent: 9c43baa1bc

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-02-26 16:06 UTC

Updates script what generates the readme

Layout: unified · split

lib/awesome-privacy-readme-gen.py +125 −29
@@ -1,13 +1,13 @@
11"""
22Reads app list from awesome-privacy.yml,
3formats into markdown, and inserts into README.md
3formats into markdown, and inserts into README.md
44"""
55
66import os
77import re
88import yaml
99import logging
10from urllib.parse import urlparse
10from urllib.parse import urlparse, quote
1111
1212# Configure Logging
1313LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper()
@@ -44,14 +44,32 @@ def tosElement(tosdrId):
4444 return ""
4545 return f"[![Privacy Policy](https://shields.tosdr.org/en_{tosdrId}.svg)](https://tosdr.org/en/service/{tosdrId})"
4646
47def statsElement(isOpenSource, isSecurityAudited, isAcceptsCrypto):
47def statsElement(app, categoryName, sectionName):
4848 statsStr = ""
49 if isOpenSource == True:
50 statsStr += "📦 Open Source "
51 if isSecurityAudited == True:
52 statsStr += "🛡️ Security Audited "
53 if isAcceptsCrypto == True:
54 statsStr += "💰 Accepts Anonymous Payment "
49 if app.get('openSource') == True:
50 github = app.get('github')
51 if github:
52 link = f"https://github.com/{github}"
53 elif app.get('url'):
54 link = app.get('url')
55 else:
56 link = f"https://awesome-privacy.xyz/{slugify(categoryName)}/{slugify(sectionName)}/{slugify(app.get('name'))}"
57 statsStr += (
58 f"[![Open Source](https://img.shields.io/badge/-Open_Source-3DA639"
59 f"?style=flat&logo=opensourceinitiative&logoColor=white)]({link}) "
60 )
61 if app.get('securityAudited') == True:
62 statsStr += (
63 "![Security Audited](https://img.shields.io/badge/-Security_Audited-3DA639"
64 "?style=flat&logo=data:image/svg+xml;base64,"
65 "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0xMiAxTDMgNXY2YzAgNS41NSAzLjg0IDEwLjc0IDkgMTIgNS4xNi0xLjI2IDktNi40NSA5LTEyVjVsLTktNHoiLz48L3N2Zz4="
66 "&logoColor=white) "
67 )
68 if app.get('acceptsCrypto') == True:
69 statsStr += (
70 "![Accepts Anonymous Payment](https://img.shields.io/badge/-Anon_Payment_Accepted"
71 "%EF%B8%8F-3DA639?style=flat&logo=bitcoincash&logoColor=white) "
72 )
5573 return statsStr
5674
5775def slugify(title):
@@ -63,6 +81,11 @@ def slugify(title):
6381 title = title.replace('?', '')
6482 return title
6583
84def shieldsEncode(text):
85 if not text: return ''
86 text = text.strip().replace('-', '--').replace('_', '__').replace(' ', '_')
87 return quote(text, safe='_-.')
88
6689def awesomePrivacyReport(categoryName, sectionName, serviceName):
6790 if not serviceName:
6891 return ""
@@ -72,12 +95,74 @@ def awesomePrivacyReport(categoryName, sectionName, serviceName):
7295 f"(https://awesome-privacy.xyz/{slugify(categoryName)}/{slugify(sectionName)}/{slugify(serviceName)})"
7396 )
7497
75def makeStatsCard():
76 return (
77 f"\t- <details><summary>Stats</summary>\n\n"
78 f""
79 f"\n\n</details>"
80 )
98def playStoreBadge(name, androidApp):
99 if not androidApp: return ""
100 encoded = shieldsEncode(name)
101 return (
102 f"[![{name} on Google Play](https://img.shields.io/badge/-{encoded}-3bd47f"
103 f"?style=flat&logo=android&logoColor=white)]"
104 f"(https://play.google.com/store/apps/details?id={androidApp}) "
105 )
106
107def appStoreBadge(name, iosApp):
108 if not iosApp: return ""
109 encoded = shieldsEncode(name)
110 return (
111 f"[![{name} on App Store](https://img.shields.io/badge/-{encoded}-0D96F6"
112 f"?style=flat&logo=appstore&logoColor=white)]"
113 f"({iosApp}) "
114 )
115
116def redditBadge(subreddit):
117 if not subreddit or not subreddit.strip(): return ""
118 sub = subreddit.strip()
119 return (
120 f"[![r/{sub} on Reddit](https://img.shields.io/badge/-{sub}-FF4500"
121 f"?style=flat&logo=reddit&logoColor=white)]"
122 f"(https://reddit.com/r/{sub}) "
123 )
124
125def discordBadge(name, discordInvite):
126 if not discordInvite or not discordInvite.strip(): return ""
127 invite = discordInvite.strip()
128 encoded = shieldsEncode(name)
129 link = invite if invite.startswith('https://') else f"https://discord.gg/{invite}"
130 return (
131 f"[![{name} on Discord](https://img.shields.io/badge/-{encoded}-5865F2"
132 f"?style=flat&logo=discord&logoColor=white)]"
133 f"({link}) "
134 )
135
136_MD_PATTERNS = [
137 re.compile(r'\[([^\]]*)\]\([^)]*\)'), # [text](url) — group 1 = visible text
138 re.compile(r'\*\*(.+?)\*\*'), # **bold**
139 re.compile(r'`([^`]+)`'), # `code`
140 re.compile(r'(?<!\*)\*([^*]+)\*(?!\*)'), # *italic*
141]
142
143def truncateMarkdown(text, maxLen=200):
144 """Returns (truncated_text, was_truncated) preserving markdown constructs."""
145 if len(text) <= maxLen:
146 return text, False
147
148 result = []
149 visible = 0
150 i = 0
151
152 while i < len(text) and visible < maxLen:
153 for pattern in _MD_PATTERNS:
154 m = pattern.match(text, i)
155 if m:
156 result.append(m.group(0))
157 visible += len(m.group(1))
158 i = m.end()
159 break
160 else:
161 result.append(text[i])
162 visible += 1
163 i += 1
164
165 return ''.join(result).rstrip(), True
81166
82167def makeHref(text):
83168 if not text: return "#"
@@ -116,21 +201,32 @@ def makeAwesomePrivacy():
116201 )
117202 # For each service, list it's name, icon, url, and description
118203 for app in section.get('services') or []:
204 description, was_truncated = truncateMarkdown(app.get('description', ''))
205 ap_link = (
206 f"https://awesome-privacy.xyz/"
207 f"{slugify(category.get('name'))}/{slugify(section.get('name'))}/{slugify(app.get('name'))}"
208 )
209 ellipsis = f"[…]({ap_link} \"View full {app.get('name')} report\")" if was_truncated else ""
119210 markdown += (
120211 f"- **[{iconElement(app.get('url'), app.get('icon'))} {app.get('name')}]"
121 f"({app.get('url')})** - {app.get('description')}"
122 f"[…](https://awesome-privacy.xyz/"
123 f"{slugify(category.get('name'))}/{slugify(section.get('name'))}/{slugify(app.get('name'))} \"View full {app.get('name')} report\") \n"
124 + ((
125 f"\t- <details>\n\t\t<summary>Stats</summary>\n\n\t\t"
126 f"{repoElement(app.get('github'))} "
127 f"{tosElement(app.get('tosdrId'))} "
128 f"{awesomePrivacyReport(category.get('name'), section.get('name'), app.get('name'))} \n"
129 f"{statsElement(app.get('openSource'), app.get('securityAudited'), app.get('acceptsCrypto'))}˙ \n"
130 f"\n\t\t</details>\n"
131 )
132 if app.get('github') or app.get('tosdrId') else '')
212 f"({app.get('url')})** - {description}{ellipsis} \n"
133213 )
214 badges = ' '.join(filter(None, [
215 repoElement(app.get('github')),
216 tosElement(app.get('tosdrId')),
217 awesomePrivacyReport(category.get('name'), section.get('name'), app.get('name')),
218 statsElement(app, category.get('name'), section.get('name')).rstrip(),
219 playStoreBadge(app.get('name'), app.get('androidApp')).rstrip(),
220 appStoreBadge(app.get('name'), app.get('iosApp')).rstrip(),
221 redditBadge(app.get('subreddit')).rstrip(),
222 discordBadge(app.get('name'), app.get('discordInvite')).rstrip(),
223 ]))
224 if badges:
225 markdown += (
226 f"\t- <details>\n\t\t<summary>Stats</summary>\n\n\t\t"
227 f"{badges}ㅤ \n"
228 f"\n\t\t</details>\n"
229 )
134230 markdown += "\n"
135231 # If word of warning exists, append it
136232 if section.get('wordOfWarning'):
@@ -145,7 +241,7 @@ def makeAwesomePrivacy():
145241 markdown += f"> - [{mention.get('name')}]({mention.get('url')})" + (
146242 f" - {mention.get('description')}" if mention.get('description') else "\n"
147243 )
148 else:
244 else:
149245 notable_mentions = section.get('notableMentions').replace('\n', '\n> ')
150246 markdown += f"> {notable_mentions}"
151247
@@ -170,7 +266,7 @@ def update_content_between_markers(content, start_marker, end_marker, new_conten
170266 logger.info(f"Updating content between {start_marker} and {end_marker} markers...")
171267 start_index = content.find(start_marker)
172268 end_index = content.find(end_marker)
173
269
174270 if start_index != -1 and end_index != -1:
175271 before_section = content[:start_index + len(start_marker)]
176272 after_section = content[end_index:]