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 @@
1""" 1"""
2Reads app list from awesome-privacy.yml, 2Reads app list from awesome-privacy.yml,
3formats into markdown, and inserts into README.md 3formats into markdown, and inserts into README.md
4""" 4"""
5 5
6import os 6import os
7import re 7import re
8import yaml 8import yaml
9import logging 9import logging
10from urllib.parse import urlparse 10from urllib.parse import urlparse, quote
11 11
12# Configure Logging 12# Configure Logging
13LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper() 13LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper()
@@ -44,14 +44,32 @@ def tosElement(tosdrId):
44 return "" 44 return ""
45 return f"[![Privacy Policy](https://shields.tosdr.org/en_{tosdrId}.svg)](https://tosdr.org/en/service/{tosdrId})" 45 return f"[![Privacy Policy](https://shields.tosdr.org/en_{tosdrId}.svg)](https://tosdr.org/en/service/{tosdrId})"
46 46
47def statsElement(isOpenSource, isSecurityAudited, isAcceptsCrypto): 47def statsElement(app, categoryName, sectionName):
48 statsStr = "" 48 statsStr = ""
49 if isOpenSource == True: 49 if app.get('openSource') == True:
50 statsStr += "📦 Open Source " 50 github = app.get('github')
51 if isSecurityAudited == True: 51 if github:
52 statsStr += "🛡️ Security Audited " 52 link = f"https://github.com/{github}"
53 if isAcceptsCrypto == True: 53 elif app.get('url'):
54 statsStr += "💰 Accepts Anonymous Payment " 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 )
55 return statsStr 73 return statsStr
56 74
57def slugify(title): 75def slugify(title):
@@ -63,6 +81,11 @@ def slugify(title):
63 title = title.replace('?', '') 81 title = title.replace('?', '')
64 return title 82 return title
65 83
84def shieldsEncode(text):
85 if not text: return ''
86 text = text.strip().replace('-', '--').replace('_', '__').replace(' ', '_')
87 return quote(text, safe='_-.')
88
66def awesomePrivacyReport(categoryName, sectionName, serviceName): 89def awesomePrivacyReport(categoryName, sectionName, serviceName):
67 if not serviceName: 90 if not serviceName:
68 return "" 91 return ""
@@ -72,12 +95,74 @@ def awesomePrivacyReport(categoryName, sectionName, serviceName):
72 f"(https://awesome-privacy.xyz/{slugify(categoryName)}/{slugify(sectionName)}/{slugify(serviceName)})" 95 f"(https://awesome-privacy.xyz/{slugify(categoryName)}/{slugify(sectionName)}/{slugify(serviceName)})"
73 ) 96 )
74 97
75def makeStatsCard(): 98def playStoreBadge(name, androidApp):
76 return ( 99 if not androidApp: return ""
77 f"\t- <details><summary>Stats</summary>\n\n" 100 encoded = shieldsEncode(name)
78 f"" 101 return (
79 f"\n\n</details>" 102 f"[![{name} on Google Play](https://img.shields.io/badge/-{encoded}-3bd47f"
80 ) 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
81 166
82def makeHref(text): 167def makeHref(text):
83 if not text: return "#" 168 if not text: return "#"
@@ -116,21 +201,32 @@ def makeAwesomePrivacy():
116 ) 201 )
117 # For each service, list it's name, icon, url, and description 202 # For each service, list it's name, icon, url, and description
118 for app in section.get('services') or []: 203 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 ""
119 markdown += ( 210 markdown += (
120 f"- **[{iconElement(app.get('url'), app.get('icon'))} {app.get('name')}]" 211 f"- **[{iconElement(app.get('url'), app.get('icon'))} {app.get('name')}]"
121 f"({app.get('url')})** - {app.get('description')}" 212 f"({app.get('url')})** - {description}{ellipsis} \n"
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 '')
133 ) 213 )
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 )
134 markdown += "\n" 230 markdown += "\n"
135 # If word of warning exists, append it 231 # If word of warning exists, append it
136 if section.get('wordOfWarning'): 232 if section.get('wordOfWarning'):
@@ -145,7 +241,7 @@ def makeAwesomePrivacy():
145 markdown += f"> - [{mention.get('name')}]({mention.get('url')})" + ( 241 markdown += f"> - [{mention.get('name')}]({mention.get('url')})" + (
146 f" - {mention.get('description')}" if mention.get('description') else "\n" 242 f" - {mention.get('description')}" if mention.get('description') else "\n"
147 ) 243 )
148 else: 244 else:
149 notable_mentions = section.get('notableMentions').replace('\n', '\n> ') 245 notable_mentions = section.get('notableMentions').replace('\n', '\n> ')
150 markdown += f"> {notable_mentions}" 246 markdown += f"> {notable_mentions}"
151 247
@@ -170,7 +266,7 @@ def update_content_between_markers(content, start_marker, end_marker, new_conten
170 logger.info(f"Updating content between {start_marker} and {end_marker} markers...") 266 logger.info(f"Updating content between {start_marker} and {end_marker} markers...")
171 start_index = content.find(start_marker) 267 start_index = content.find(start_marker)
172 end_index = content.find(end_marker) 268 end_index = content.find(end_marker)
173 269
174 if start_index != -1 and end_index != -1: 270 if start_index != -1 and end_index != -1:
175 before_section = content[:start_index + len(start_marker)] 271 before_section = content[:start_index + len(start_marker)]
176 after_section = content[end_index:] 272 after_section = content[end_index:]