Skip to content

Akashii0/OtakuTorrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Step 1: Set Up the Project Structure

Create a new directory for your FastAPI project and navigate into it:

mkdir OtakuTorrent
cd OtakuTorrent

Step 2: Create a Virtual Environment

It's a good practice to use a virtual environment for Python projects:

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

Step 3: Install FastAPI and Other Dependencies

Install FastAPI and an ASGI server (like uvicorn) along with the required libraries:

pip install fastapi uvicorn beautifulsoup4 requests

Step 4: Create the Project Files

Create the following files and directories:

mkdir app
touch app/__init__.py app/main.py app/services.py app/scraper.py

Step 5: Implement the Code Snippets

app/services.py

Copy the provided code from services.py into this file. Make sure to adjust any imports if necessary.

# app/services.py

# flake8: noqa: E501

import random
import re
from typing import Callable, cast

from bs4 import BeautifulSoup, ResultSet, Tag
from requests.cookies import RequestsCookieJar
from app.scraper import CLIENT, PARSER, AiringStatus, AnimeMetadata, Download

# ... (rest of the provided services.py code)

app/scraper.py

Copy the provided code from scraper.py into this file. Make sure to adjust any imports if necessary.

# app/scraper.py

# flake8: noqa: E501

from base64 import b64decode
from enum import Enum
from string import ascii_letters, digits, printable
from threading import Event
from typing import Callable, Iterator, TypeVar, cast
import requests
import os

# ... (rest of the provided scraper.py code)

app/main.py

This file will contain the FastAPI application and the endpoints for your scraping functionality.

# app/main.py

from fastapi import FastAPI, HTTPException
from app.services import search  # Import the search function from services.py

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Welcome to the Anime Scraper API"}

@app.get("/search/")
def search_anime(keyword: str, ignore_dub: bool = True):
    try:
        results = search(keyword, ignore_dub)
        return {"results": results}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

Step 6: Run the Application

You can run the FastAPI application using uvicorn:

uvicorn app.main:app --reload

Step 7: Test the API

Once the server is running, you can test the API by navigating to http://127.0.0.1:8000/docs in your web browser. This will show you the automatically generated API documentation where you can test the /search/ endpoint.

Step 8: Additional Considerations

  1. Error Handling: You may want to implement more robust error handling in your scraping functions.
  2. Rate Limiting: Consider adding rate limiting to avoid overwhelming the target website.
  3. Caching: Implement caching for search results to improve performance.
  4. Deployment: When you're ready to deploy, consider using a service like Heroku, AWS, or DigitalOcean.

About

A webapp that scraps animes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages