Skip to content

Commit

Permalink
برمجة تصدير البيانات إلى صيغة json في نموذج قواعد البيانات
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Nov 18, 2024
1 parent 8359a5a commit 7c3aebc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return float(obj)
elif isinstance(obj, datetime.datetime):
return obj.isoformat()
elif isinstance(obj, Account):
return obj.to_dict()
elif obj.__class__.__name__ == "QueryResult":
x = []
for y in x:
x.append(y.to_dict())
return x
return super().default(obj)


Expand Down Expand Up @@ -3564,7 +3573,12 @@ def daily_logs(self, weekday: WeekDay = WeekDay.Friday, debug: bool = False):
}

def export_json(self, path: str = "data.json") -> bool:
pass
with open(path, "w") as file:
vault = self.vault()
if self.debug:
print('vault', vault)
json.dump(vault, file, indent=4, cls=JSONEncoder)
return True

@pony.db_session()
def vault(self, section: Vault = Vault.ALL) -> dict:
Expand Down

0 comments on commit 7c3aebc

Please sign in to comment.