Skip to content

Commit

Permalink
Merge branch 'dishamodi0910:master' into komal
Browse files Browse the repository at this point in the history
  • Loading branch information
komal-agarwal5 authored Jul 24, 2024
2 parents 72635a4 + 445b5c2 commit 4545e52
Show file tree
Hide file tree
Showing 127 changed files with 57,537 additions and 25 deletions.
74 changes: 74 additions & 0 deletions Existing_API_Collection/Anilist API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Sure! Below is a sample README file that explains how to use the AniList API:

---

# AniList API

The AniList API provides access to a wide range of information about anime and manga. This document will guide you through the process of using the API to search for anime titles and retrieve their details.

## Getting Started

To use the AniList API, you'll need to obtain an API key by signing up for an AniList account and creating an application. Follow these steps to get started:

1. **Sign Up**: If you don't already have an account, sign up for an AniList account at [AniList](https://anilist.co).

2. **Create Application**: Once logged in, go to the [Developer Dashboard](https://anilist.co/settings/developer) and create a new application. This will generate an API key that you'll use to authenticate your requests.

3. **API Key**: Copy the generated API key. You'll need to include this key in your API requests as an authorization header.

## Making Requests

The AniList API uses GraphQL for querying data. Here's an example of how to make a simple request to search for anime titles:

```graphql
query ($title: String) {
Page {
media (search: $title, type: ANIME) {
id
title {
romaji
english
native
}
description
averageScore
coverImage {
large
medium
}
}
}
}
```

This query searches for anime titles matching the provided title string and retrieves their ID, titles in different languages, descriptions, average scores, and cover images.

## Authentication

To authenticate your requests, include your API key as an authorization header in your HTTP requests. For example:

```
Authorization: Bearer YOUR_API_KEY
```

Replace `YOUR_API_KEY` with the API key you obtained from the AniList Developer Dashboard.

## Rate Limiting

The AniList API has rate limits to prevent abuse. Be sure to check the [API documentation](https://anilist.gitbook.io/anilist-apiv2-docs/) for the most up-to-date information on rate limits and usage guidelines.

## Examples

Check out the provided examples in various programming languages for implementing AniList API requests:

- [JavaScript](examples/javascript)
- [Python](examples/python)
- [Ruby](examples/ruby)

## Support

For help or questions about using the AniList API, you can visit the [AniList API Support](https://anilist.co/forum/section/4) forum.

---

Feel free to customize this README file according to your project's needs!
19 changes: 19 additions & 0 deletions Existing_API_Collection/Anilist API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anime Search</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Anime Search</h1>
<input type="text" id="searchInput" placeholder="Search for anime...">
<button onclick="searchAnime()">Search</button>
<div id="animeResults"></div>
</div>

<script src="script.js"></script>
</body>
</html>
75 changes: 75 additions & 0 deletions Existing_API_Collection/Anilist API/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Function to search for anime by title
async function searchAnime() {
const title = document.getElementById("searchInput").value;
try {
// Constructing the GraphQL query with image fields
const query = `
query ($title: String) {
Page {
media (search: $title, type: ANIME) {
id
title {
romaji
english
native
}
description
averageScore
coverImage {
large
medium
}
}
}
}
`;

// Making a POST request to the AniList API's GraphQL endpoint
const response = await fetch('https://graphql.anilist.co', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
variables: { title }
}),
});

// Parsing the JSON response
const responseData = await response.json();

// Extracting data from the response
const animeList = responseData.data.Page.media;

// Displaying results
const animeResultsDiv = document.getElementById("animeResults");
animeResultsDiv.innerHTML = "";
animeList.forEach(anime => {
const animeCard = document.createElement("div");
animeCard.classList.add("anime-card");

const titleElement = document.createElement("h2");
titleElement.textContent = anime.title.romaji || anime.title.english || anime.title.native;
animeCard.appendChild(titleElement);

const descriptionElement = document.createElement("p");
descriptionElement.textContent = anime.description;
animeCard.appendChild(descriptionElement);

const scoreElement = document.createElement("p");
scoreElement.textContent = "Average Score: " + anime.averageScore;
animeCard.appendChild(scoreElement);

if (anime.coverImage && anime.coverImage.medium) {
const imageElement = document.createElement("img");
imageElement.src = anime.coverImage.medium;
animeCard.appendChild(imageElement);
}

animeResultsDiv.appendChild(animeCard);
});
} catch (error) {
console.error('Error:', error);
}
}
72 changes: 72 additions & 0 deletions Existing_API_Collection/Anilist API/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

.container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1 {
font-size: 24px;
margin-bottom: 20px;
}

#searchInput {
padding: 10px;
width: 70%;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}

