コード例 #1
0
ファイル: main.py プロジェクト: j-rogers/pbabot
 def save_data(self):
     """Dumps data structures to JSON files"""
     with open(f'{self.data_file}/clocks.json', 'wb') as file:
         file.write(jsons.dumpb(self.clocks))
     with open(f'{self.data_file}/contacts.json', 'wb') as file:
         file.write(jsons.dumpb(self.contacts))
     with open(f'{self.data_file}/memories.json', 'wb') as file:
         file.write(jsons.dumpb(self.memories))
     with open(f'{self.data_file}/dead_characters.json', 'wb') as file:
         file.write(jsons.dumpb(self.dead_characters))
コード例 #2
0
    def test_dumpb(self):
        class A:
            def __init__(self):
                self.name = 'A'

        class B:
            def __init__(self, a: A):
                self.a = a
                self.name = 'B'

        dumped = jsons.dumpb(B(A()), jdkwargs={'sort_keys': True})
        b = json.dumps({
            'a': {
                'name': 'A'
            },
            'name': 'B'
        }, sort_keys=True).encode()
        self.assertEqual(b, dumped)
コード例 #3
0
ファイル: pickle_to_json.py プロジェクト: j-rogers/pbabot
"""Pickle2Json

Converts old pickled data into the newer JSON format

Author: Josh Rogers (2021)
"""
from pbabot.main import Clock, Contact
import pickle
import jsons

try:
    with open('data.pickle', 'rb') as file:
        pickled_data = pickle.loads(file)
except FileNotFoundError:
    print('Pickled data not found.')
else:
    with open('clocks.json', 'wb') as file:
        file.write(jsons.dumpb(pickled_data['clocks']))
    with open('contacts.json', 'wb') as file:
        file.write(jsons.dumpb(pickled_data['contacts']))
    with open('memories.json', 'wb') as file:
        file.write(jsons.dumpb(pickled_data['memories']))
    with open('/dead_characters.json', 'wb') as file:
        file.write(jsons.dumpb(pickled_data['dead_characters']))
コード例 #4
0
ファイル: manager.py プロジェクト: NERD-ALMATY/sicp-bot
 def _rewrite_db(self):
     self._db.put(self._list_name, jsons.dumpb(self))
コード例 #5
0
 def encode(self):
     return jsons.dumpb(self)