1

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.

An example tree inside the root folder, on the same level as the script.

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?

  • For clarity: You don't want to do this manually. You want to code this functionality into your application and are wondering if it's an acceptable solution? – MetaFight Jan 15 '17 at 14:07
  • @MetaFight Exactly. The project is on GitHub, with the lang files already included, but I was wondering if it's acceptable to just pull them from GitHub to keep them fresh. – haykam Jan 15 '17 at 14:08
  • 1
    This sounds suspiciously like abusing GitHub as a content delivery network – why not use your own server? There seems to be something missing in your question. In particular you ask “which one is better” but have provided only a single suggestion. Please add more information to make this answerable. – amon Jan 15 '17 at 15:12
  • @amon It's local vs. loading from the repo. – haykam Jan 15 '17 at 15:32
  • 1
    Your question is currently difficult to understand. Could you rewrite it taking these comments into consideration? Explain your problem, list the options you're considering, and tell us which option you think is best (and why). – MetaFight Jan 15 '17 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.