Created
September 27, 2018 17:45
-
-
Save leplatrem/5193f85849a887dfb97429a4bbae3cc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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