From 550da1677ded2d0a28650df237b90a2a2773abae Mon Sep 17 00:00:00 2001 From: Samartha Date: Mon, 10 Oct 2022 21:15:44 +0530 Subject: [PATCH 1/3] loop method --- scripts/Horoscope/script.py | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 scripts/Horoscope/script.py diff --git a/scripts/Horoscope/script.py b/scripts/Horoscope/script.py new file mode 100644 index 0000000..93d8049 --- /dev/null +++ b/scripts/Horoscope/script.py @@ -0,0 +1,59 @@ +# Python script to get day-to-day horoscope +import os +import requests +import msvcrt +from bs4 import BeautifulSoup + + +def printBanner(): + banner = ''' + + --------------------Read your Day-to-day horoscope------------------------ + ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗ + ██║ ██║██╔═══██╗██╔══██╗██╔═══██╗██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝ + ███████║██║ ██║██████╔╝██║ ██║███████╗██║ ██║ ██║██████╔╝█████╗ + ██╔══██║██║ ██║██╔══██╗██║ ██║╚════██║██║ ██║ ██║██╔═══╝ ██╔══╝ + ██║ ██║╚██████╔╝██║ ██║╚██████╔╝███████║╚██████╗╚██████╔╝██║ ███████╗ + + + ''' + print(banner) + + +def read_horoscope(sign: int, day: int) -> str: + if not isinstance(sign, int) or sign < 1 or sign > 12: + return "Input a valid number the represents the sign from 1 to 12" + if day < 1 or day > 3 or not isinstance(day, int): + return "Input a valid number the represents the day from 1 to 3" + days = ['yesterday', 'today', 'tomorrow'] + url = ( + f"https://www.horoscope.com/us/horoscopes/general/\ +horoscope-general-daily-{days[day-1]}.aspx?sign={sign}" + ) + soup = BeautifulSoup(requests.get(url).content, "html.parser") + return soup.find("div", class_="main-horoscope").p.text + + +def refresh(): + os.system('cls') + printBanner() + + +again = 'y' +while again == 'y': + refresh() + zodiac_sign = int(input( + "Enter your Zodiac sign:\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> " + )) + refresh() + print("Choose Day:\n[1] Yesterday\t[2] Today\t[3] Tomorrow:\n> ") + day = int(str(msvcrt.getch())[2]) + refresh() + print("Horoscope Reading\n---------------------------------------------\n") + result = read_horoscope(zodiac_sign, day) + print(result) + print('\nDo you want to read horoscope again [y/n] > ') + again = str(msvcrt.getch())[2].lower() From 5ff3ecfe65d7b6c6cc7f3355cdb5cdf425a1abf0 Mon Sep 17 00:00:00 2001 From: Samartha Date: Mon, 10 Oct 2022 21:15:55 +0530 Subject: [PATCH 2/3] update requirements --- scripts/Horoscope/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 scripts/Horoscope/requirements.txt diff --git a/scripts/Horoscope/requirements.txt b/scripts/Horoscope/requirements.txt new file mode 100644 index 0000000..a151126 --- /dev/null +++ b/scripts/Horoscope/requirements.txt @@ -0,0 +1,2 @@ +beautifulsoup4 +requests \ No newline at end of file From e6e9d065b9de820cfcc4dbd1dad065dbd976d5c3 Mon Sep 17 00:00:00 2001 From: Samartha Date: Mon, 10 Oct 2022 21:16:38 +0530 Subject: [PATCH 3/3] update readme --- scripts/Horoscope/README.md | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/Horoscope/README.md diff --git a/scripts/Horoscope/README.md b/scripts/Horoscope/README.md new file mode 100644 index 0000000..5074e5b --- /dev/null +++ b/scripts/Horoscope/README.md @@ -0,0 +1,70 @@ +# Horoscope + +> Python script to read day to day horoscope. + +## Introduction + +Horoscope Reader takes zodiac sign and gives out the horoscope readings for the given day. Information is obtained from [horoscope.com](https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx?sign=1) using web scraping technique. + +## Dependencies + +Horoscope Reader uses `beautifulsoup` to scrape information from web and `requests` to fetch the webpage of [horoscope.com](https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx?sign=1). + +### Install the dependencies + +To install dependencies run the command : + +```bash +$ pip install -r requirements.txt +``` + +This will install `beautifulsoup` and `requests` (if you dont have already). + + +## Usage + +Run the script.py + +### Input + +Input the number that corresponds to the zodiac sign. eg: If the sign is Cancer then input `4`. + +``` +Enter your Zodiac sign: +[1] Aries +[2] Taurus +[3] Gemini +[4] Cancer +[5] Leo +[6] Virgo +[7] Libra +[8] Scorpio +[9] Sagittarius +[10] Capricorn +[11] Aquarius +[12] Pisces +> 4 +``` + +Input the number corresponding to the day you want to check. eg: If you want to check for yesterday then input `1` + +``` +Choose Day: +[1] Yesterday [2] Today [3] Tomorrow: +> 1 +``` + +### Output + +Outputs the horoscope reading. If you want to continue press `y` or press `n` to quit. + +``` +Horoscope Reading +--------------------------------------------- + +Oct 9, 2022 - Compliments are apt to feel like gold to you, Taurus. There's nothing you need more than love and affection on a day like this. Beware that you may end up as putty in the hands of whoever showers you with flattery. You may also resent this need for attention and not be willing to receive it graciously. This isn't the right attitude. Receive accolades with open arms and offer an equal amount of affection in return. + +Do you want to read horoscope again [y/n] > +``` + +## Author : Samartha | [@yunghog](https://github.com/yunghog)