Skip to content

Instantly share code, notes, and snippets.

View flodolo's full-sized avatar

Francesco Lodolo flodolo

View GitHub Profile
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
from fluent.migrate.helpers import transforms_from
from fluent.migrate.transforms import TransformPattern
import fluent.syntax.ast as FTL
class REPLACE_TOTAL(TransformPattern):
def visit_TextElement(self, node):
@flodolo
flodolo / extract_hg_changesets.py
Last active January 27, 2025 12:45
Script to extract l10n builds changeset for Firefox 68–127
import json
import requests
base_url = "https://product-details.mozilla.org/1.0/l10n/"
changesets = {}
for version in range(68, 128):
version_str = f"{version}.0"
for build_number in range(1, 6):
@flodolo
flodolo / minimize_fontawesome.py
Created January 5, 2025 06:54
Pontoon: minimize Font Awesome
#! /usr/bin/env python
"""
The script looks for TTF fonts in FontAwesome folder. It doesn't use WOFF2
directly, because glyph names seem to be unreliable.
Optimized fonts are saved in `/pontoon/base/static/fonts/` as WOFF2.
The list of possible icons is done searching for `fa-*` in specific files (HTML,
@flodolo
flodolo / analyze.py
Created January 2, 2025 06:43
Pontoon: analyze search options in Heroku logs
#! /usr/bin/env python
import glob
import json
# Find all .json files in logs/
json_files = glob.glob("logs/*.json")
json_files.sort()
@flodolo
flodolo / extract.py
Created November 8, 2024 06:39
Extract spotlight completion
import json
from urllib.request import urlopen
string_ids = [
"browser/browser/newtab/asrouter.ftl:device-migration-fxa-spotlight-sync-body",
"browser/browser/newtab/asrouter.ftl:device-migration-fxa-spotlight-sync-header",
"browser/browser/newtab/asrouter.ftl:device-migration-fxa-spotlight-sync-primary-button",
]
locales = {}
@flodolo
flodolo / amo_localization_data.py
Last active September 16, 2024 18:21
AMO locales data
#!/usr/bin/env python3
import json
import re
import sys
from urllib.parse import quote as urlquote
from urllib.request import urlopen
def main():
@flodolo
flodolo / test.py
Created September 12, 2024 11:16
Test python-levenshtein vs RapidFuzz
import Levenshtein
from rapidfuzz.distance import Indel
sentence_pairs = (
("The sky is blue.", "It looks like rain."),
("I love reading books.", "My favorite genre is fantasy."),
("She enjoys playing piano.", "He prefers the guitar."),
("Coffee wakes me up.", "Tea relaxes me."),
("We are going to the park.", "They are staying home."),
("The dog barked loudly.", "The cat quietly meowed."),
@flodolo
flodolo / check_heroku.py
Created August 28, 2024 13:28
Check Heroku log for IPs
import re
import sys
if len(sys.argv) == 1:
sys.exit("Provide the log file as an argument")
ips = {}
filter = re.compile(r"fwd=\"([\d.]+)\"")
threshold = 10
# Copy from Heroku settings
@flodolo
flodolo / check_survey.py
Last active February 15, 2024 06:30
Check survey files exported from Smartling
from glob import glob
import csv
import os
import re
import sys
# Pass a path as an argument, the script will go through all .csv files included.
if len(sys.argv) < 2:
sys.exit("Missing path argument")
path = os.path.abspath(sys.argv[1])
@flodolo
flodolo / phabricator_query.py
Last active January 24, 2024 20:18
Query reviews on phabricator
#!/usr/bin/env python3
import argparse
import datetime
import json
import urllib.parse as url_parse
import urllib.request as url_request
from collections import defaultdict
api_token = "TOKEN"