Skip to content

Instantly share code, notes, and snippets.

@leplatrem
Created September 27, 2018 17:45
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 leplatrem/5193f85849a887dfb97429a4bbae3cc7 to your computer and use it in GitHub Desktop.
Save leplatrem/5193f85849a887dfb97429a4bbae3cc7 to your computer and use it in GitHub Desktop.
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