Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import os
import requests
import kinto_http
ACCESS_TOKEN = os.getenv("TOKEN", "")
SERVER = os.getenv("SERVER", "https://settings-writer.stage.mozaws.net/v1")
DICT_URL = os.getenv("SOURCE", "https://github.com/mozilla-l10n/firefox-dictionaries/raw/master/output/dictionaries_minimal.json")
DOC_URL = "https://remote-settings.readthedocs.io/en/latest/frequently-asked-questions.html#how-do-i-automate-the-publication-of-records"
resp = requests.get(DICT_URL)
dictionaries = resp.json()
class OpenIDConnect(requests.auth.AuthBase):
def __call__(self, r):
r.headers["Authorization"] = "Bearer %s" % ACCESS_TOKEN
return r
client = kinto_http.Client(
server_url=SERVER,
bucket="main-workspace",
collection="language-dictionaries",
auth=OpenIDConnect(),
)
if not ACCESS_TOKEN or "user" not in client.server_info():
raise ValueError("TOKEN env value '%s' is not a valid access token. See %s" % (ACCESS_TOKEN, DOC_URL))
with client.batch() as batch:
for lang, dictionaries in dictionaries.items():
batch.create_record(data=dict(id=lang, dictionaries=dictionaries))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.