Advertisement
LukeSavefrogs

Untitled

Jun 9th, 2023 (edited)
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. class Database:
  2.     def __init__(self, file_name: str):
  3.         self.database = file_name
  4.         with open(file_name, "w") as file:
  5.             json.dump({"word": {}, "wordr": {}, "sticker": False, "animati": {}, "media": {}}, file)
  6.  
  7.     async def save(self, update: dict):
  8.         with open(self.database, "w") as f:
  9.             json.dump(update, f)
  10.            
  11.     async def load(self):
  12.         with open(self.database, "r") as f:
  13.             return json.load(f)
  14.  
  15.     async def add_word(self, word: str, risposta: str):
  16.         update = self.load()
  17.         update["word"][str(word)] = risposta
  18.         await self.save(update)
  19.         return risposta
  20.  
  21.     async def add_wordr(self, word: str, risposta: str):
  22.         update = self.load()
  23.         update["wordr"][str(word)] = risposta
  24.         await self.save(update)
  25.         return risposta
  26.  
  27.     async def add_word_media(self, word: str, risposta):
  28.         update = self.load()
  29.         update["media"][str(word)] = risposta
  30.         await self.save(update)
  31.         return risposta
  32.  
  33.     async def add_word_animate(self, word: str, risposta: list):
  34.         update = self.load()
  35.         update["animati"][str(word)] = risposta
  36.         await self.save(update)
  37.         return risposta
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement