Skip to content

Commit

Permalink
- تحسين طريقة تخزين قاعدة البيانات.
Browse files Browse the repository at this point in the history
- اطلاق النسخة 0.2.5
  • Loading branch information
vzool committed Jul 4, 2024
1 parent fd5ac67 commit 9bcf569
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "zakat"
version = "0.2.4"
version = "0.2.5"
authors = [
{ name="Abdelaziz Elrashed Elshaikh Mohamed", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='zakat',
packages=find_packages(include=['zakat']),
version='0.2.4',
version='0.2.5',
description='A Python Library for Islamic Financial Management.',
author='Abdelaziz Elrashed Elshaikh Mohamed',
install_requires=[],
Expand Down
24 changes: 18 additions & 6 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from pprint import PrettyPrinter as pp
from math import floor
from enum import Enum, auto
from sys import version_info


class Action(Enum):
Expand Down Expand Up @@ -160,7 +161,7 @@ class ZakatTracker:
ZakatCut = lambda x: 0.025 * x # Zakat Cut in one Lunar Year
TimeCycle = lambda days=355: int(60 * 60 * 24 * days * 1e9) # Lunar Year in nanoseconds
Nisab = lambda x: 595 * x # Silver Price in Local currency value
Version = lambda: '0.2.41'
Version = lambda: '0.2.5'

def __init__(self, db_path: str = "zakat.pickle", history_mode: bool = True):
"""
Expand Down Expand Up @@ -1261,18 +1262,28 @@ def export_json(self, path: str = "data.json") -> bool:

def save(self, path: str = None) -> bool:
"""
Save the current state of the ZakatTracker object to a pickle file.
Saves the ZakatTracker's current state to a pickle file.
This method serializes the internal data (`_vault`) along with metadata
(Python version, pickle protocol) for future compatibility.
Parameters:
path (str): The path where the pickle file will be saved. If not provided, it will use the default path.
path (str, optional): File path for saving. Defaults to a predefined location.
Returns:
bool: True if the save operation is successful, False otherwise.
bool: True if the save operation is successful, False otherwise.
"""
if path is None:
path = self.path()
with open(path, "wb") as f:
pickle.dump(self._vault, f)
version = f'{version_info.major}.{version_info.minor}.{version_info.micro}'
pickle_protocol = pickle.HIGHEST_PROTOCOL
data = {
'python_version': version,
'pickle_protocol': pickle_protocol,
'data': self._vault,
}
pickle.dump(data, f, protocol=pickle_protocol)
return True

def load(self, path: str = None) -> bool:
Expand All @@ -1289,7 +1300,8 @@ def load(self, path: str = None) -> bool:
path = self.path()
if os.path.exists(path):
with open(path, "rb") as f:
self._vault = pickle.load(f)
data = pickle.load(f)
self._vault = data['data']
return True
return False

Expand Down

0 comments on commit 9bcf569

Please sign in to comment.