Skip to content

Commit a96602a

Browse files
authored
Anime tracker in python (HarshCasper#777)
* anime tracker in python * Update Readme.md * Update tracker.py * Update Readme.md * Update Readme.md * Create requirements.txt * Update Readme.md * Update and rename Readme.md to README.md * Update requirements.txt * Update tracker.py * Update README.md * Update tracker.py * Update tracker.py * Update tracker.py * Update tracker.py * Update tracker.py
1 parent 2868d5f commit a96602a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Python/Anime-tracker/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Anime Tracker in Python
2+
Python Script which will fetch information about a particular anime. The information fetched includes:
3+
- Tags (Genre)
4+
- Rating
5+
- Total episodes released till date
6+
- Active years
7+
# Packages Used
8+
- [bs4](https://pypi.org/project/bs4/)
9+
- [requests](https://pypi.org/project/requests/)
10+
# How to run
11+
Navigate to the project directory.
12+
```bash
13+
cd Rotten-Scripts/python/Anime-tracker
14+
```
15+
```bash
16+
pip install -r requirements.txt
17+
```
18+
```bash
19+
python tracker.py
20+
```
21+
## Output
22+
![](https://i.imgur.com/qSVsSjb.png)
23+
## Author
24+
- [Pritam Pawar](https://github.com/pritamp17)

Python/Anime-tracker/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bs4==0.0.1
2+
requests==2.25.1

Python/Anime-tracker/tracker.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
try:
2+
import requests
3+
from bs4 import BeautifulSoup
4+
import urllib.parse as parse
5+
import re
6+
except ImportError:
7+
print('Some modules are not installed! ')
8+
9+
def details(soup):
10+
"""
11+
BS4 Library is being used to extract HTML from the Webpages
12+
In this function we will basically select some HTML elements using parsed HTML (soup).
13+
"""
14+
info = soup.find('div', {'class': 'pure-1 md-3-5'})
15+
# now extracting the text for p tag of the div
16+
print("\nAbout the Anime : \n", "\t\t", info.find('p').getText(), "\n")
17+
total_episodes = soup.find('div', {'class': 'pure-1 md-1-5'})
18+
# using regex for only selecting numbers
19+
print("\nTotal number of episodes :\t",re.sub("[^0-9]", "", total_episodes.find('span').getText()))
20+
Active_years = soup.find('span', {'class': 'iconYear'})
21+
print("\n Years Active (From-To)\t:\t",
22+
Active_years.getText(), "-\n")
23+
rating = soup.find('div', {'class': 'avgRating'})
24+
print("Rating : ", rating.find('span').getText())
25+
tags = soup.find('div', {'class': 'tags'})
26+
list = []
27+
for _ in range(4):
28+
list.append(tags.find('ul').getText())
29+
print("\nTags : \n")
30+
print((list[0].replace("\n", " ")))
31+
def entry():
32+
"""
33+
In this function we will take input .
34+
And parse HTML using Beautifulsoup
35+
"""
36+
print("\nType complete name>>\n")
37+
anime_name = input("[+] Enter the name of the Anime : ").strip().title().replace(" ", "-")
38+
print("\n")
39+
print(anime_name)
40+
search_url = ("https://www.anime-planet.com/anime/" + anime_name)
41+
source_code = requests.get(search_url)
42+
content = source_code.content
43+
global soup
44+
# to parse the selected HTML
45+
soup = BeautifulSoup(content, features="html.parser")
46+
try:
47+
details(soup)
48+
except AttributeError:
49+
print("Anime info not found")
50+
if __name__ == "__main__":
51+
entry()

0 commit comments

Comments
 (0)