summaryrefslogtreecommitdiff
path: root/python-ichingshifa.spec
blob: b7f024ee6bf10513cc99b083287df6a1ff0e4874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
%global _empty_manifest_terminate_build 0
Name:		python-ichingshifa
Version:	3.1.8
Release:	1
Summary:	A package of iching stalk divination in Traditional Chinese Language. Python周易筮法,納甲六爻,起卦不求人。
License:	MIT License
URL:		https://github.com/kentang2017/iching_shifa
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/1f/d9/557d751b8a40ca7296bb3910cc12e2aed66c617b3abfc12a040a1cf82375/ichingshifa-3.1.8.tar.gz
BuildArch:	noarch


%description
# Python IchingShifa Python 周易 筮法 卜卦 (stalk divination)

[![Python](https://img.shields.io/pypi/pyversions/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![PIP](https://img.shields.io/pypi/v/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![Downloads](https://img.shields.io/pypi/dm/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![TG](https://img.shields.io/badge/chat-on%20telegram-blue)](https://t.me/gnatnek)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg?logo=paypal&style=flat-square)](https://www.paypal.me/kinyeah) 

![alt text](https://upload.wikimedia.org/wikipedia/commons/a/af/French_Polished_Yarrow_stalks_from_LPKaster.jpg "Stalk divination")

"筮"是傳統的周易起卦方式。古人以50根蓍草作為占卜工具,名為策,故此法亦稱"籌策"占卜。《周易系辭上傳》辭曰:"大衍之數五十,其用四十有九。分而為二以像兩,掛一以像三, 揲之以四以像四時,歸奇於扐以像閏,五歲再閏,故再扐而後掛。 天一地二,天三地四,天五地六,天七地八,天九地十。天數五,地數五,五位相得而各有合。天數二十有五,地數三十,凡天地之數五十有五。此所以成變化而行鬼神也。"整個起卦過程是要求得十八個隨機數目,當中包括"六次"(即六根爻)的"三變"。


**"Shi"(筮)** or so-called Stalk divination, one of the oldest IChing divination method in the Chinese society, in which the ancient Chinese used 50 sticks of yarrow stalks to do divination or prediction. According to Zhouyi 周易, the number of "Da Yan" (大衍) is 50 while 1 is taken away and 49 sticks of yarrow stalks were used in divination. 49 stalks were seperated into 2 bunches respectively held by both left hand and right hand, and then one stick would be extracted from the right hand, the bunch of stalks held by right hand was divided by four, until the remainder comes, that is called the change (or 'bian'), repeating thrice. The whole process of this divination includes getting 18 random numbers. The value of Line may come after  "Three Changes", that is  (49 stalks - first change - second change - third change) divided by 4, it will be either **6(old yin 老陰)**, **7(young yang 少陽)**, **8(young yin 少陰)**, or **9(old yang 老陽)**.  The BenGua (本卦) is formed when the value of Line is formed from the bottom to the top. If the line with value of either 6 or 9, meaning that line must have a change, like 6(old yin) change to 7(young yang), and 9 (old yang) change to 8 (old yin). Each of the lines has its own meaning or explantion. BianGua (變卦) or ZhiGua (之卦) is also formed after BenGua with value 6 or 9 has been changed. 


## **1. 大衍之數、太一、分二、掛一、揲四、歸奇 The number of DaYan**︰

```python
#一變的過程
n=2
stalks_first = 50-1  #把太一拿走
dividers = sorted(random.sample(range(24, stalks_first), n - 1)) #分二
division  = [a - b for a, b in zip(dividers + [stalks_first+10], [10] + dividers)]
guayi = 1 #掛一
right = division[0] - guayi 
left_extract = division[1] % 4  #揲四
if left_extract == 0:
    left_extract = 4
right_extract = right % 4
if right_extract == 0:
    right_extract = 4 #歸奇
bian  = left_extract + right_extract + guayi #一變,其餘二變倣效此法,如果做for loop 這裡的掛一可以拿走,不用加上。
```

## **2. 處理變(動)爻的方法︰The way in handling the change of line(s)(yao(s))**

1. 凡卦六爻皆不變,則占本卦彖辭,而以內卦為貞,外卦為悔,彖辭為卦下之辭。

2. 一爻變,則以本卦變爻辭

3. 二爻變,則以本卦二變爻辭占,仍以上爻為主

4. 三爻變,則占本卦及之卦之彖辭,即以本卦為貞,之卦為悔,前十卦(初爻出現變爻)主貞,後十卦(非初爻出現變爻)主悔

5. 四爻變,則以之卦二不變爻占,仍以下爻為主經,亦無文,今以例推之當如此。

6. 五爻變,則以之卦不變爻占。

7. 六爻變,則乾、坤占二用,餘卦占之卦彖辭。

_參考自【宋】‧朱熹、蔡元定《易學啟蒙》卷下 考變占︰_

1. If the Six lines without any changed lines, the explantion of Gua is based on the general explanation of BenGua. 
2. If the Six lines with one line changed, the explanation is depended on there. 
3. If the Six lines with two lines changed, the upper one is the main explanation. 
4. If the Six lines with three lines changed, the explanation is lied on the BenGua's general explanation if the change line starts from the first line, while the explantion is base on BianGua's general explanation if the change line starts from the second line. 
5. If the Six lines with four lines changed,  the explanation is upon the lower line of BianGua. 
6. If the Six lines with five lines changed,  the explanation is upon the one line without change on BianGua. 
7. If the Six lines with six lines changed, except for QianGua and KunGua with explanation on 用, use the general explanation  
_The above method is advocated by ZhuXi, a Confucian of Song Dynasty_

![alt text](https://github.com/kentang2017/iching_shifa/blob/master/data/results.png?raw=true)

## **3. 納甲 Najia **:

其後漢元帝師從梁人焦延壽的京房開創京氏易學,把筮法加入干支納甲,後世學者再加以五行、五星、六親及二十八宿等加以詳推。

Later on, an iching expert Jing Fang during the Han Dynasty created a najia method of hexagram interpretation amongiching. which correlates their separate lines with elements of the Chinese calendar.


## **4. 安裝套件 Installation**:
```
pip install --upgrade ichingshifa
```

## **5. 快速起卦 Quick Start**:
```
from ichingshifa import ichingshifa #導入周易筮法套件庫 Import ichingshifa


ichingshifa.Iching().mget_bookgua_details() #手動起卦,從下而上,適合以蓍草起卦者使用,譬如 "初爻7, 二爻8, 三爻9, 四爻7, 五爻8, 上爻9",即 ichingshifa.mget_bookgua_details('789789') Manually input each of lines' value, e.g. Iching().mget_bookgua_details('789789')
ichingshifa.Iching().bookgua_details() #顯示隨機起卦結果 Making divination randomly
ichingshifa.Iching().datetime_bookgua('年', '月', '日', '時') #指定年月日時起卦 make divination with the specific datetime
ichingshifa.Iching().current_bookgua() #按現在的年月日時起卦,此法只有一動爻 make divination with the current datetime
ichingshifa.Iching().decode_gua("787987", "庚寅") #手動起卦,從下而上,起本卦之卦納甲
ichingshifa.Iching().qigua_now() #{'日期': '辛丑年戊戌月庚寅日甲申時', '大衍筮法': ['887888', '謙', '謙', {0: '亨,君子有終。', 1: '初六:謙謙君子,用涉大川,吉。', 2: '六二,鳴謙,貞吉。', 3: '九三,勞謙,君子有終,吉。', 4: '六四:無不利,撝謙。', 5: '六五:不富,以其鄰,利用侵伐,無不利。', 6: '上六:鳴謙,利用行師,征邑國。', 7: '彖︰謙,亨,天道下濟而光明,地道卑而上行。天道虧盈而益謙,地道變盈而流謙,鬼神害盈而福謙,人道惡盈而好謙。謙尊而光,卑而不可踰,君子之終也。'}, ('動爻有【0】根。', '主要看【謙】卦彖辭。', '謙,亨,天道下濟而光明,地道卑而上行。天道虧盈而益謙,地道變盈而流謙,鬼神害盈而福謙,人道惡盈而好謙。謙尊而光,卑而不可踰,君子之終也。')], '本卦': {'卦': '謙', '五星': '太白', '世應卦': '五世卦', '星宿': ['亢', '角', '軫', '翼', '張', '星'], '天干': ['丙', '丙', '丙', '癸', '癸', '癸'], '地支': ['辰', '午', '申', '丑', '亥', '酉'], '五行': ['土', '火', '金', '土', '水', '金'], '世應爻': ['初', '應', '三', '四', '世', '六'], '身爻': '兄癸酉金', '六親用神': ['父', '官', '兄', '父', '子', '兄'], '伏神': {'伏神所在爻': '官', '伏神六親': '妻', '伏神排爻數字': 1, '本卦伏神所在爻': '官丙午火', '伏神爻': '妻丁卯木'}, '六獸': ['虎', '武', '龍', '雀', '陳', '蛇'], '納甲': ['丙辰', '丙午', '丙申', '癸丑', '癸亥', '癸酉'], '建月': ['庚申', '辛酉', '壬戌', '癸亥', '甲子', '乙丑'], '積算': [['乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午'], ['辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子'], ['丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午'], ['癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子'], ['己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午'], ['乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子'], ['辛丑', '壬寅', '癸卯', '甲辰', '乙巳', '丙午'], ['丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子'], ['癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午'], ['己未', '庚申', '辛酉', '壬戌', '癸亥', '甲子']]}, '之卦': {'卦': '謙', '五星': '太白', '世應卦': '五世卦', '星宿': ['亢', '角', '軫', '翼', '張', '星'], '天干': ['丙', '丙', '丙', '癸', '癸', '癸'], '地支': ['辰', '午', '申', '丑', '亥', '酉'], '五行': ['土', '火', '金', '土', '水', '金'], '世應爻': ['初', '應', '三', '四', '世', '六'], '身爻': '兄癸酉金', '六親用神': ['父', '官', '兄', '父', '子', '兄'], '伏神': {'伏神所在爻': '官', '伏神六親': '妻', '伏神排爻數字': 1, '本卦伏神所在爻': '官丙午火', '伏神爻': '妻丁卯木'}, '六獸': ['虎', '武', '龍', '雀', '陳', '蛇'], '納甲': ['丙辰', '丙午', '丙申', '癸丑', '癸亥', '癸酉'], '建月': ['庚申', '辛酉', '壬戌', '癸亥', '甲子', '乙丑'], '積算': [['乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午'], ['辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子'], ['丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午'], ['癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子'], ['己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午'], ['乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子'], ['辛丑', '壬寅', '癸卯', '甲辰', '乙巳', '丙午'], ['丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子'], ['癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午'], ['己未', '庚申', '辛酉', '壬戌', '癸亥', '甲子']]}, '飛神': ''}

```
## **6. 軟件 Application**
A mobile app of Ichingshifa written in Kivy
https://github.com/kentang2017/iching_shifa/blob/master/kinshifa-0.2-release.apk




%package -n python3-ichingshifa
Summary:	A package of iching stalk divination in Traditional Chinese Language. Python周易筮法,納甲六爻,起卦不求人。
Provides:	python-ichingshifa
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-ichingshifa
# Python IchingShifa Python 周易 筮法 卜卦 (stalk divination)

[![Python](https://img.shields.io/pypi/pyversions/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![PIP](https://img.shields.io/pypi/v/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![Downloads](https://img.shields.io/pypi/dm/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![TG](https://img.shields.io/badge/chat-on%20telegram-blue)](https://t.me/gnatnek)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg?logo=paypal&style=flat-square)](https://www.paypal.me/kinyeah) 

![alt text](https://upload.wikimedia.org/wikipedia/commons/a/af/French_Polished_Yarrow_stalks_from_LPKaster.jpg "Stalk divination")

"筮"是傳統的周易起卦方式。古人以50根蓍草作為占卜工具,名為策,故此法亦稱"籌策"占卜。《周易系辭上傳》辭曰:"大衍之數五十,其用四十有九。分而為二以像兩,掛一以像三, 揲之以四以像四時,歸奇於扐以像閏,五歲再閏,故再扐而後掛。 天一地二,天三地四,天五地六,天七地八,天九地十。天數五,地數五,五位相得而各有合。天數二十有五,地數三十,凡天地之數五十有五。此所以成變化而行鬼神也。"整個起卦過程是要求得十八個隨機數目,當中包括"六次"(即六根爻)的"三變"。


**"Shi"(筮)** or so-called Stalk divination, one of the oldest IChing divination method in the Chinese society, in which the ancient Chinese used 50 sticks of yarrow stalks to do divination or prediction. According to Zhouyi 周易, the number of "Da Yan" (大衍) is 50 while 1 is taken away and 49 sticks of yarrow stalks were used in divination. 49 stalks were seperated into 2 bunches respectively held by both left hand and right hand, and then one stick would be extracted from the right hand, the bunch of stalks held by right hand was divided by four, until the remainder comes, that is called the change (or 'bian'), repeating thrice. The whole process of this divination includes getting 18 random numbers. The value of Line may come after  "Three Changes", that is  (49 stalks - first change - second change - third change) divided by 4, it will be either **6(old yin 老陰)**, **7(young yang 少陽)**, **8(young yin 少陰)**, or **9(old yang 老陽)**.  The BenGua (本卦) is formed when the value of Line is formed from the bottom to the top. If the line with value of either 6 or 9, meaning that line must have a change, like 6(old yin) change to 7(young yang), and 9 (old yang) change to 8 (old yin). Each of the lines has its own meaning or explantion. BianGua (變卦) or ZhiGua (之卦) is also formed after BenGua with value 6 or 9 has been changed. 


## **1. 大衍之數、太一、分二、掛一、揲四、歸奇 The number of DaYan**︰

```python
#一變的過程
n=2
stalks_first = 50-1  #把太一拿走
dividers = sorted(random.sample(range(24, stalks_first), n - 1)) #分二
division  = [a - b for a, b in zip(dividers + [stalks_first+10], [10] + dividers)]
guayi = 1 #掛一
right = division[0] - guayi 
left_extract = division[1] % 4  #揲四
if left_extract == 0:
    left_extract = 4
right_extract = right % 4
if right_extract == 0:
    right_extract = 4 #歸奇
bian  = left_extract + right_extract + guayi #一變,其餘二變倣效此法,如果做for loop 這裡的掛一可以拿走,不用加上。
```

## **2. 處理變(動)爻的方法︰The way in handling the change of line(s)(yao(s))**

1. 凡卦六爻皆不變,則占本卦彖辭,而以內卦為貞,外卦為悔,彖辭為卦下之辭。

2. 一爻變,則以本卦變爻辭

3. 二爻變,則以本卦二變爻辭占,仍以上爻為主

4. 三爻變,則占本卦及之卦之彖辭,即以本卦為貞,之卦為悔,前十卦(初爻出現變爻)主貞,後十卦(非初爻出現變爻)主悔

5. 四爻變,則以之卦二不變爻占,仍以下爻為主經,亦無文,今以例推之當如此。

6. 五爻變,則以之卦不變爻占。

7. 六爻變,則乾、坤占二用,餘卦占之卦彖辭。

_參考自【宋】‧朱熹、蔡元定《易學啟蒙》卷下 考變占︰_

1. If the Six lines without any changed lines, the explantion of Gua is based on the general explanation of BenGua. 
2. If the Six lines with one line changed, the explanation is depended on there. 
3. If the Six lines with two lines changed, the upper one is the main explanation. 
4. If the Six lines with three lines changed, the explanation is lied on the BenGua's general explanation if the change line starts from the first line, while the explantion is base on BianGua's general explanation if the change line starts from the second line. 
5. If the Six lines with four lines changed,  the explanation is upon the lower line of BianGua. 
6. If the Six lines with five lines changed,  the explanation is upon the one line without change on BianGua. 
7. If the Six lines with six lines changed, except for QianGua and KunGua with explanation on 用, use the general explanation  
_The above method is advocated by ZhuXi, a Confucian of Song Dynasty_

![alt text](https://github.com/kentang2017/iching_shifa/blob/master/data/results.png?raw=true)

## **3. 納甲 Najia **:

其後漢元帝師從梁人焦延壽的京房開創京氏易學,把筮法加入干支納甲,後世學者再加以五行、五星、六親及二十八宿等加以詳推。

Later on, an iching expert Jing Fang during the Han Dynasty created a najia method of hexagram interpretation amongiching. which correlates their separate lines with elements of the Chinese calendar.


## **4. 安裝套件 Installation**:
```
pip install --upgrade ichingshifa
```

## **5. 快速起卦 Quick Start**:
```
from ichingshifa import ichingshifa #導入周易筮法套件庫 Import ichingshifa


ichingshifa.Iching().mget_bookgua_details() #手動起卦,從下而上,適合以蓍草起卦者使用,譬如 "初爻7, 二爻8, 三爻9, 四爻7, 五爻8, 上爻9",即 ichingshifa.mget_bookgua_details('789789') Manually input each of lines' value, e.g. Iching().mget_bookgua_details('789789')
ichingshifa.Iching().bookgua_details() #顯示隨機起卦結果 Making divination randomly
ichingshifa.Iching().datetime_bookgua('年', '月', '日', '時') #指定年月日時起卦 make divination with the specific datetime
ichingshifa.Iching().current_bookgua() #按現在的年月日時起卦,此法只有一動爻 make divination with the current datetime
ichingshifa.Iching().decode_gua("787987", "庚寅") #手動起卦,從下而上,起本卦之卦納甲
ichingshifa.Iching().qigua_now() #{'日期': '辛丑年戊戌月庚寅日甲申時', '大衍筮法': ['887888', '謙', '謙', {0: '亨,君子有終。', 1: '初六:謙謙君子,用涉大川,吉。', 2: '六二,鳴謙,貞吉。', 3: '九三,勞謙,君子有終,吉。', 4: '六四:無不利,撝謙。', 5: '六五:不富,以其鄰,利用侵伐,無不利。', 6: '上六:鳴謙,利用行師,征邑國。', 7: '彖︰謙,亨,天道下濟而光明,地道卑而上行。天道虧盈而益謙,地道變盈而流謙,鬼神害盈而福謙,人道惡盈而好謙。謙尊而光,卑而不可踰,君子之終也。'}, ('動爻有【0】根。', '主要看【謙】卦彖辭。', '謙,亨,天道下濟而光明,地道卑而上行。天道虧盈而益謙,地道變盈而流謙,鬼神害盈而福謙,人道惡盈而好謙。謙尊而光,卑而不可踰,君子之終也。')], '本卦': {'卦': '謙', '五星': '太白', '世應卦': '五世卦', '星宿': ['亢', '角', '軫', '翼', '張', '星'], '天干': ['丙', '丙', '丙', '癸', '癸', '癸'], '地支': ['辰', '午', '申', '丑', '亥', '酉'], '五行': ['土', '火', '金', '土', '水', '金'], '世應爻': ['初', '應', '三', '四', '世', '六'], '身爻': '兄癸酉金', '六親用神': ['父', '官', '兄', '父', '子', '兄'], '伏神': {'伏神所在爻': '官', '伏神六親': '妻', '伏神排爻數字': 1, '本卦伏神所在爻': '官丙午火', '伏神爻': '妻丁卯木'}, '六獸': ['虎', '武', '龍', '雀', '陳', '蛇'], '納甲': ['丙辰', '丙午', '丙申', '癸丑', '癸亥', '癸酉'], '建月': ['庚申', '辛酉', '壬戌', '癸亥', '甲子', '乙丑'], '積算': [['乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午'], ['辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子'], ['丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午'], ['癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子'], ['己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午'], ['乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子'], ['辛丑', '壬寅', '癸卯', '甲辰', '乙巳', '丙午'], ['丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子'], ['癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午'], ['己未', '庚申', '辛酉', '壬戌', '癸亥', '甲子']]}, '之卦': {'卦': '謙', '五星': '太白', '世應卦': '五世卦', '星宿': ['亢', '角', '軫', '翼', '張', '星'], '天干': ['丙', '丙', '丙', '癸', '癸', '癸'], '地支': ['辰', '午', '申', '丑', '亥', '酉'], '五行': ['土', '火', '金', '土', '水', '金'], '世應爻': ['初', '應', '三', '四', '世', '六'], '身爻': '兄癸酉金', '六親用神': ['父', '官', '兄', '父', '子', '兄'], '伏神': {'伏神所在爻': '官', '伏神六親': '妻', '伏神排爻數字': 1, '本卦伏神所在爻': '官丙午火', '伏神爻': '妻丁卯木'}, '六獸': ['虎', '武', '龍', '雀', '陳', '蛇'], '納甲': ['丙辰', '丙午', '丙申', '癸丑', '癸亥', '癸酉'], '建月': ['庚申', '辛酉', '壬戌', '癸亥', '甲子', '乙丑'], '積算': [['乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午'], ['辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子'], ['丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午'], ['癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子'], ['己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午'], ['乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子'], ['辛丑', '壬寅', '癸卯', '甲辰', '乙巳', '丙午'], ['丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子'], ['癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午'], ['己未', '庚申', '辛酉', '壬戌', '癸亥', '甲子']]}, '飛神': ''}

```
## **6. 軟件 Application**
A mobile app of Ichingshifa written in Kivy
https://github.com/kentang2017/iching_shifa/blob/master/kinshifa-0.2-release.apk




%package help
Summary:	Development documents and examples for ichingshifa
Provides:	python3-ichingshifa-doc
%description help
# Python IchingShifa Python 周易 筮法 卜卦 (stalk divination)

[![Python](https://img.shields.io/pypi/pyversions/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![PIP](https://img.shields.io/pypi/v/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![Downloads](https://img.shields.io/pypi/dm/ichingshifa)](https://pypi.org/project/ichingshifa/)
[![TG](https://img.shields.io/badge/chat-on%20telegram-blue)](https://t.me/gnatnek)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg?logo=paypal&style=flat-square)](https://www.paypal.me/kinyeah) 

![alt text](https://upload.wikimedia.org/wikipedia/commons/a/af/French_Polished_Yarrow_stalks_from_LPKaster.jpg "Stalk divination")

"筮"是傳統的周易起卦方式。古人以50根蓍草作為占卜工具,名為策,故此法亦稱"籌策"占卜。《周易系辭上傳》辭曰:"大衍之數五十,其用四十有九。分而為二以像兩,掛一以像三, 揲之以四以像四時,歸奇於扐以像閏,五歲再閏,故再扐而後掛。 天一地二,天三地四,天五地六,天七地八,天九地十。天數五,地數五,五位相得而各有合。天數二十有五,地數三十,凡天地之數五十有五。此所以成變化而行鬼神也。"整個起卦過程是要求得十八個隨機數目,當中包括"六次"(即六根爻)的"三變"。


**"Shi"(筮)** or so-called Stalk divination, one of the oldest IChing divination method in the Chinese society, in which the ancient Chinese used 50 sticks of yarrow stalks to do divination or prediction. According to Zhouyi 周易, the number of "Da Yan" (大衍) is 50 while 1 is taken away and 49 sticks of yarrow stalks were used in divination. 49 stalks were seperated into 2 bunches respectively held by both left hand and right hand, and then one stick would be extracted from the right hand, the bunch of stalks held by right hand was divided by four, until the remainder comes, that is called the change (or 'bian'), repeating thrice. The whole process of this divination includes getting 18 random numbers. The value of Line may come after  "Three Changes", that is  (49 stalks - first change - second change - third change) divided by 4, it will be either **6(old yin 老陰)**, **7(young yang 少陽)**, **8(young yin 少陰)**, or **9(old yang 老陽)**.  The BenGua (本卦) is formed when the value of Line is formed from the bottom to the top. If the line with value of either 6 or 9, meaning that line must have a change, like 6(old yin) change to 7(young yang), and 9 (old yang) change to 8 (old yin). Each of the lines has its own meaning or explantion. BianGua (變卦) or ZhiGua (之卦) is also formed after BenGua with value 6 or 9 has been changed. 


## **1. 大衍之數、太一、分二、掛一、揲四、歸奇 The number of DaYan**︰

```python
#一變的過程
n=2
stalks_first = 50-1  #把太一拿走
dividers = sorted(random.sample(range(24, stalks_first), n - 1)) #分二
division  = [a - b for a, b in zip(dividers + [stalks_first+10], [10] + dividers)]
guayi = 1 #掛一
right = division[0] - guayi 
left_extract = division[1] % 4  #揲四
if left_extract == 0:
    left_extract = 4
right_extract = right % 4
if right_extract == 0:
    right_extract = 4 #歸奇
bian  = left_extract + right_extract + guayi #一變,其餘二變倣效此法,如果做for loop 這裡的掛一可以拿走,不用加上。
```

## **2. 處理變(動)爻的方法︰The way in handling the change of line(s)(yao(s))**

1. 凡卦六爻皆不變,則占本卦彖辭,而以內卦為貞,外卦為悔,彖辭為卦下之辭。

2. 一爻變,則以本卦變爻辭

3. 二爻變,則以本卦二變爻辭占,仍以上爻為主

4. 三爻變,則占本卦及之卦之彖辭,即以本卦為貞,之卦為悔,前十卦(初爻出現變爻)主貞,後十卦(非初爻出現變爻)主悔

5. 四爻變,則以之卦二不變爻占,仍以下爻為主經,亦無文,今以例推之當如此。

6. 五爻變,則以之卦不變爻占。

7. 六爻變,則乾、坤占二用,餘卦占之卦彖辭。

_參考自【宋】‧朱熹、蔡元定《易學啟蒙》卷下 考變占︰_

1. If the Six lines without any changed lines, the explantion of Gua is based on the general explanation of BenGua. 
2. If the Six lines with one line changed, the explanation is depended on there. 
3. If the Six lines with two lines changed, the upper one is the main explanation. 
4. If the Six lines with three lines changed, the explanation is lied on the BenGua's general explanation if the change line starts from the first line, while the explantion is base on BianGua's general explanation if the change line starts from the second line. 
5. If the Six lines with four lines changed,  the explanation is upon the lower line of BianGua. 
6. If the Six lines with five lines changed,  the explanation is upon the one line without change on BianGua. 
7. If the Six lines with six lines changed, except for QianGua and KunGua with explanation on 用, use the general explanation  
_The above method is advocated by ZhuXi, a Confucian of Song Dynasty_

![alt text](https://github.com/kentang2017/iching_shifa/blob/master/data/results.png?raw=true)

## **3. 納甲 Najia **:

其後漢元帝師從梁人焦延壽的京房開創京氏易學,把筮法加入干支納甲,後世學者再加以五行、五星、六親及二十八宿等加以詳推。

Later on, an iching expert Jing Fang during the Han Dynasty created a najia method of hexagram interpretation amongiching. which correlates their separate lines with elements of the Chinese calendar.


## **4. 安裝套件 Installation**:
```
pip install --upgrade ichingshifa
```

## **5. 快速起卦 Quick Start**:
```
from ichingshifa import ichingshifa #導入周易筮法套件庫 Import ichingshifa


ichingshifa.Iching().mget_bookgua_details() #手動起卦,從下而上,適合以蓍草起卦者使用,譬如 "初爻7, 二爻8, 三爻9, 四爻7, 五爻8, 上爻9",即 ichingshifa.mget_bookgua_details('789789') Manually input each of lines' value, e.g. Iching().mget_bookgua_details('789789')
ichingshifa.Iching().bookgua_details() #顯示隨機起卦結果 Making divination randomly
ichingshifa.Iching().datetime_bookgua('年', '月', '日', '時') #指定年月日時起卦 make divination with the specific datetime
ichingshifa.Iching().current_bookgua() #按現在的年月日時起卦,此法只有一動爻 make divination with the current datetime
ichingshifa.Iching().decode_gua("787987", "庚寅") #手動起卦,從下而上,起本卦之卦納甲
ichingshifa.Iching().qigua_now() #{'日期': '辛丑年戊戌月庚寅日甲申時', '大衍筮法': ['887888', '謙', '謙', {0: '亨,君子有終。', 1: '初六:謙謙君子,用涉大川,吉。', 2: '六二,鳴謙,貞吉。', 3: '九三,勞謙,君子有終,吉。', 4: '六四:無不利,撝謙。', 5: '六五:不富,以其鄰,利用侵伐,無不利。', 6: '上六:鳴謙,利用行師,征邑國。', 7: '彖︰謙,亨,天道下濟而光明,地道卑而上行。天道虧盈而益謙,地道變盈而流謙,鬼神害盈而福謙,人道惡盈而好謙。謙尊而光,卑而不可踰,君子之終也。'}, ('動爻有【0】根。', '主要看【謙】卦彖辭。', '謙,亨,天道下濟而光明,地道卑而上行。天道虧盈而益謙,地道變盈而流謙,鬼神害盈而福謙,人道惡盈而好謙。謙尊而光,卑而不可踰,君子之終也。')], '本卦': {'卦': '謙', '五星': '太白', '世應卦': '五世卦', '星宿': ['亢', '角', '軫', '翼', '張', '星'], '天干': ['丙', '丙', '丙', '癸', '癸', '癸'], '地支': ['辰', '午', '申', '丑', '亥', '酉'], '五行': ['土', '火', '金', '土', '水', '金'], '世應爻': ['初', '應', '三', '四', '世', '六'], '身爻': '兄癸酉金', '六親用神': ['父', '官', '兄', '父', '子', '兄'], '伏神': {'伏神所在爻': '官', '伏神六親': '妻', '伏神排爻數字': 1, '本卦伏神所在爻': '官丙午火', '伏神爻': '妻丁卯木'}, '六獸': ['虎', '武', '龍', '雀', '陳', '蛇'], '納甲': ['丙辰', '丙午', '丙申', '癸丑', '癸亥', '癸酉'], '建月': ['庚申', '辛酉', '壬戌', '癸亥', '甲子', '乙丑'], '積算': [['乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午'], ['辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子'], ['丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午'], ['癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子'], ['己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午'], ['乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子'], ['辛丑', '壬寅', '癸卯', '甲辰', '乙巳', '丙午'], ['丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子'], ['癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午'], ['己未', '庚申', '辛酉', '壬戌', '癸亥', '甲子']]}, '之卦': {'卦': '謙', '五星': '太白', '世應卦': '五世卦', '星宿': ['亢', '角', '軫', '翼', '張', '星'], '天干': ['丙', '丙', '丙', '癸', '癸', '癸'], '地支': ['辰', '午', '申', '丑', '亥', '酉'], '五行': ['土', '火', '金', '土', '水', '金'], '世應爻': ['初', '應', '三', '四', '世', '六'], '身爻': '兄癸酉金', '六親用神': ['父', '官', '兄', '父', '子', '兄'], '伏神': {'伏神所在爻': '官', '伏神六親': '妻', '伏神排爻數字': 1, '本卦伏神所在爻': '官丙午火', '伏神爻': '妻丁卯木'}, '六獸': ['虎', '武', '龍', '雀', '陳', '蛇'], '納甲': ['丙辰', '丙午', '丙申', '癸丑', '癸亥', '癸酉'], '建月': ['庚申', '辛酉', '壬戌', '癸亥', '甲子', '乙丑'], '積算': [['乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午'], ['辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子'], ['丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午'], ['癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子'], ['己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午'], ['乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子'], ['辛丑', '壬寅', '癸卯', '甲辰', '乙巳', '丙午'], ['丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子'], ['癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午'], ['己未', '庚申', '辛酉', '壬戌', '癸亥', '甲子']]}, '飛神': ''}

```
## **6. 軟件 Application**
A mobile app of Ichingshifa written in Kivy
https://github.com/kentang2017/iching_shifa/blob/master/kinshifa-0.2-release.apk




%prep
%autosetup -n ichingshifa-3.1.8

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-ichingshifa -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Thu May 18 2023 Python_Bot <Python_Bot@openeuler.org> - 3.1.8-1
- Package Spec generated