|
| 1 | +import requests |
| 2 | + |
| 3 | + |
| 4 | +def get_info(sign, day): |
| 5 | + """This function makes the API call to get the result |
| 6 | + of the desired zodiac sign for the desired day.""" |
| 7 | + |
| 8 | + base_url = "https://sameer-kumar-aztro-v1.p.rapidapi.com/" |
| 9 | + |
| 10 | + parameters = {"sign": sign, "day": day} |
| 11 | + |
| 12 | + headers = {'x-rapidapi-host': "sameer-kumar-aztro-v1.p.rapidapi.com", |
| 13 | + 'x-rapidapi-key': |
| 14 | + "9b63804a3cmsh368b3af884ede93p1e0b5djsn7ebb3eb30986"} |
| 15 | + |
| 16 | + robj = requests.post(base_url, headers=headers, params=parameters) |
| 17 | + return_object = robj.json() |
| 18 | + if robj.status_code == 200: |
| 19 | + res = f'''We see that you are {sign.capitalize()}. Your horoscope for the date |
| 20 | + {return_object['current_date']} says that : '{return_object["description"]}'\n |
| 21 | + You are compatible with {return_object["compatibility"]}. Your lucky color, |
| 22 | + number and time are {return_object["color"]}, {return_object["lucky_number"]} |
| 23 | + and {return_object["lucky_time"]} respectively.\n |
| 24 | + You are expected to be in '{return_object["mood"]}' mood.''' |
| 25 | + |
| 26 | + return res |
| 27 | + else: |
| 28 | + return "Sorry! No result found." |
| 29 | + |
| 30 | + |
| 31 | +def bad_input(container, code): |
| 32 | + """This function is used to handle bad user input and gives the user a choice |
| 33 | + to either QUIT the game or enter a valid input.""" |
| 34 | + |
| 35 | + print("\nThis is NOT a valid entry.") |
| 36 | + yn = input("Are you requesting to QUIT? (press y / n) : ") |
| 37 | + if yn == 'y': |
| 38 | + print("\nThankyou for holding up!\n") |
| 39 | + return 1 |
| 40 | + elif yn == 'n': |
| 41 | + print("\nPlease enter a valid number.\n") |
| 42 | + return 0 |
| 43 | + else: |
| 44 | + print("\nBad Input Again!\nBye Bye.\n") |
| 45 | + return 1 |
| 46 | + |
| 47 | + |
| 48 | +def main(): |
| 49 | + """This function displays the complete menu to the user and asks |
| 50 | + for user input. It also invokes bad_input() function in case of |
| 51 | + an invalid entry by the user. It then invokes the get_info() function |
| 52 | + to collect the required result and print it.""" |
| 53 | + |
| 54 | + info_zodiac = ''' |
| 55 | + Hello and Welcome to your Horoscope Destination!\n\n |
| 56 | + Select your Zodiac Sign from the list below. Press the code |
| 57 | + along the Sign to proceed.\n |
| 58 | + 1. Aries |
| 59 | + 2. Taurus |
| 60 | + 3. Gemini |
| 61 | + 4. Cancer |
| 62 | + 5. Leo |
| 63 | + 6. Virgo |
| 64 | + 7. Libra |
| 65 | + 8. Scorpio |
| 66 | + 9. Sagittarius |
| 67 | + 10. Capricorn |
| 68 | + 11. Aquarius |
| 69 | + 12. Pisces |
| 70 | + Press any other character to QUIT.\n''' |
| 71 | + |
| 72 | + info_day = ''' |
| 73 | + Which day's horoscope are you looking for?\n |
| 74 | + 1. Yesterday |
| 75 | + 2. Today |
| 76 | + 3. Tomorrow |
| 77 | + Press any other character to QUIT.\n''' |
| 78 | + |
| 79 | + zodiac = {'1': 'aries', '2': 'taurus', '3': 'gemini', |
| 80 | + '4': 'cancer', '5': 'leo', '6': 'virgo', '7': 'libra', |
| 81 | + '8': 'scorpio', '9': 'sagittarius', '10': 'capricorn', |
| 82 | + '11': 'aquarius', '12': 'pisces'} |
| 83 | + day = {'1': "yesterday", '2': "today", '3': "tomorrow"} |
| 84 | + |
| 85 | + zodiac_code, day_code = 0, 0 |
| 86 | + |
| 87 | + print(info_zodiac) |
| 88 | + |
| 89 | + while True: |
| 90 | + |
| 91 | + while True: |
| 92 | + zodiac_code = input("Press the zodiac code : ") |
| 93 | + if not zodiac.get(zodiac_code, 0): |
| 94 | + if bad_input(zodiac, zodiac_code): |
| 95 | + return |
| 96 | + else: |
| 97 | + continue |
| 98 | + break |
| 99 | + |
| 100 | + print(info_day) |
| 101 | + |
| 102 | + while True: |
| 103 | + day_code = input("Press the day code : ") |
| 104 | + if not day.get(day_code, 0): |
| 105 | + if bad_input(day, day_code): |
| 106 | + return |
| 107 | + else: |
| 108 | + continue |
| 109 | + break |
| 110 | + result = get_info(zodiac[zodiac_code], day[day_code]) |
| 111 | + print(f'\n\nWe have an astro prediction for you!\n\n" {result} "\n') |
| 112 | + |
| 113 | + |
| 114 | +if __name__ == '__main__': |
| 115 | + """The main driver code.""" |
| 116 | + main() |
0 commit comments