absfuyu 2.8.1__py3-none-any.whl → 3.1.0__py3-none-any.whl
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.
Potentially problematic release.
This version of absfuyu might be problematic. Click here for more details.
- absfuyu/__init__.py +13 -10
- absfuyu/__main__.py +55 -38
- absfuyu/config/config.json +3 -3
- absfuyu/core.py +39 -25
- absfuyu/everything.py +4 -5
- absfuyu/extensions/__init__.py +3 -2
- absfuyu/extensions/dev/__init__.py +162 -19
- absfuyu/extensions/dev/password_hash.py +11 -10
- absfuyu/extensions/dev/passwordlib.py +256 -0
- absfuyu/extensions/dev/pkglib.py +53 -57
- absfuyu/extensions/dev/project_starter.py +58 -0
- absfuyu/extensions/dev/shutdownizer.py +8 -0
- absfuyu/extensions/extra/data_analysis.py +687 -119
- absfuyu/fun/__init__.py +88 -118
- absfuyu/fun/tarot.py +32 -34
- absfuyu/game/tictactoe2.py +90 -78
- absfuyu/{collections → general}/__init__.py +14 -12
- absfuyu/{collections → general}/content.py +105 -87
- absfuyu/{collections → general}/data_extension.py +652 -172
- absfuyu/{collections → general}/generator.py +65 -4
- absfuyu/{collections → general}/human.py +28 -3
- absfuyu/pkg_data/__init__.py +14 -36
- absfuyu/pkg_data/chemistry.pkl +0 -0
- absfuyu/pkg_data/tarot.pkl +0 -0
- absfuyu/tools/converter.py +58 -31
- absfuyu/tools/obfuscator.py +4 -4
- absfuyu/tools/stats.py +4 -4
- absfuyu/tools/web.py +2 -2
- absfuyu/util/lunar.py +144 -123
- absfuyu/util/path.py +22 -3
- absfuyu/util/performance.py +101 -14
- absfuyu/version.py +93 -84
- {absfuyu-2.8.1.dist-info → absfuyu-3.1.0.dist-info}/METADATA +63 -33
- absfuyu-3.1.0.dist-info/RECORD +55 -0
- {absfuyu-2.8.1.dist-info → absfuyu-3.1.0.dist-info}/WHEEL +1 -1
- absfuyu-3.1.0.dist-info/entry_points.txt +2 -0
- absfuyu/pkg_data/chemistry.json +0 -6268
- absfuyu/pkg_data/tarot.json +0 -2593
- absfuyu-2.8.1.dist-info/RECORD +0 -52
- absfuyu-2.8.1.dist-info/entry_points.txt +0 -2
- {absfuyu-2.8.1.dist-info → absfuyu-3.1.0.dist-info}/LICENSE +0 -0
- {absfuyu-2.8.1.dist-info → absfuyu-3.1.0.dist-info}/top_level.txt +0 -0
absfuyu/util/lunar.py
CHANGED
|
@@ -14,9 +14,7 @@ https://www.informatik.uni-leipzig.de/~duc/amlich/AL.py
|
|
|
14
14
|
|
|
15
15
|
# Module level
|
|
16
16
|
###########################################################################
|
|
17
|
-
__all__ = [
|
|
18
|
-
"LunarCalendar"
|
|
19
|
-
]
|
|
17
|
+
__all__ = ["LunarCalendar"]
|
|
20
18
|
|
|
21
19
|
|
|
22
20
|
# Library
|
|
@@ -32,15 +30,16 @@ from typing import Union
|
|
|
32
30
|
###########################################################################
|
|
33
31
|
class LunarCalendar:
|
|
34
32
|
"""Lunar Calendar"""
|
|
33
|
+
|
|
35
34
|
def __init__(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
self,
|
|
36
|
+
year: int,
|
|
37
|
+
month: int,
|
|
38
|
+
day: int,
|
|
39
|
+
*,
|
|
40
|
+
time_zone: int = 7,
|
|
41
|
+
lunar_leap: bool = False,
|
|
42
|
+
) -> None:
|
|
44
43
|
"""
|
|
45
44
|
:param time_zone: Time zone
|
|
46
45
|
:param lunar_leap: Do not use this
|
|
@@ -48,65 +47,75 @@ class LunarCalendar:
|
|
|
48
47
|
self.date = date(year, month, day)
|
|
49
48
|
self.time_zone = time_zone
|
|
50
49
|
self._lunar_leap = lunar_leap
|
|
50
|
+
|
|
51
51
|
def __str__(self) -> str:
|
|
52
52
|
return f"{self.__class__.__name__}({self.date}|lunar_leap={self._lunar_leap})"
|
|
53
|
+
|
|
53
54
|
def __repr__(self) -> str:
|
|
54
55
|
return self.__str__()
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
def _julian_day_from_date(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
self,
|
|
59
|
+
*,
|
|
60
|
+
overwrite_year: int = None,
|
|
61
|
+
overwrite_month: int = None,
|
|
62
|
+
overwrite_day: int = None,
|
|
63
|
+
) -> int:
|
|
63
64
|
"""
|
|
64
65
|
Compute the (integral) Julian day number of `self.date`
|
|
65
|
-
|
|
66
|
+
|
|
66
67
|
i.e., the number of days between 1/1/4713 BC (Julian calendar) and `self.date`.
|
|
67
68
|
"""
|
|
68
69
|
day = self.date.day if overwrite_day is None else overwrite_day
|
|
69
70
|
month = self.date.month if overwrite_month is None else overwrite_month
|
|
70
71
|
year = self.date.year if overwrite_year is None else overwrite_year
|
|
71
|
-
a = int((14 - month) / 12.)
|
|
72
|
+
a = int((14 - month) / 12.0)
|
|
72
73
|
y = year + 4800 - a
|
|
73
|
-
m = month + 12*a - 3
|
|
74
|
-
jd =
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
m = month + 12 * a - 3
|
|
75
|
+
jd = (
|
|
76
|
+
day
|
|
77
|
+
+ int((153 * m + 2) / 5.0)
|
|
78
|
+
+ 365 * y
|
|
79
|
+
+ int(y / 4.0)
|
|
80
|
+
- int(y / 100.0)
|
|
81
|
+
+ int(y / 400.0)
|
|
82
|
+
- 32045
|
|
83
|
+
)
|
|
84
|
+
if jd < 2299161:
|
|
85
|
+
jd = day + int((153 * m + 2) / 5.0) + 365 * y + int(y / 4.0) - 32083
|
|
77
86
|
return jd
|
|
78
|
-
|
|
87
|
+
|
|
79
88
|
@staticmethod
|
|
80
89
|
def _julian_day_to_date(julian_day: int) -> date:
|
|
81
90
|
"""
|
|
82
91
|
Convert a Julian day number to `datetime.date`
|
|
83
|
-
|
|
92
|
+
|
|
84
93
|
julian_day: Julian day
|
|
85
94
|
"""
|
|
86
|
-
if
|
|
95
|
+
if julian_day > 2299160:
|
|
87
96
|
## After 5/10/1582, Gregorian calendar
|
|
88
97
|
a = julian_day + 32044
|
|
89
|
-
b = int((4*a + 3) / 146097.)
|
|
90
|
-
c = a - int((b*146097) / 4.)
|
|
98
|
+
b = int((4 * a + 3) / 146097.0)
|
|
99
|
+
c = a - int((b * 146097) / 4.0)
|
|
91
100
|
else:
|
|
92
101
|
b = 0
|
|
93
102
|
c = julian_day + 32082
|
|
94
|
-
|
|
95
|
-
d = int((4*c + 3) / 1461.)
|
|
96
|
-
e = c - int((1461*d) / 4.)
|
|
97
|
-
m = int((5*e + 2) / 153.)
|
|
98
|
-
day = e - int((153*m + 2) / 5.) + 1
|
|
99
|
-
month = m + 3 - 12*int(m / 10.)
|
|
100
|
-
year = b*100 + d - 4800 + int(m / 10.)
|
|
103
|
+
|
|
104
|
+
d = int((4 * c + 3) / 1461.0)
|
|
105
|
+
e = c - int((1461 * d) / 4.0)
|
|
106
|
+
m = int((5 * e + 2) / 153.0)
|
|
107
|
+
day = e - int((153 * m + 2) / 5.0) + 1
|
|
108
|
+
month = m + 3 - 12 * int(m / 10.0)
|
|
109
|
+
year = b * 100 + d - 4800 + int(m / 10.0)
|
|
101
110
|
return date(year, month, day)
|
|
102
|
-
|
|
111
|
+
|
|
103
112
|
@staticmethod
|
|
104
113
|
def _new_moon(k: int) -> float:
|
|
105
114
|
"""
|
|
106
115
|
Compute the time of the k-th new moon after the new moon of `1/1/1900 13:52 UCT`
|
|
107
116
|
measured as the number of days since `1/1/4713 BC noon UCT`,
|
|
108
117
|
e.g., `2451545.125 is 1/1/2000 15:00 UTC`.
|
|
109
|
-
|
|
118
|
+
|
|
110
119
|
Example:
|
|
111
120
|
`2415079.9758617813` for `k=2` or `2414961.935157746` for `k=-2`
|
|
112
121
|
"""
|
|
@@ -114,27 +123,43 @@ class LunarCalendar:
|
|
|
114
123
|
T = k / 1236.85
|
|
115
124
|
T2 = math.pow(T, 2)
|
|
116
125
|
T3 = math.pow(T, 3)
|
|
117
|
-
dr = math.pi / 180.
|
|
118
|
-
Jd1 = 2415020.75933 + 29.53058868*k + 0.0001178*T2 - 0.000000155*T3
|
|
119
|
-
Jd1 = Jd1 + 0.00033*math.sin((166.56 + 132.87*T - 0.009173*T2)*dr)
|
|
126
|
+
dr = math.pi / 180.0
|
|
127
|
+
Jd1 = 2415020.75933 + 29.53058868 * k + 0.0001178 * T2 - 0.000000155 * T3
|
|
128
|
+
Jd1 = Jd1 + 0.00033 * math.sin((166.56 + 132.87 * T - 0.009173 * T2) * dr)
|
|
120
129
|
## Mean new moon
|
|
121
|
-
M = 359.2242 + 29.10535608*k - 0.0000333*T2 - 0.00000347*T3
|
|
130
|
+
M = 359.2242 + 29.10535608 * k - 0.0000333 * T2 - 0.00000347 * T3
|
|
122
131
|
## Sun's mean anomaly
|
|
123
|
-
Mpr = 306.0253 + 385.81691806*k + 0.0107306*T2 + 0.00001236*T3
|
|
132
|
+
Mpr = 306.0253 + 385.81691806 * k + 0.0107306 * T2 + 0.00001236 * T3
|
|
124
133
|
## Moon's mean anomaly
|
|
125
|
-
F = 21.2964 + 390.67050646*k - 0.0016528*T2 - 0.00000239*T3
|
|
134
|
+
F = 21.2964 + 390.67050646 * k - 0.0016528 * T2 - 0.00000239 * T3
|
|
126
135
|
## Moon's argument of latitude
|
|
127
|
-
C1 = (0.1734 - 0.000393*T)*math.sin(M*dr) + 0.0021*math.sin(2*dr*M)
|
|
128
|
-
C1 = C1 - 0.4068*math.sin(Mpr*dr) + 0.0161*math.sin(dr*2*Mpr)
|
|
129
|
-
C1 = C1 - 0.0004*math.sin(dr*3*Mpr)
|
|
130
|
-
C1 = C1 + 0.0104*math.sin(dr*2*F) - 0.0051*math.sin(dr*(M + Mpr))
|
|
131
|
-
C1 =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
C1 = (0.1734 - 0.000393 * T) * math.sin(M * dr) + 0.0021 * math.sin(2 * dr * M)
|
|
137
|
+
C1 = C1 - 0.4068 * math.sin(Mpr * dr) + 0.0161 * math.sin(dr * 2 * Mpr)
|
|
138
|
+
C1 = C1 - 0.0004 * math.sin(dr * 3 * Mpr)
|
|
139
|
+
C1 = C1 + 0.0104 * math.sin(dr * 2 * F) - 0.0051 * math.sin(dr * (M + Mpr))
|
|
140
|
+
C1 = (
|
|
141
|
+
C1 - 0.0074 * math.sin(dr * (M - Mpr)) + 0.0004 * math.sin(dr * (2 * F + M))
|
|
142
|
+
)
|
|
143
|
+
C1 = (
|
|
144
|
+
C1
|
|
145
|
+
- 0.0004 * math.sin(dr * (2 * F - M))
|
|
146
|
+
- 0.0006 * math.sin(dr * (2 * F + Mpr))
|
|
147
|
+
)
|
|
148
|
+
C1 = (
|
|
149
|
+
C1
|
|
150
|
+
+ 0.0010 * math.sin(dr * (2 * F - Mpr))
|
|
151
|
+
+ 0.0005 * math.sin(dr * (2 * Mpr + M))
|
|
152
|
+
)
|
|
153
|
+
if T < -11:
|
|
154
|
+
deltat = (
|
|
155
|
+
0.001
|
|
156
|
+
+ 0.000839 * T
|
|
157
|
+
+ 0.0002261 * T2
|
|
158
|
+
- 0.00000845 * T3
|
|
159
|
+
- 0.000000081 * T * T3
|
|
160
|
+
)
|
|
136
161
|
else:
|
|
137
|
-
deltat= -0.000278 + 0.000265*T + 0.000262*T2
|
|
162
|
+
deltat = -0.000278 + 0.000265 * T + 0.000262 * T2
|
|
138
163
|
JdNew = Jd1 + C1 - deltat
|
|
139
164
|
return JdNew
|
|
140
165
|
|
|
@@ -142,64 +167,71 @@ class LunarCalendar:
|
|
|
142
167
|
def _sun_longitude(julian_day_noon: float) -> float:
|
|
143
168
|
"""
|
|
144
169
|
Compute the longitude of the sun at any time.
|
|
145
|
-
|
|
170
|
+
|
|
146
171
|
julian_day_noon: The number of days since `1/1/4713 BC noon`.
|
|
147
172
|
"""
|
|
148
|
-
T = (julian_day_noon - 2451545.0
|
|
173
|
+
T = (julian_day_noon - 2451545.0) / 36525.0
|
|
149
174
|
## Time in Julian centuries
|
|
150
175
|
## from 2000-01-01 12:00:00 GMT
|
|
151
176
|
T2 = math.pow(T, 2)
|
|
152
177
|
T3 = math.pow(T, 3)
|
|
153
|
-
dr = math.pi / 180. ## degree to radian
|
|
154
|
-
M = 357.52910 + 35999.05030*T - 0.0001559*T2 - 0.00000048*T3
|
|
178
|
+
dr = math.pi / 180.0 ## degree to radian
|
|
179
|
+
M = 357.52910 + 35999.05030 * T - 0.0001559 * T2 - 0.00000048 * T3
|
|
155
180
|
## mean anomaly, degree
|
|
156
|
-
L0 = 280.46645 + 36000.76983*T + 0.0003032*T2
|
|
181
|
+
L0 = 280.46645 + 36000.76983 * T + 0.0003032 * T2
|
|
157
182
|
## mean longitude, degree
|
|
158
|
-
DL = (1.914600 - 0.004817*T - 0.000014*T2) * math.sin(dr*M)
|
|
159
|
-
DL += (0.019993 - 0.000101*T) * math.sin(dr*2*M) + 0.000290 * math.sin(
|
|
183
|
+
DL = (1.914600 - 0.004817 * T - 0.000014 * T2) * math.sin(dr * M)
|
|
184
|
+
DL += (0.019993 - 0.000101 * T) * math.sin(dr * 2 * M) + 0.000290 * math.sin(
|
|
185
|
+
dr * 3 * M
|
|
186
|
+
)
|
|
160
187
|
L = L0 + DL ## true longitude, degree
|
|
161
188
|
L = L * dr
|
|
162
|
-
L = L - math.pi*2*(int(L / (math.pi*2)))
|
|
189
|
+
L = L - math.pi * 2 * (int(L / (math.pi * 2)))
|
|
163
190
|
#### Normalize to (0, 2*math.pi)
|
|
164
191
|
return L
|
|
165
|
-
|
|
192
|
+
|
|
166
193
|
def _get_sun_longitude(self, day_number: int) -> int:
|
|
167
194
|
"""
|
|
168
195
|
Compute sun position at midnight of the day with the given Julian day number.
|
|
169
|
-
|
|
196
|
+
|
|
170
197
|
The time zone if the time difference between local time and UTC: 7.0 for UTC+7:00.
|
|
171
|
-
|
|
172
|
-
The function returns a number between `0` and `11`.
|
|
173
|
-
|
|
198
|
+
|
|
199
|
+
The function returns a number between `0` and `11`.
|
|
200
|
+
|
|
174
201
|
From the day after March equinox and the 1st major term after March equinox, 0 is returned. After that, return 1, 2, 3 ...
|
|
175
202
|
"""
|
|
176
|
-
return int(
|
|
203
|
+
return int(
|
|
204
|
+
__class__._sun_longitude(day_number - 0.5 - self.time_zone / 24.0)
|
|
205
|
+
/ math.pi
|
|
206
|
+
* 6
|
|
207
|
+
)
|
|
177
208
|
|
|
178
209
|
def _get_new_moon_day(self, k: int) -> int:
|
|
179
210
|
"""
|
|
180
211
|
Compute the day of the k-th new moon in the given time zone.
|
|
181
|
-
|
|
212
|
+
|
|
182
213
|
The time zone if the time difference between local time and UTC: 7.0 for UTC+7:00.
|
|
183
214
|
"""
|
|
184
|
-
return int(__class__._new_moon(k) + 0.5 + self.time_zone / 24.)
|
|
185
|
-
|
|
186
|
-
def _get_lunar_month_11(
|
|
187
|
-
self,
|
|
188
|
-
*,
|
|
189
|
-
overwrite_year: int = None
|
|
190
|
-
) -> int:
|
|
215
|
+
return int(__class__._new_moon(k) + 0.5 + self.time_zone / 24.0)
|
|
216
|
+
|
|
217
|
+
def _get_lunar_month_11(self, *, overwrite_year: int = None) -> int:
|
|
191
218
|
"""
|
|
192
219
|
Find the day that starts the luner month 11
|
|
193
220
|
of the given year for the given time zone.
|
|
194
221
|
"""
|
|
195
222
|
# off = self._julian_day_from_date(overwrite_month=12, overwrite_day=31) - 2415021.076998695
|
|
196
223
|
year = self.date.year if overwrite_year is None else overwrite_year
|
|
197
|
-
off =
|
|
224
|
+
off = (
|
|
225
|
+
self._julian_day_from_date(
|
|
226
|
+
overwrite_month=12, overwrite_day=31, overwrite_year=year
|
|
227
|
+
)
|
|
228
|
+
- 2415021.0
|
|
229
|
+
)
|
|
198
230
|
k = int(off / 29.530588853)
|
|
199
231
|
nm = self._get_new_moon_day(k)
|
|
200
232
|
sunLong = self._get_sun_longitude(nm)
|
|
201
233
|
#### sun longitude at local midnight
|
|
202
|
-
if
|
|
234
|
+
if sunLong >= 9:
|
|
203
235
|
nm = self._get_new_moon_day(k - 1)
|
|
204
236
|
return nm
|
|
205
237
|
|
|
@@ -215,9 +247,9 @@ class LunarCalendar:
|
|
|
215
247
|
last = arc
|
|
216
248
|
i += 1
|
|
217
249
|
arc = self._get_sun_longitude(self._get_new_moon_day(k + i))
|
|
218
|
-
if
|
|
250
|
+
if not (arc != last and i < 14):
|
|
219
251
|
break
|
|
220
|
-
|
|
252
|
+
|
|
221
253
|
# for i in range(1, 14):
|
|
222
254
|
# arc = self._get_sun_longitude(self._get_new_moon_day(k + i))
|
|
223
255
|
# if arc != last:
|
|
@@ -225,7 +257,7 @@ class LunarCalendar:
|
|
|
225
257
|
# else:
|
|
226
258
|
# break
|
|
227
259
|
return i - 1
|
|
228
|
-
|
|
260
|
+
|
|
229
261
|
def to_lunar(self):
|
|
230
262
|
"""
|
|
231
263
|
Convert solar date to the corresponding lunar date.
|
|
@@ -239,32 +271,34 @@ class LunarCalendar:
|
|
|
239
271
|
day_number = self._julian_day_from_date()
|
|
240
272
|
k = int((day_number - 2415021.076998695) / 29.530588853)
|
|
241
273
|
month_start = self._get_new_moon_day(k + 1)
|
|
242
|
-
if
|
|
274
|
+
if month_start > day_number:
|
|
243
275
|
month_start = self._get_new_moon_day(k)
|
|
244
276
|
# alert(day_number + " -> " + month_start)
|
|
245
277
|
a11 = self._get_lunar_month_11()
|
|
246
278
|
b11 = a11
|
|
247
|
-
if
|
|
279
|
+
if a11 >= month_start:
|
|
248
280
|
lunar_year = yy
|
|
249
281
|
a11 = self._get_lunar_month_11(overwrite_year=yy - 1)
|
|
250
282
|
else:
|
|
251
283
|
lunar_year = yy + 1
|
|
252
284
|
b11 = self._get_lunar_month_11(overwrite_year=yy + 1)
|
|
253
285
|
lunar_day = day_number - month_start + 1
|
|
254
|
-
diff = int((month_start - a11) / 29.)
|
|
286
|
+
diff = int((month_start - a11) / 29.0)
|
|
255
287
|
lunar_month = diff + 11
|
|
256
|
-
if
|
|
288
|
+
if b11 - a11 > 365:
|
|
257
289
|
leap_month_diff = self._get_leap_month_offset(a11)
|
|
258
|
-
if
|
|
290
|
+
if diff >= leap_month_diff:
|
|
259
291
|
lunar_month = diff + 10
|
|
260
|
-
if
|
|
292
|
+
if diff == leap_month_diff:
|
|
261
293
|
self._lunar_leap = True
|
|
262
|
-
if
|
|
294
|
+
if lunar_month > 12:
|
|
263
295
|
lunar_month = lunar_month - 12
|
|
264
|
-
if
|
|
296
|
+
if lunar_month >= 11 and diff < 4:
|
|
265
297
|
lunar_year -= 1
|
|
266
|
-
return __class__(
|
|
267
|
-
|
|
298
|
+
return __class__(
|
|
299
|
+
lunar_year, lunar_month, lunar_day, lunar_leap=self._lunar_leap
|
|
300
|
+
)
|
|
301
|
+
|
|
268
302
|
def to_solar(self):
|
|
269
303
|
"""
|
|
270
304
|
Convert a lunar date to the corresponding solar date.
|
|
@@ -273,14 +307,14 @@ class LunarCalendar:
|
|
|
273
307
|
-------
|
|
274
308
|
LunarCalendar
|
|
275
309
|
LunarCalendar instance
|
|
276
|
-
|
|
310
|
+
|
|
277
311
|
date
|
|
278
312
|
When unable to convert
|
|
279
313
|
"""
|
|
280
314
|
lunarD = self.date.day
|
|
281
315
|
lunarM = self.date.month
|
|
282
316
|
lunarY = self.date.year
|
|
283
|
-
if
|
|
317
|
+
if lunarM < 11:
|
|
284
318
|
a11 = self._get_lunar_month_11(overwrite_year=lunarY - 1)
|
|
285
319
|
b11 = self._get_lunar_month_11(overwrite_year=lunarY)
|
|
286
320
|
else:
|
|
@@ -288,45 +322,35 @@ class LunarCalendar:
|
|
|
288
322
|
b11 = self._get_lunar_month_11(overwrite_year=lunarY + 1)
|
|
289
323
|
k = int(0.5 + (a11 - 2415021.076998695) / 29.530588853)
|
|
290
324
|
off = lunarM - 11
|
|
291
|
-
if
|
|
325
|
+
if off < 0:
|
|
292
326
|
off += 12
|
|
293
|
-
if
|
|
327
|
+
if b11 - a11 > 365:
|
|
294
328
|
leapOff = self._get_leap_month_offset(a11)
|
|
295
329
|
leapM = leapOff - 2
|
|
296
|
-
if
|
|
330
|
+
if leapM < 0:
|
|
297
331
|
leapM += 12
|
|
298
|
-
if
|
|
332
|
+
if self._lunar_leap is True and lunarM != leapM:
|
|
299
333
|
# logger.warning("lunar_leap is True")
|
|
300
334
|
# raise ValueError()
|
|
301
335
|
return date(1, 1, 1)
|
|
302
|
-
elif
|
|
336
|
+
elif self._lunar_leap is True or off >= leapOff:
|
|
303
337
|
off += 1
|
|
304
338
|
monthStart = self._get_new_moon_day(k + off)
|
|
305
339
|
out = self._julian_day_to_date(monthStart + lunarD - 1)
|
|
306
340
|
return __class__(out.year, out.month, out.day, lunar_leap=self._lunar_leap)
|
|
307
|
-
|
|
341
|
+
|
|
308
342
|
def convert_all(self) -> dict:
|
|
309
343
|
"""
|
|
310
344
|
Convert to both lunar and solar
|
|
311
|
-
|
|
345
|
+
|
|
312
346
|
This method has no practical use
|
|
313
347
|
|
|
314
348
|
:rtype: dict
|
|
315
349
|
"""
|
|
316
|
-
return {
|
|
317
|
-
"lunar": self.to_lunar(),
|
|
318
|
-
"original": self,
|
|
319
|
-
"solar": self.to_solar()
|
|
320
|
-
}
|
|
350
|
+
return {"lunar": self.to_lunar(), "original": self, "solar": self.to_solar()}
|
|
321
351
|
|
|
322
352
|
@classmethod
|
|
323
|
-
def from_solar(
|
|
324
|
-
cls,
|
|
325
|
-
year: int,
|
|
326
|
-
month: int,
|
|
327
|
-
day: int,
|
|
328
|
-
lunar_leap: bool = False
|
|
329
|
-
):
|
|
353
|
+
def from_solar(cls, year: int, month: int, day: int, lunar_leap: bool = False):
|
|
330
354
|
"""
|
|
331
355
|
Convert to lunar day from solar day
|
|
332
356
|
|
|
@@ -340,37 +364,34 @@ class LunarCalendar:
|
|
|
340
364
|
|
|
341
365
|
day : int
|
|
342
366
|
Day (in range [1, 31])
|
|
343
|
-
|
|
367
|
+
|
|
344
368
|
lunar_leap : bool
|
|
345
369
|
Is leap (Default: ``False``)
|
|
346
|
-
|
|
370
|
+
|
|
347
371
|
Returns
|
|
348
372
|
-------
|
|
349
373
|
LunarCalendar
|
|
350
374
|
LunarCalendar instance
|
|
351
375
|
"""
|
|
352
376
|
return cls(year, month, day, lunar_leap=lunar_leap).to_lunar()
|
|
353
|
-
|
|
377
|
+
|
|
354
378
|
@classmethod
|
|
355
|
-
def from_datetime(
|
|
356
|
-
cls,
|
|
357
|
-
datetime_object: Union[date, datetime]
|
|
358
|
-
):
|
|
379
|
+
def from_datetime(cls, datetime_object: Union[date, datetime]):
|
|
359
380
|
"""
|
|
360
381
|
Convert from ``datetime.datetime`` object
|
|
361
|
-
|
|
382
|
+
|
|
362
383
|
Parameters
|
|
363
384
|
----------
|
|
364
385
|
datetime_object : date | datetime
|
|
365
386
|
``datetime.datetime`` object
|
|
366
|
-
|
|
387
|
+
|
|
367
388
|
Returns
|
|
368
389
|
-------
|
|
369
390
|
LunarCalendar
|
|
370
391
|
LunarCalendar instance
|
|
371
392
|
"""
|
|
372
393
|
return cls(datetime_object.year, datetime_object.month, datetime_object.day)
|
|
373
|
-
|
|
394
|
+
|
|
374
395
|
@classmethod
|
|
375
396
|
def now(cls):
|
|
376
397
|
"""
|
|
@@ -389,4 +410,4 @@ class LunarCalendar:
|
|
|
389
410
|
###########################################################################
|
|
390
411
|
if __name__ == "__main__":
|
|
391
412
|
# logger.setLevel(10)
|
|
392
|
-
pass
|
|
413
|
+
pass
|
absfuyu/util/path.py
CHANGED
|
@@ -31,7 +31,7 @@ import os
|
|
|
31
31
|
from pathlib import Path
|
|
32
32
|
import re
|
|
33
33
|
import shutil
|
|
34
|
-
from typing import Any, List, Tuple, Union
|
|
34
|
+
from typing import Any, List, Literal, Tuple, Union
|
|
35
35
|
|
|
36
36
|
from absfuyu.logger import logger
|
|
37
37
|
|
|
@@ -302,7 +302,7 @@ class Directory:
|
|
|
302
302
|
@staticmethod
|
|
303
303
|
def _date_filter(
|
|
304
304
|
value: Tuple[Path, datetime],
|
|
305
|
-
period:
|
|
305
|
+
period: Literal["Y", "M", "D"] = "Y"
|
|
306
306
|
) -> bool:
|
|
307
307
|
"""
|
|
308
308
|
Filter out file with current Year|Month|Day
|
|
@@ -326,7 +326,7 @@ class Directory:
|
|
|
326
326
|
entire: bool = False,
|
|
327
327
|
*,
|
|
328
328
|
based_on_time: bool = False,
|
|
329
|
-
keep:
|
|
329
|
+
keep: Literal["Y", "M", "D"] = "Y"
|
|
330
330
|
) -> None:
|
|
331
331
|
"""
|
|
332
332
|
Deletes everything
|
|
@@ -414,6 +414,25 @@ class SaveFileAs:
|
|
|
414
414
|
"""
|
|
415
415
|
with open(path, "w", encoding=self.encoding) as file:
|
|
416
416
|
file.writelines(self.data)
|
|
417
|
+
|
|
418
|
+
# def to_pickle(self, path: Union[str, Path]) -> None:
|
|
419
|
+
# """
|
|
420
|
+
# Save as .pickle file
|
|
421
|
+
|
|
422
|
+
# :param path: Save location
|
|
423
|
+
# """
|
|
424
|
+
# from absfuyu.util.pkl import Pickler
|
|
425
|
+
# Pickler.save(path, self.data)
|
|
426
|
+
|
|
427
|
+
# def to_json(self, path: Union[str, Path]) -> None:
|
|
428
|
+
# """
|
|
429
|
+
# Save as .json file
|
|
430
|
+
|
|
431
|
+
# :param path: Save location
|
|
432
|
+
# """
|
|
433
|
+
# from absfuyu.util.json_method import JsonFile
|
|
434
|
+
# temp = JsonFile(path, sort_keys=False)
|
|
435
|
+
# temp.save_json()
|
|
417
436
|
|
|
418
437
|
|
|
419
438
|
# Run
|