Order JSON config import

We should also retain order when importing JSON from a URL.

Change-Id: I27ffb63de17606893779c7c4c002aee15d7b56e0
This commit is contained in:
Thierry Carrez 2019-04-17 13:45:37 +02:00
parent 98811703f6
commit ed359e957a
2 changed files with 5 additions and 5 deletions

View File

@ -22,7 +22,6 @@ import irc.bot
import json import json
import logging.config import logging.config
import os import os
import requests
import time import time
import textwrap import textwrap
@ -177,7 +176,7 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot):
url = words[1] url = words[1]
self.send(chan, "Loading DB from %s ..." % url) self.send(chan, "Loading DB from %s ..." % url)
try: try:
self.data.import_json(requests.get(url).json()) self.data.import_json(url)
self.send(chan, "Done.") self.send(chan, "Done.")
except Exception as e: except Exception as e:
self.send(chan, "Error loading DB: %s" % e) self.send(chan, "Error loading DB: %s" % e)

View File

@ -19,6 +19,7 @@ import datetime
import json import json
import os import os
import random import random
import requests
class PTGDataBase(): class PTGDataBase():
@ -45,9 +46,9 @@ class PTGDataBase():
self.save() self.save()
def import_json(self, jsondata): def import_json(self, url):
# Update the DB with the data found in the provided JSON # Update the DB with the JSON data found at URL
self.data.update(jsondata) self.data.update(requests.get(url).json(object_pairs_hook=OrderedDict))
# Add tracks mentioned in configuration that are not in track list # Add tracks mentioned in configuration that are not in track list
for room, bookings in self.data['schedule'].items(): for room, bookings in self.data['schedule'].items():