0
点赞
收藏
分享

微信扫一扫

python - 简单实现预测最近运势


根据星座预测最近运势

from bs4 import BeautifulSoup
import requests


def check_sign():
your_birth_day = input("输入您的生日的日期> ")
your_birth_month = input("输入你生日的月份> ")
if (int(your_birth_month) == 12 and int(your_birth_day) >= 22) or (
int(your_birth_month) == 1 and int(your_birth_day) <= 19
):
sign = "Capricorn"
elif (int(your_birth_month) == 1 and int(your_birth_day) >= 20) or (
int(your_birth_month) == 2 and int(your_birth_day) <= 17
):
sign = "Aquarium"
elif (int(your_birth_month) == 2 and int(your_birth_day) >= 18) or (
int(your_birth_month) == 3 and int(your_birth_day) <= 19
):
sign = "Pices"
elif (int(your_birth_month) == 3 and int(your_birth_day) >= 20) or (
int(your_birth_month) == 4 and int(your_birth_day) <= 19
):
sign = "Aries"
elif (int(your_birth_month) == 4 and int(your_birth_day) >= 20) or (
int(your_birth_month) == 5 and int(your_birth_day) <= 20
):
sign = "Taurus"
elif (int(your_birth_month) == 5 and int(your_birth_day) >= 21) or (
int(your_birth_month) == 6 and int(your_birth_day) <= 20
):
sign = "Gemini"
elif (int(your_birth_month) == 6 and int(your_birth_day) >= 21) or (
int(your_birth_month) == 7 and int(your_birth_day) <= 22
):
sign = "Cancer"
elif (int(your_birth_month) == 7 and int(your_birth_day) >= 23) or (
int(your_birth_month) == 8 and int(your_birth_day) <= 22
):
sign = "Leo"
elif (int(your_birth_month) == 8 and int(your_birth_day) >= 23) or (
int(your_birth_month) == 9 and int(your_birth_day) <= 22
):
sign = "Virgo"
elif (int(your_birth_month) == 9 and int(your_birth_day) >= 23) or (
int(your_birth_month) == 10 and int(your_birth_day) <= 22
):
sign = "Libra"
elif (int(your_birth_month) == 10 and int(your_birth_day) >= 23) or (
int(your_birth_month) == 11 and int(your_birth_day) <= 21
):
sign = "Scorpio"
elif (int(your_birth_month) == 11 and int(your_birth_day) >= 22) or (
int(your_birth_month) == 12 and int(your_birth_day) <= 21
):
sign = "Sagittarius"

return sign


def horoscope(zodiac_sign, day):
url = (
"https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{}.aspx?sign={}".format(day,
zodiac_sign)
)
soup = BeautifulSoup(requests.get(url).content, "html.parser")
return soup.find("div", class_="main-horoscope").p.text


def main():
# while 1:
print("Daily Horoscope. \n")
print(
"输入你的星座号码:\n",
"1. 白羊座-Aries\n",
"2. 金牛座-Taurus\n",
"3. 双子座-Gemini\n",
"4. 巨蟹座-Cancer\n",
"5. 狮子座-Leo\n",
"6. 处女座-Virgo\n",
"7. 天秤座-Libra\n",
"8. 天蝎座-Scorpio\n",
"9. 射手座-Sagittarius\n",
"10. 魔羯座-Capricorn\n",
"11. 水瓶座-Aquarius\n",
"12. 双鱼座-Pisces\n",
"或者,如果您不确定自己的星座,请输入'calculate'",
)
zodiac_sign = input("number> ")
if zodiac_sign != "calculate":
print("choose some day:\n", "0-yesterday\n", "1-today\n", "2-tomorrow\n")
dayNum = input("enter the day(number)> ")
dayMap = {0: 'yesterday', 1: 'today', 2: 'tomorrow'}
day = dayMap[int(dayNum)]
horoscope_text = horoscope(zodiac_sign, day)
print(horoscope_text)
else:
print("\n好的,别担心。很快你就会通过这个小测验")
print("\n恭喜!你绝对是", check_sign())


if __name__ == "__main__":
main()


举报

相关推荐

0 条评论