"""
Reads app list from awesome-privacy.yml,
formats into markdown, and inserts into README.md
"""
import os
import re
import yaml
import logging
from urllib.parse import urlparse, quote
# Configure Logging
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper()
logging.basicConfig(level=LOG_LEVEL)
logger = logging.getLogger(__name__)
# Determine the project root based on the script's location
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
app_list_file_path = os.path.join(project_root, 'awesome-privacy.yml')
readme_path = os.path.join(project_root, '.github/README.md')
icon_size=16
# Read the main YAML file, where all data lives
logger.info("Reading the awesome-privacy file...")
with open(app_list_file_path, 'r') as file:
data = yaml.safe_load(file)
def iconElement(serviceUrl, serviceIcon):
path = serviceIcon or f"https://icon.horse/icon/{urlparse(serviceUrl).netloc}"
return f""
def repoElement(repoUrl):
if not repoUrl:
return ""
return (
f"[[1]}"
"&color=%235f53f4&cacheSeconds=3600)]"
f"(https://github.com/{repoUrl})"
)
def tosElement(tosdrId):
if not tosdrId:
return ""
return f"[](https://tosdr.org/en/service/{tosdrId})"
def statsElement(app, categoryName, sectionName):
statsStr = ""
if app.get('openSource') == True:
github = app.get('github')
if github:
link = f"https://github.com/{github}"
elif app.get('url'):
link = app.get('url')
else:
link = f"https://awesome-privacy.xyz/{slugify(categoryName)}/{slugify(sectionName)}/{slugify(app.get('name'))}"
statsStr += (
f"[]({link}) "
)
if app.get('securityAudited') == True:
statsStr += (
" "
)
if app.get('acceptsCrypto') == True:
statsStr += (
" "
)
return statsStr
def slugify(title):
if not title:
return ''
title = title.lower()
title = re.sub(r'\s+', '-', title)
title = re.sub(r'\+|&', 'and', title)
title = title.replace('?', '')
return title
def shieldsEncode(text):
if not text: return ''
text = text.strip().replace('-', '--').replace('_', '__').replace(' ', '_')
return quote(text, safe='_-.')
def awesomePrivacyReport(categoryName, sectionName, serviceName):
if not serviceName:
return ""
return (
f"[![{serviceName} on Awesome Privacy]"
f"(https://img.shields.io/badge/View%20Report-FC60A8?style=flat&logo=awesomelists&label={serviceName.replace(' ', '_')})]"
f"(https://awesome-privacy.xyz/{slugify(categoryName)}/{slugify(sectionName)}/{slugify(serviceName)})"
)
def playStoreBadge(name, androidApp):
if not androidApp: return ""
encoded = shieldsEncode(name)
return (
f"[]"
f"(https://play.google.com/store/apps/details?id={androidApp}) "
)
def appStoreBadge(name, iosApp):
if not iosApp: return ""
encoded = shieldsEncode(name)
return (
f"[]"
f"({iosApp}) "
)
def redditBadge(subreddit):
if not subreddit or not subreddit.strip(): return ""
sub = subreddit.strip()
return (
f"[]"
f"(https://reddit.com/r/{sub}) "
)
def discordBadge(name, discordInvite):
if not discordInvite or not discordInvite.strip(): return ""
invite = discordInvite.strip()
encoded = shieldsEncode(name)
link = invite if invite.startswith('https://') else f"https://discord.gg/{invite}"
return (
f"[]"
f"({link}) "
)
_MD_PATTERNS = [
re.compile(r'\[([^\]]*)\]\([^)]*\)'), # [text](url) — group 1 = visible text
re.compile(r'\*\*(.+?)\*\*'), # **bold**
re.compile(r'`([^`]+)`'), # `code`
re.compile(r'(?
📋 Contents
\n"
for category in data.get('categories'):
contents += f"\n- **{category.get('name')}**"
for section in category.get('sections'):
if (len(section.get('services') or []) > 0):
contents += (
f"\n\t- [{section.get('name')}](#{makeHref(section.get('name'))}) "
f"({len(section.get('services') or [])})"
)
contents += "\n
"
"⚠️ This section is still a work in progress ⚠️
"
"Check back soon, or help us complete it by submitting a pull request"
"