Skip to content

Instantly share code, notes, and snippets.

@Sancus
Created April 8, 2022 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sancus/58c7a4c5174eab3b513f7a9c876a17b5 to your computer and use it in GitHub Desktop.
Save Sancus/58c7a4c5174eab3b513f7a9c876a17b5 to your computer and use it in GitHub Desktop.
Upload language packs to addons.thunderbird.net
import datetime
import glob
import jwt
import random
import requests
import string
import time
from pathlib import Path
# Example download command:
# wget --no-parent -rnH --cut-dirs=6 -R "index.html" https://ftp.mozilla.org/pub/thunderbird/candidates/91.0-candidates/build1/linux-x86_64/xpi/
# key is user:7digits:3digits
api_key = ""
api_secret = ""
# langpack version directly from the manifest, should be the same for all languages.
version = "91.0buildid20220401203107"
# upload url including the GUID and langpack version.
url = "https://addons.thunderbird.net/api/v3/addons/langpack-{langcode}@thunderbird.mozilla.org/versions/{version}/"
xpi_folder = 'xpi'
for filepath in glob.glob(xpi_folder + '/*'):
langcode = Path(filepath).stem
now = datetime.datetime.utcnow()
payload = {
"iss": api_key,
"jti": ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(64)),
"exp": now + datetime.timedelta(seconds=60),
"iat": now
}
header = "Authorization: JWT {0}".format(jwt.encode(payload, api_secret, algorithm="HS256"))
headers = {'Authorization': 'JWT {0}'.format(jwt.encode(payload, api_secret, algorithm="HS256"))}
file = {'upload': ('upload', open(xpi_folder + '/' + langcode +'.xpi', 'rb'))}
response = requests.put(url.format(version=version, langcode=langcode), files=file, headers=headers)
print(response.text)
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment