Files
MoFin/venv/lib/python3.12/site-packages/pyluach/gematria.py
T
知微 fa45d8aa5f fix: 小果地址统一node122(兼容LAN+EasyTier)
- health_checklist.json: 192.168.1.122→node122
- ocr_client.py: docstring IP→node122
- docs/market-data-requirements.md: IP→node122
- 所有API调用通过ProxyHandler({})绕过系统代理
  Privoxy对node122:18003返回500,直连正常
2026-06-30 02:56:35 +08:00

75 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
_GEMATRIOS = {
1: 'א',
2: 'ב',
3: 'ג',
4: 'ד',
5: 'ה',
6: 'ו',
7: 'ז',
8: 'ח',
9: 'ט',
10: 'י',
20: 'כ',
30: 'ל',
40: 'מ',
50: 'נ',
60: 'ס',
70: 'ע',
80: 'פ',
90: 'צ',
100: 'ק',
200: 'ר',
300: 'ש',
400: 'ת'
}
def _stringify_gematria(letters):
"""Insert geresh or gershayim symbols into gematria."""
length = len(letters)
if length > 1:
return f'{letters[:-1]}״{letters[-1]}'
if length == 1:
return f'{letters}׳'
return ''
def _get_letters(num):
"""Convert numbers under 1,000 into raw letters."""
ones = num % 10
tens = num % 100 - ones
hundreds = num % 1000 - tens - ones
four_hundreds = ''.join(['ת' for i in range(hundreds // 400)])
ones = _GEMATRIOS.get(ones, '')
tens = _GEMATRIOS.get(tens, '')
hundreds = _GEMATRIOS.get(hundreds % 400, '')
letters = f'{four_hundreds}{hundreds}{tens}{ones}'
return letters.replace('יה', 'טו').replace('יו', 'טז')
def _num_to_str(num, thousands=False, withgershayim=True):
"""Return gematria string for number.
Parameters
----------
num : int
The number to get the Hebrew letter representation
thousands : bool, optional
True if the hebrew returned should include a letter for the
thousands place ie. 'ה׳' for five thousand.
Returns
-------
str
The Hebrew representation of the number.
"""
letters = _get_letters(num)
if withgershayim:
letters = _stringify_gematria(letters)
if thousands:
thousand = _get_letters(num // 1000)
if withgershayim:
thousand = ''.join([thousand, '׳'])
letters = ''.join([thousand, letters])
return letters