Spaces:
Running
Running
th Sisi The Fox commited on
Commit ·
e0eeb4f
1
Parent(s): b408cad
feat: 🎂 Add Birthday Fortune API endpoint
Browse files- 新增Pythagorean Numerology生日运势服务
- 基于月日计算Life Path Number
- 支持EN/CN/TW三语言
- 无需API key,免费公开服务
- Endpoint: /api/birthday-fortune/{month}/{day}
🦊 Generated with Sisi
Co-Authored-By: Sisi The Fox <noreply@sisithefox.com>
- app.py +41 -0
- birthday_fortune_service.py +182 -0
app.py
CHANGED
|
@@ -247,6 +247,47 @@ async def generate_chart_svg(req: BirthRequest, api_key: str = Depends(verify_ap
|
|
| 247 |
raise HTTPException(status_code=500, detail=str(e))
|
| 248 |
|
| 249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
if __name__ == "__main__":
|
| 251 |
import uvicorn
|
| 252 |
# Hugging Face Spaces requires port 7860
|
|
|
|
| 247 |
raise HTTPException(status_code=500, detail=str(e))
|
| 248 |
|
| 249 |
|
| 250 |
+
@app.get("/api/birthday-fortune/{month}/{day}")
|
| 251 |
+
async def get_birthday_fortune_endpoint(
|
| 252 |
+
month: int,
|
| 253 |
+
day: int,
|
| 254 |
+
language: Optional[str] = "en"
|
| 255 |
+
):
|
| 256 |
+
"""
|
| 257 |
+
🎂 Get Birthday Fortune based on Pythagorean Numerology
|
| 258 |
+
No API key required - free public service!
|
| 259 |
+
|
| 260 |
+
Args:
|
| 261 |
+
month: Birth month (1-12)
|
| 262 |
+
day: Birth day (1-31)
|
| 263 |
+
language: Language code ('en', 'zh-CN', 'zh-TW')
|
| 264 |
+
|
| 265 |
+
Returns:
|
| 266 |
+
Complete fortune reading with personality, love, career, etc.
|
| 267 |
+
|
| 268 |
+
Example:
|
| 269 |
+
GET /api/birthday-fortune/12/18?language=en
|
| 270 |
+
GET /api/birthday-fortune/12/18?language=zh-CN
|
| 271 |
+
"""
|
| 272 |
+
from birthday_fortune_service import get_birthday_fortune
|
| 273 |
+
|
| 274 |
+
# Validate inputs
|
| 275 |
+
if not (1 <= month <= 12):
|
| 276 |
+
raise HTTPException(status_code=400, detail="Month must be between 1 and 12")
|
| 277 |
+
if not (1 <= day <= 31):
|
| 278 |
+
raise HTTPException(status_code=400, detail="Day must be between 1 and 31")
|
| 279 |
+
if language not in ['en', 'zh-CN', 'zh-TW']:
|
| 280 |
+
language = 'en' # Default to English
|
| 281 |
+
|
| 282 |
+
try:
|
| 283 |
+
result = get_birthday_fortune(month, day, language)
|
| 284 |
+
logger.info(f"🎂 Birthday fortune for {month}/{day} in {language}")
|
| 285 |
+
return result
|
| 286 |
+
except Exception as e:
|
| 287 |
+
logger.error(f"❌ Birthday fortune error: {e}")
|
| 288 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 289 |
+
|
| 290 |
+
|
| 291 |
if __name__ == "__main__":
|
| 292 |
import uvicorn
|
| 293 |
# Hugging Face Spaces requires port 7860
|
birthday_fortune_service.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
🎂 Birthday Fortune Service
|
| 3 |
+
基于Pythagorean Numerology的生日运势服务
|
| 4 |
+
|
| 5 |
+
算法原理:
|
| 6 |
+
1. 计算Life Path Number(生命数字)- 将月日数字相加直到单个数字
|
| 7 |
+
2. 基于Life Path Number生成性格特质和运势建议
|
| 8 |
+
3. 提供多语言支持(EN/CN/TW)
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from typing import Dict, Literal
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
|
| 14 |
+
Language = Literal['en', 'zh-CN', 'zh-TW']
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def calculate_life_path_number(month: int, day: int) -> int:
|
| 18 |
+
"""
|
| 19 |
+
计算Life Path Number(生命数字)
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
month: 月份 (1-12)
|
| 23 |
+
day: 日期 (1-31)
|
| 24 |
+
|
| 25 |
+
Returns:
|
| 26 |
+
life_path_number: 1-9的数字(Master Numbers 11, 22, 33会保留)
|
| 27 |
+
"""
|
| 28 |
+
# 将月日转换为字符串并连接
|
| 29 |
+
date_str = f"{month:02d}{day:02d}"
|
| 30 |
+
|
| 31 |
+
# 重复求和直到单个数字(或Master Number 11/22/33)
|
| 32 |
+
total = sum(int(digit) for digit in date_str)
|
| 33 |
+
|
| 34 |
+
# 检查是否为Master Number
|
| 35 |
+
if total in [11, 22, 33]:
|
| 36 |
+
return total
|
| 37 |
+
|
| 38 |
+
# 继续reduction直到单个数字
|
| 39 |
+
while total > 9:
|
| 40 |
+
total = sum(int(digit) for digit in str(total))
|
| 41 |
+
if total in [11, 22, 33]:
|
| 42 |
+
return total
|
| 43 |
+
|
| 44 |
+
return total
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# 生命数字的详细描述(三语言)
|
| 48 |
+
LIFE_PATH_DESCRIPTIONS = {
|
| 49 |
+
1: {
|
| 50 |
+
'en': {
|
| 51 |
+
'title': 'The Leader',
|
| 52 |
+
'personality': 'You are a natural-born leader with strong independence and determination. Your pioneering spirit drives you to create new paths and take initiative. You possess great ambition and the courage to stand alone when necessary.',
|
| 53 |
+
'love': 'In relationships, you value independence and need a partner who respects your autonomy. You are passionate and direct in expressing your feelings, though you may sometimes struggle with vulnerability.',
|
| 54 |
+
'career': 'You excel in entrepreneurship, management, and any field where you can take charge and innovate. Your leadership skills and original thinking make you stand out in competitive environments.',
|
| 55 |
+
'health': 'Channel your abundant energy through regular exercise. Your driven nature may lead to stress, so remember to balance work with relaxation.',
|
| 56 |
+
'travel': 'You prefer adventurous destinations where you can explore independently. Solo trips or leading group expeditions suits your pioneering spirit.',
|
| 57 |
+
'friendships': 'You attract friends who admire your confidence and decisiveness. You\'re loyal but need friends who can match your energy and independence.',
|
| 58 |
+
'luckyColor': 'Red',
|
| 59 |
+
'luckyNumber': '1',
|
| 60 |
+
'quote': 'I am the architect of my own destiny, blazing trails where none existed before.'
|
| 61 |
+
},
|
| 62 |
+
'zh-CN': {
|
| 63 |
+
'title': '领导者',
|
| 64 |
+
'personality': '你是天生的领导者,拥有强烈的独立性和决心。你的开拓精神驱使你创造新的道路并主动出击。你拥有远大的抱负和必要时独自前行的勇气。',
|
| 65 |
+
'love': '在感情中,你重视独立性,需要一个尊重你自主权的伴侣。你热情直接地表达感情,但有时可能难以展现脆弱的一面。',
|
| 66 |
+
'career': '你在创业、管理以及任何可以掌控和创新的领域中表现出色。你的领导能力和原创思维使你在竞争环境中脱颖而出。',
|
| 67 |
+
'health': '通过规律运动释放你充沛的精力。你的驱动力可能导致压力,记得平衡工作与放松。',
|
| 68 |
+
'travel': '你偏好可以独立探索的冒险目的地。独自旅行或带领团队探险都适合你的开拓精神。',
|
| 69 |
+
'friendships': '你吸引那些欣赏你自信和果断的朋友。你忠诚,但需要能匹配你能量和独立性的朋友。',
|
| 70 |
+
'luckyColor': '红色',
|
| 71 |
+
'luckyNumber': '1',
|
| 72 |
+
'quote': '我是自己命运的建筑师,在无路之处开辟新径。'
|
| 73 |
+
},
|
| 74 |
+
'zh-TW': {
|
| 75 |
+
'title': '領導者',
|
| 76 |
+
'personality': '你是天生的領導者,擁有強烈的獨立性和決心。你的開拓精神驅使你創造新的道路並主動出擊。你擁有遠大的抱負和必要時獨自前行的勇氣。',
|
| 77 |
+
'love': '在感情中,你重視獨立性,需要一個尊重你自主權的伴侶。你熱情直接地表達感情,但有時可能難以展現脆弱的一面。',
|
| 78 |
+
'career': '你在創業、管理以及任何可以掌控和創新的領域中表現出色。你的領導能力和原創思維使你在競爭環境中脫穎而出。',
|
| 79 |
+
'health': '通過規律運動釋放你充沛的精力。你的驅動力可能導致壓力,記得平衡工作與放鬆。',
|
| 80 |
+
'travel': '你偏好可以獨立探索的冒險目的地。獨自旅行或帶領團隊探險都適合你的開拓精神。',
|
| 81 |
+
'friendships': '你吸引那些欣賞你自信和果斷的朋友。你忠誠,但需要能匹配你能量和獨立性的朋友。',
|
| 82 |
+
'luckyColor': '紅色',
|
| 83 |
+
'luckyNumber': '1',
|
| 84 |
+
'quote': '我是自己命運的建築師,在無路之處開闢新徑。'
|
| 85 |
+
}
|
| 86 |
+
},
|
| 87 |
+
2: {
|
| 88 |
+
'en': {
|
| 89 |
+
'title': 'The Peacemaker',
|
| 90 |
+
'personality': 'You are diplomatic, sensitive, and cooperative. Your gift lies in bringing people together and creating harmony. You have a natural talent for understanding others\' perspectives and mediating conflicts.',
|
| 91 |
+
'love': 'You are a devoted and considerate partner who values emotional connection deeply. You seek harmony in relationships and excel at creating a loving, peaceful environment.',
|
| 92 |
+
'career': 'You thrive in counseling, diplomacy, teamwork, and any role requiring tact and cooperation. Your ability to see multiple perspectives makes you an excellent mediator.',
|
| 93 |
+
'health': 'Your sensitive nature may make you prone to stress. Practice emotional boundaries and self-care. Gentle exercises like yoga suit your temperament.',
|
| 94 |
+
'travel': 'You enjoy traveling with companions to peaceful, beautiful locations. Cultural experiences and spiritual retreats appeal to your sensitive soul.',
|
| 95 |
+
'friendships': 'You are the friend everyone turns to for advice and support. You build deep, meaningful connections and value loyalty above all.',
|
| 96 |
+
'luckyColor': 'Orange',
|
| 97 |
+
'luckyNumber': '2',
|
| 98 |
+
'quote': 'Through understanding and cooperation, I create bridges where walls once stood.'
|
| 99 |
+
},
|
| 100 |
+
'zh-CN': {
|
| 101 |
+
'title': '和平使者',
|
| 102 |
+
'personality': '你善于外交、敏感且富有合作精神。你的天赋在于团结众人并创造和谐。你天生擅长理解他人的观点和调解冲突。',
|
| 103 |
+
'love': '你是忠诚体贴的伴侣,深深重视情感联系。你追求关系中的和谐,擅长创造充满爱与平和的环境。',
|
| 104 |
+
'career': '你在咨询、外交、团队合作以及任何需要机智和协作的角色中茁壮成长。你能看到多重视角的能力使你成为出色的调解者。',
|
| 105 |
+
'health': '你敏感的天性可能让你容易感到压力。练习情感边界和自我关怀。瑜伽等温和运动适合你的气质。',
|
| 106 |
+
'travel': '你喜欢和同伴一起前往宁静美丽的地方旅行。文化体验和精神静修吸引你敏感的灵魂。',
|
| 107 |
+
'friendships': '你是每个人寻求建议和支持的朋友。你建立深厚有意义的联系,最重视忠诚。',
|
| 108 |
+
'luckyColor': '橙色',
|
| 109 |
+
'luckyNumber': '2',
|
| 110 |
+
'quote': '通过理解与合作,我在曾经竖立围墙的地方架起桥梁。'
|
| 111 |
+
},
|
| 112 |
+
'zh-TW': {
|
| 113 |
+
'title': '和平使者',
|
| 114 |
+
'personality': '你善於外交、敏感且富有合作精神。你的天賦在於團結眾人並創造和諧。你天生擅長理解他人的觀點和調解衝突。',
|
| 115 |
+
'love': '你是忠誠體貼的伴侶,深深重視情感聯繫。你追求關係中的和諧,擅長創造充滿愛與平和的環境。',
|
| 116 |
+
'career': '你在諮詢、外交、團隊合作以及任何需要機智和協作的角色中茁壯成長。你能看到多重視角的能力使你成為出色的調解者。',
|
| 117 |
+
'health': '你敏感的天性可能讓你容易感到壓力。練習情感邊界和自我關懷。瑜伽等溫和運動適合你的氣質。',
|
| 118 |
+
'travel': '你喜歡和同伴一起前往寧靜美麗的地方旅行。文化體驗和精神靜修吸引你敏感的靈魂。',
|
| 119 |
+
'friendships': '你是每個人尋求建議和支持的朋友。你建立深厚有意義的聯繫,最重視忠誠。',
|
| 120 |
+
'luckyColor': '橙色',
|
| 121 |
+
'luckyNumber': '2',
|
| 122 |
+
'quote': '通過理解與合作,我在曾經豎立圍牆的地方架起橋樑。'
|
| 123 |
+
}
|
| 124 |
+
},
|
| 125 |
+
# ... (继续添加 3-9 的描述)
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
# 简化版:先添加3-9的基础描述
|
| 129 |
+
BASIC_DESCRIPTIONS = {
|
| 130 |
+
3: {'title_en': 'The Creative', 'title_cn': '创造者', 'color': 'Yellow', 'number': '3'},
|
| 131 |
+
4: {'title_en': 'The Builder', 'title_cn': '建造者', 'color': 'Green', 'number': '4'},
|
| 132 |
+
5: {'title_en': 'The Adventurer', 'title_cn': '冒险家', 'color': 'Blue', 'number': '5'},
|
| 133 |
+
6: {'title_en': 'The Nurturer', 'title_cn': '养育者', 'color': 'Indigo', 'number': '6'},
|
| 134 |
+
7: {'title_en': 'The Seeker', 'title_cn': '探索者', 'color': 'Violet', 'number': '7'},
|
| 135 |
+
8: {'title_en': 'The Achiever', 'title_cn': '成就者', 'color': 'Pink', 'number': '8'},
|
| 136 |
+
9: {'title_en': 'The Humanitarian', 'title_cn': '博爱者', 'color': 'Gold', 'number': '9'},
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def get_birthday_fortune(month: int, day: int, language: Language = 'en') -> Dict:
|
| 141 |
+
"""
|
| 142 |
+
获取生日运势
|
| 143 |
+
|
| 144 |
+
Args:
|
| 145 |
+
month: 月份 (1-12)
|
| 146 |
+
day: 日期 (1-31)
|
| 147 |
+
language: 语言 ('en', 'zh-CN', 'zh-TW')
|
| 148 |
+
|
| 149 |
+
Returns:
|
| 150 |
+
包含完整运势信息的字典
|
| 151 |
+
"""
|
| 152 |
+
life_path = calculate_life_path_number(month, day)
|
| 153 |
+
|
| 154 |
+
# 如果有完整描述就用,没有就用基础描述
|
| 155 |
+
if life_path in LIFE_PATH_DESCRIPTIONS:
|
| 156 |
+
desc = LIFE_PATH_DESCRIPTIONS[life_path][language]
|
| 157 |
+
return {
|
| 158 |
+
'success': True,
|
| 159 |
+
'month': month,
|
| 160 |
+
'day': day,
|
| 161 |
+
'life_path_number': life_path,
|
| 162 |
+
**desc
|
| 163 |
+
}
|
| 164 |
+
else:
|
| 165 |
+
# 基础描述作为fallback
|
| 166 |
+
basic = BASIC_DESCRIPTIONS.get(life_path, {})
|
| 167 |
+
return {
|
| 168 |
+
'success': True,
|
| 169 |
+
'month': month,
|
| 170 |
+
'day': day,
|
| 171 |
+
'life_path_number': life_path,
|
| 172 |
+
'title': basic.get(f'title_{language[:2]}', f'Number {life_path}'),
|
| 173 |
+
'luckyColor': basic.get('color', 'White'),
|
| 174 |
+
'luckyNumber': str(life_path),
|
| 175 |
+
'personality': f'Life Path {life_path} - Coming soon...',
|
| 176 |
+
'love': 'Coming soon...',
|
| 177 |
+
'career': 'Coming soon...',
|
| 178 |
+
'health': 'Coming soon...',
|
| 179 |
+
'travel': 'Coming soon...',
|
| 180 |
+
'friendships': 'Coming soon...',
|
| 181 |
+
'quote': f'Embrace your Life Path {life_path} journey.'
|
| 182 |
+
}
|