sharedkernel 1.4.5__tar.gz → 1.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/PKG-INFO +7 -1
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/README.md +5 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/setup.py +3 -2
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/mongo_generic_repository.py +3 -1
- sharedkernel-1.5.1/sharedkernel/date_converter.py +122 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel.egg-info/PKG-INFO +7 -1
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel.egg-info/requires.txt +1 -0
- sharedkernel-1.4.5/sharedkernel/date_converter.py +0 -32
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/setup.cfg +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/common.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/__init__.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/vector_database_repository/__init__.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/vector_database_repository/chroma_startegy.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/vector_database_repository/milvus_strategy.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/vector_database_repository/vector_database_repository.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/database/vector_database_repository/vector_database_strategy.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/enum/__init__.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/enum/error_code.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/enum/vector_database_type.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/exception/__init__.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/exception/exception.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/exception/exception_handlers.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/jwt_service.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/objects/__init__.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/objects/base_document.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/objects/jwt_model.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/objects/result.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/regex_masking.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel/string_extentions.py +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel.egg-info/SOURCES.txt +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel.egg-info/dependency_links.txt +0 -0
- {sharedkernel-1.4.5 → sharedkernel-1.5.1}/sharedkernel.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.1
|
|
4
4
|
Summary: sharekernel is an shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -14,11 +14,17 @@ Requires-Dist: chromadb
|
|
|
14
14
|
Requires-Dist: persian_tools
|
|
15
15
|
Requires-Dist: sentry-sdk
|
|
16
16
|
Requires-Dist: jdatetime
|
|
17
|
+
Requires-Dist: persiantools
|
|
17
18
|
|
|
18
19
|
# SharedKernel
|
|
19
20
|
this a shared kernel package
|
|
20
21
|
|
|
21
22
|
# Change Log
|
|
23
|
+
### Version 1.5.1
|
|
24
|
+
- fix mongo repository bug
|
|
25
|
+
### Version 1.5.0
|
|
26
|
+
- implement date converter
|
|
27
|
+
- example: فردا - دیروز - یک ماه قبل
|
|
22
28
|
### Version 1.4.5
|
|
23
29
|
- upgrade fastapi version
|
|
24
30
|
### Version 1.4.4
|
|
@@ -29,10 +29,11 @@ setup(
|
|
|
29
29
|
"chromadb",
|
|
30
30
|
"persian_tools",
|
|
31
31
|
"sentry-sdk",
|
|
32
|
-
"jdatetime"
|
|
32
|
+
"jdatetime",
|
|
33
|
+
"persiantools"
|
|
33
34
|
],
|
|
34
35
|
# *strongly* suggested for sharing
|
|
35
|
-
version="1.
|
|
36
|
+
version="1.5.1",
|
|
36
37
|
description="sharekernel is an shared package between all python projects",
|
|
37
38
|
long_description=long_description,
|
|
38
39
|
long_description_content_type="text/markdown",
|
|
@@ -22,6 +22,7 @@ class MongoGenericRepository(Generic[T]):
|
|
|
22
22
|
query = {"_id": ObjectId(id), "is_deleted": False}
|
|
23
23
|
result = self.collection.find_one(query)
|
|
24
24
|
return self._map_to_model(result) if result else None
|
|
25
|
+
|
|
25
26
|
|
|
26
27
|
def insert_one(self, data: T) -> str:
|
|
27
28
|
delattr(data, "id")
|
|
@@ -46,5 +47,6 @@ class MongoGenericRepository(Generic[T]):
|
|
|
46
47
|
|
|
47
48
|
def get_all(self, page_number=1, page_size=10) -> List[T]:
|
|
48
49
|
skip_count = (page_number - 1) * page_size
|
|
49
|
-
|
|
50
|
+
query = {"is_deleted": False}
|
|
51
|
+
result = self.collection.find(query).skip(skip_count).limit(page_size)
|
|
50
52
|
return [self._map_to_model(doc) for doc in result]
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import jdatetime
|
|
2
|
+
from datetime import datetime, timedelta
|
|
3
|
+
from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
4
|
+
from math import floor
|
|
5
|
+
|
|
6
|
+
from sharedkernel.enum import ErrorCode
|
|
7
|
+
|
|
8
|
+
MONTH = 30
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DateConverter:
|
|
12
|
+
@staticmethod
|
|
13
|
+
def to_jalali(
|
|
14
|
+
input_datetime: datetime | jdatetime.datetime, format_string: str = "%Y/%m/%d"
|
|
15
|
+
):
|
|
16
|
+
if isinstance(input_datetime, jdatetime.datetime):
|
|
17
|
+
return input_datetime.strftime(format_string)
|
|
18
|
+
|
|
19
|
+
if isinstance(input_datetime, datetime):
|
|
20
|
+
jalali_date = jdatetime.datetime.fromgregorian(date=input_datetime)
|
|
21
|
+
return jalali_date.strftime(format_string)
|
|
22
|
+
|
|
23
|
+
raise ValueError(ErrorCode.Unsupported_Date_Type)
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def to_georgian(
|
|
27
|
+
input_datetime: datetime | jdatetime.datetime, format_string: str = "%Y/%m/%d"
|
|
28
|
+
):
|
|
29
|
+
if isinstance(input_datetime, jdatetime.datetime):
|
|
30
|
+
georgian_date = jdatetime.datetime.togregorian(input_datetime)
|
|
31
|
+
return georgian_date.strftime(format_string)
|
|
32
|
+
|
|
33
|
+
if isinstance(input_datetime, datetime):
|
|
34
|
+
return input_datetime.strftime(format_string)
|
|
35
|
+
|
|
36
|
+
raise ValueError(ErrorCode.Unsupported_Date_Type)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def to_diff_persian_date_time_string(
|
|
40
|
+
dt, comparison_base, append_hh_mm=False, has_suffix=False
|
|
41
|
+
):
|
|
42
|
+
|
|
43
|
+
def get_persian_day_name(jalali_date):
|
|
44
|
+
# Adjust this function based on how Persian day names should be retrieved
|
|
45
|
+
day_names = [
|
|
46
|
+
"شنبه",
|
|
47
|
+
"یکشنبه",
|
|
48
|
+
"دوشنبه",
|
|
49
|
+
"سهشنبه",
|
|
50
|
+
"چهارشنبه",
|
|
51
|
+
"پنجشنبه",
|
|
52
|
+
"جمعه",
|
|
53
|
+
]
|
|
54
|
+
return day_names[jalali_date.weekday()]
|
|
55
|
+
|
|
56
|
+
persian_date = JalaliDateTime.to_jalali(dt)
|
|
57
|
+
persian_year = persian_date.year
|
|
58
|
+
persian_month = persian_date.month
|
|
59
|
+
persian_day = persian_date.day
|
|
60
|
+
|
|
61
|
+
hour = dt.hour
|
|
62
|
+
minute = dt.minute
|
|
63
|
+
hh_mm = f"{hour:02}:{minute:02}"
|
|
64
|
+
|
|
65
|
+
date = JalaliDateTime(persian_year, persian_month, persian_day, hour, minute)
|
|
66
|
+
diff = date - comparison_base
|
|
67
|
+
total_seconds = round(diff.total_seconds())
|
|
68
|
+
total_days = round(total_seconds / 86400)
|
|
69
|
+
total_hours = abs(round(total_seconds / 3600))
|
|
70
|
+
total_months = abs(total_days // MONTH) # Approximate months calculation
|
|
71
|
+
|
|
72
|
+
suffix = " بعد"
|
|
73
|
+
if total_seconds < 0:
|
|
74
|
+
suffix = " قبل"
|
|
75
|
+
total_seconds = abs(total_seconds)
|
|
76
|
+
total_days = abs(total_days)
|
|
77
|
+
total_months = abs(total_months)
|
|
78
|
+
|
|
79
|
+
date_time_today = comparison_base.date()
|
|
80
|
+
yesterday = date_time_today - timedelta(days=1)
|
|
81
|
+
tomorrow = date_time_today + timedelta(days=1)
|
|
82
|
+
|
|
83
|
+
suffix = suffix if has_suffix else ""
|
|
84
|
+
hh_mm = f"، ساعت {hh_mm}" if append_hh_mm else ""
|
|
85
|
+
|
|
86
|
+
if total_hours < 24:
|
|
87
|
+
if total_seconds < 60:
|
|
88
|
+
return "هم اکنون"
|
|
89
|
+
if total_seconds < 120:
|
|
90
|
+
return f"یک دقیقه{suffix}{hh_mm}"
|
|
91
|
+
if total_seconds < 3600:
|
|
92
|
+
return f"{floor(total_seconds / 60)} دقیقه{suffix}{hh_mm}"
|
|
93
|
+
if total_seconds < 7200:
|
|
94
|
+
return f"یک ساعت{suffix}{hh_mm}"
|
|
95
|
+
if total_seconds < 86400:
|
|
96
|
+
return f"{floor(total_seconds / 3600)} ساعت{suffix}{hh_mm}"
|
|
97
|
+
|
|
98
|
+
if yesterday == date.date():
|
|
99
|
+
return f"دیروز {get_persian_day_name(JalaliDate(yesterday.year, yesterday.month, yesterday.day -1))}"
|
|
100
|
+
if tomorrow == date.date():
|
|
101
|
+
return f"فردا {get_persian_day_name(JalaliDate(tomorrow.year, tomorrow.month, tomorrow.day -1))}"
|
|
102
|
+
|
|
103
|
+
if total_days < MONTH: # 30 days
|
|
104
|
+
return f"{int(total_days)} روز{suffix}"
|
|
105
|
+
|
|
106
|
+
total_months = int(total_days / MONTH)
|
|
107
|
+
total_days = total_days - MONTH
|
|
108
|
+
|
|
109
|
+
if total_months < 12 * MONTH:
|
|
110
|
+
if total_days == 0:
|
|
111
|
+
return f"{total_months} ماه {suffix}"
|
|
112
|
+
else:
|
|
113
|
+
return f"{total_months} ماه و {total_days} روز{suffix}"
|
|
114
|
+
|
|
115
|
+
# Handling years and months
|
|
116
|
+
total_years = total_months // 12
|
|
117
|
+
remaining_months = total_months % 12
|
|
118
|
+
if remaining_months > 0:
|
|
119
|
+
return f"{total_years} سال و {remaining_months} ماه{suffix}"
|
|
120
|
+
else:
|
|
121
|
+
return f"{total_years} سال{suffix}"
|
|
122
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.1
|
|
4
4
|
Summary: sharekernel is an shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -14,11 +14,17 @@ Requires-Dist: chromadb
|
|
|
14
14
|
Requires-Dist: persian_tools
|
|
15
15
|
Requires-Dist: sentry-sdk
|
|
16
16
|
Requires-Dist: jdatetime
|
|
17
|
+
Requires-Dist: persiantools
|
|
17
18
|
|
|
18
19
|
# SharedKernel
|
|
19
20
|
this a shared kernel package
|
|
20
21
|
|
|
21
22
|
# Change Log
|
|
23
|
+
### Version 1.5.1
|
|
24
|
+
- fix mongo repository bug
|
|
25
|
+
### Version 1.5.0
|
|
26
|
+
- implement date converter
|
|
27
|
+
- example: فردا - دیروز - یک ماه قبل
|
|
22
28
|
### Version 1.4.5
|
|
23
29
|
- upgrade fastapi version
|
|
24
30
|
### Version 1.4.4
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import jdatetime
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
|
|
4
|
-
from sharedkernel.enum import ErrorCode
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class DateConverter:
|
|
8
|
-
@staticmethod
|
|
9
|
-
def to_jalali(
|
|
10
|
-
input_datetime: datetime | jdatetime.datetime, format_string: str = "%Y/%m/%d"
|
|
11
|
-
):
|
|
12
|
-
if isinstance(input_datetime, jdatetime.datetime):
|
|
13
|
-
return input_datetime.strftime(format_string)
|
|
14
|
-
|
|
15
|
-
if isinstance(input_datetime, datetime):
|
|
16
|
-
jalali_date = jdatetime.datetime.fromgregorian(date=input_datetime)
|
|
17
|
-
return jalali_date.strftime(format_string)
|
|
18
|
-
|
|
19
|
-
raise ValueError(ErrorCode.Unsupported_Date_Type)
|
|
20
|
-
|
|
21
|
-
@staticmethod
|
|
22
|
-
def to_georgian(
|
|
23
|
-
input_datetime: datetime | jdatetime.datetime, format_string: str = "%Y/%m/%d"
|
|
24
|
-
):
|
|
25
|
-
if isinstance(input_datetime, jdatetime.datetime):
|
|
26
|
-
georgian_date = jdatetime.datetime.togregorian(input_datetime)
|
|
27
|
-
return georgian_date.strftime(format_string)
|
|
28
|
-
|
|
29
|
-
if isinstance(input_datetime, datetime):
|
|
30
|
-
return input_datetime.strftime(format_string)
|
|
31
|
-
|
|
32
|
-
raise ValueError(ErrorCode.Unsupported_Date_Type)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|