mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-27 14:01:12 +00:00
Merge pull request #326 from yunghog/master
Added python script for getting day-to-day horoscope using web scraping
This commit is contained in:
commit
e9780e61a9
70
scripts/Horoscope/README.md
Normal file
70
scripts/Horoscope/README.md
Normal file
|
@ -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)
|
2
scripts/Horoscope/requirements.txt
Normal file
2
scripts/Horoscope/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
beautifulsoup4
|
||||||
|
requests
|
59
scripts/Horoscope/script.py
Normal file
59
scripts/Horoscope/script.py
Normal file
|
@ -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()
|
Loading…
Reference in New Issue
Block a user