I am currently in a dilemma. I am thinking about downloading a JSON file from a GitHub repo to replace local files. The local files are stored in a folder named
lang, which is stored in the project folder. The repo is stored on GitHub and can be accessed using a URL.
The GitHub solution, in my opinion, would be good so that I could push automatic updates (our clients want strings) to local projects. Only the language needed would be downloaded as well, and would download every 30 minutes, on startup, and via a custom function. Plus, I could code in a manual override so you can supply your own ones as well. Here's the code for the GitHub solution:
def get_jsonparsed_data(url): response = urllib.request.urlopen(url) data = response.read().decode("utf-8") return json.loads(data) if MESSAGE_LANGUAGE in get_jsonparsed_data("https://raw.githubusercontent.com/user/repo/master/languages.json")['languages']: url = ("https://raw.githubusercontent.com/user/repo/master/" + MESSAGE_LANGUAGE + ".json") else: url = ("https://raw.githubusercontent.com/user/repo/master/lang.json") lang = get_jsonparsed_data(url)
On the other hand, locally storing it will make it easier to edit while harder to update.
Here's the code for this as well:
if os.path.isfile('./lang/' + MESSAGE_LANGUAGE + '.json'): with open('lang/' + MESSAGE_LANGUAGE + '.json') as data_file: lang = json.load(data_file) else: with open('lang/en.json') as data_file: lang = json.load(data_file)
Which one would be better to use, and why?