button {
padding: 10px 20px;
border: none;
background-color: #007bff;
color: #fff;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}

button:hover {
background-color: #0056b3;
}

#animeResults {
margin-top: 20px;
}

.anime-card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
background-color: #f9f9f9;
}

.anime-card img {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
margin-top: 10px;
}

.anime-card h2 {
font-size: 20px;
margin-bottom: 10px;
}

.anime-card p {
font-size: 16px;
margin-bottom: 10px;
}
30 changes: 30 additions & 0 deletions Existing_API_Collection/Bhagavad_Gita_API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Bhagavad Gita Quotes

Welcome to the Bhagavad Gita Quotes web application! This app is designed to help you explore and discover quotes from the Bhagavad Gita, offering wisdom and inspiration. You can either select specific chapters and verses or get a random quote every time you click the "Get Random Quote" button.

## Features
- **Fetch Specific Quotes:** Select a chapter and verse to get a specific quote from the Bhagavad Gita.
- **Random Quote:** Discover a random quote every time you click the "Get Random Quote" button.
- **Error Handling:** Robust error handling to ensure meaningful error messages and smooth usage.
- **Simple and Easy-to-Use Interface:** Designed with utmost simplicity for an easy and intuitive user experience.
- **Dropdown Selection:** Easily select chapters and verses from dropdown lists to fetch specific quotes.

## Technologies Used
- HTML
- Vanilla CSS
- JavaScript
- API (for fetching data)

# API Integration
This application uses the [Bhagavad Gita API](https://bhagavadgitaapi.in/) to fetch quotes from the Bhagavad Gita.

## Installation
To set up the Brewery Finder API locally, follow these steps:

1. Clone the repository.
2. Switch to Existing_API_Collection folder `cd Existing_API_Collection`
3. Navigate to the `Bhagavad_Gita_API` directory.
4. Open the `index.html` file in your browser.

## Screenshot
![Screenshot](screenshot.png)
31 changes: 31 additions & 0 deletions Existing_API_Collection/Bhagavad_Gita_API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bhagavad Gita Quotes</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div class="container">
<h1>Bhagavad Gita Quotes</h1>
<div class="selector">
<label for="chapterSelect">Chapter:</label>
<select id="chapterSelect"></select>
<label for="verseSelect">Verse:</label>
<select id="verseSelect"></select>
</div>
<button id="getQuoteButton">Get Quote</button>
<button id="randomQuoteButton">Get Random Quote</button>
<div id="quoteContainer">
<p id="slok"></p>
<p id="translation"></p>
</div>
</div>
<script src="script.js"></script>
</body>

</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions Existing_API_Collection/Bhagavad_Gita_API/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
document.addEventListener("DOMContentLoaded", () => {
const getQuoteButton = document.getElementById("getQuoteButton");
const randomQuoteButton = document.getElementById("randomQuoteButton");
const slokElement = document.getElementById("slok");
const translationElement = document.getElementById("translation");
const chapterSelect = document.getElementById("chapterSelect");
const verseSelect = document.getElementById("verseSelect");


// Populating chapter and verse options
for (let i = 1; i <= 18; i++) {
let option = document.createElement("option");
option.value = i;
option.textContent = i;
chapterSelect.appendChild(option);
}


for (let i = 1; i <= 20; i++) {
let option = document.createElement("option");
option.value = i;
option.textContent = i;
verseSelect.appendChild(option);
}

getQuoteButton.addEventListener("click", async () => {
const chapter = chapterSelect.value;
const verse = verseSelect.value;

try {
const response = await fetch(`https://bhagavadgitaapi.in/slok/${chapter}/${verse}/`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
slokElement.textContent = `Slok: ${data.slok}`;
translationElement.textContent = `Translation: ${data.purohit.et}`;
}
catch (error) {
slokElement.textContent = "An error occurred while fetching the quote.";
translationElement.textContent = "";
console.error("Fetch error:", error);
}
});


// Random button
randomQuoteButton.addEventListener("click", async () => {
const chapter = Math.floor(Math.random() * 18) + 1;
const verse = Math.floor(Math.random() * 20) + 1;


try {
const response = await fetch(`https://bhagavadgitaapi.in/slok/${chapter}/${verse}/`);
if (!response.ok) {
throw new Error("Error!");
}
const data = await response.json();
slokElement.textContent = `Slok: ${data.slok}`;
translationElement.textContent = `Translation: ${data.purohit.et}`;
}
catch (error) {
slokElement.textContent = "error while fetching the quote.";
translationElement.textContent = "";
console.error("error:", error);
}
});
});
Loading

0 comments on commit 4545e52

Please sign in to comment.