Browse Source

Order JSON config import

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

Change-Id: I27ffb63de17606893779c7c4c002aee15d7b56e0
changes/11/653411/1
Thierry Carrez 2 years ago
parent
commit
ed359e957a
2 changed files with 5 additions and 5 deletions
  1. +1
    -2
      ptgbot/bot.py
  2. +4
    -3
      ptgbot/db.py

+ 1
- 2
ptgbot/bot.py View File

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


+ 4
- 3
ptgbot/db.py View File

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


Loading…
Cancel
Save