diff --git a/Dictionary.css b/Dictionary.css new file mode 100644 index 0000000..a83945a --- /dev/null +++ b/Dictionary.css @@ -0,0 +1,295 @@ +/* --- Google Font Import --- */ +@import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&family=Lato:wght@400;700&display=swap'); + +/* --- Main Body and Container Styling --- */ +body { + font-family: 'Lato', sans-serif; + background-color: #979797; + margin: 0; + padding: 20px; +} +.container { + background-color: #ffffff; + max-width: 800px; + margin: 0 auto; + padding: 20px 40px; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0,0,0,0.05); +} + +/* --- Search Box Styling --- */ +.search-box { display: flex; gap: 10px; margin-bottom: 30px; } +#word-input { flex-grow: 1; padding: 12px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; } +#search-btn { padding: 12px 20px; border: none; background-color: #007bff; color: white; border-radius: 5px; cursor: pointer; font-size: 16px; transition: background-color 0.2s; } +#search-btn:hover { background-color: #0056b3; } + +/* --- Result Header (Word and Pronunciation) --- */ +.result-header { border-bottom: 1px solid #e0e0e0; padding-bottom: 15px; margin-bottom: 20px; } +.result-header h1 { font-family: 'Merriweather', serif; color: #d92727; font-size: 3rem; margin: 0; } +.phonetics-container { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; margin-top: 10px; } +.phonetic-item { display: flex; align-items: center; gap: 8px; } +.phonetic { font-size: 1.2rem; color: #555; } +.audio-btn { background: none; border: none; cursor: pointer; font-size: 1.5rem; } + +/* --- Part of Speech & Definitions --- */ +.part-of-speech-section { margin-bottom: 30px; } +.part-of-speech-section h2 { font-family: 'Merriweather', serif; font-size: 1.5rem; color: #333; border-bottom: 2px solid #e0e0e0; padding-bottom: 5px; margin-bottom: 15px; } +.definitions-list { list-style-type: decimal; padding-left: 20px; } +.definitions-list li { margin-bottom: 15px; } +.definitions-list p { margin: 0; line-height: 1.6; } +.example { color: #666; font-style: italic; margin-top: 5px; padding-left: 15px; border-left: 3px solid #d0e0ff; } + +/* --- NEW: Synonyms/Antonyms Tags --- */ +.related-words { margin-top: 20px; } +.related-words h3 { font-size: 1.1rem; color: #555; margin-bottom: 10px; } +.tags-container { display: flex; flex-wrap: wrap; gap: 10px; } +.tag { + background-color: #eef4ff; + color: #0056b3; + border: 1px solid #d0e0ff; + border-radius: 4px; + padding: 5px 10px; + font-size: 0.9rem; + cursor: pointer; + transition: background-color 0.2s, color 0.2s; +} +.tag:hover { background-color: #0056b3; color: white; } + +/* --- NEW: Source Section --- */ +.source-section { + border-top: 1px solid #e0e0e0; + padding-top: 15px; + margin-top: 20px; + font-size: 0.9rem; + color: #666; +} +.source-section a { color: #007bff; text-decoration: none; } +.source-section a:hover { text-decoration: underline; } + +/* --- Utility --- */ +.error { color: #d92727; text-align: center; font-size: 1.2rem; } + +/* --- NEW: View Controls Styling --- */ +.view-controls { + display: flex; + justify-content: flex-start; /* CHANGE THIS from flex-end */ + gap: 10px; + margin-bottom: 15px; +} + +.view-btn { + background-color: #f0f0f0; + border: 1px solid #ccc; + padding: 5px 15px; + border-radius: 5px; + cursor: pointer; + font-size: 0.9rem; + color: #555; + font-size: 1.2rem; /* Make icons a bit bigger */ + padding: 2px 10px; /* Adjust padding for a squarer look */ +} + +.view-btn.active { + background-color: #007bff; + color: white; + border-color: #007bff; +} + + +/* --- NEW: Grid Layout Rules --- */ +#result-body-container.grid-view { /* <-- THIS LINE WAS CORRECTED */ + display: flex; + flex-wrap: wrap; /* Allows items to wrap to the next line if needed */ + gap: 20px; /* Space between the columns */ +} + +#result-body-container.grid-view .part-of-speech-section { /* <-- THIS LINE WAS CORRECTED */ + flex: 1; /* Each section will try to take up equal space */ + min-width: 250px; /* Prevents columns from becoming too narrow */ + margin-bottom: 0; /* Remove the bottom margin in grid view */ +} + +.synonym-section .tag { + background-color: #e6f9e6; /* Light green background */ + color: #0d6b0d; /* Dark green text */ + border-color: #b3e0b3; /* Green border */ +} + +.synonym-section .tag:hover { + background-color: #0d6b0d; /* Dark green background on hover */ + color: white; /* White text on hover */ +} + + +/* Style for Antonym tags (light red) */ +.antonym-section .tag { + background-color: #ffe6e6; /* Light red background */ + color: #b30000; /* Dark red text */ + border-color: #ffb3b3; /* Red border */ +} + +.antonym-section .tag:hover { + background-color: #b30000; /* Dark red background on hover */ + color: white; /* White text on hover */ +} + + +/* body +{ + font-family: Arial, sans-serif; + background-color: #f0f2f5; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; +} + +.container { + background-color: #ffffff; + padding: 30px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + width: 90%; + max-width: 500px; +} + +h1 { + text-align: center; + color: #333; +} + +.search-box { + display: flex; + gap: 10px; + margin-bottom: 20px; +} + +#word-input { + flex-grow: 1; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; + font-size: 16px; +} + +#search-btn { + padding: 10px 20px; + border: none; + background-color: #007bff; + color: white; + border-radius: 5px; + cursor: pointer; + font-size: 16px; +} + +#search-btn:hover { + background-color: #0056b3; +} + +#result-container { + margin-top: 20px; +} + +.word-info h2 { + margin-bottom: 5px; +} + +.word-info p { + color: #555; + margin: 5px 0; +} + +.error { + color: red; + text-align: center; +} + +.audio-btn { + background: none; + border: none; + cursor: pointer; + font-size: 1.2rem; + margin-left: 10px; + padding: 0; + vertical-align: middle; +}body { + font-family: Arial, sans-serif; + background-color: #f0f2f5; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; +} + +.container { + background-color: #ffffff; + padding: 30px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + width: 90%; + max-width: 500px; +} + +h1 { + text-align: center; + color: #333; +} + +.search-box { + display: flex; + gap: 10px; + margin-bottom: 20px; +} + +#word-input { + flex-grow: 1; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; + font-size: 16px; +} + +#search-btn { + padding: 10px 20px; + border: none; + background-color: #007bff; + color: white; + border-radius: 5px; + cursor: pointer; + font-size: 16px; +} + +#search-btn:hover { + background-color: #0056b3; +} + +#result-container { + margin-top: 20px; +} + +.word-info h2 { + margin-bottom: 5px; +} + +.word-info p { + color: #555; + margin: 5px 0; +} + +.error { + color: red; + text-align: center; +} + +.audio-btn { + background: none; + border: none; + cursor: pointer; + font-size: 1.2rem; + margin-left: 10px; + padding: 0; + vertical-align: middle; +} + */ \ No newline at end of file diff --git a/Dictionary.html b/Dictionary.html new file mode 100644 index 0000000..f77be57 --- /dev/null +++ b/Dictionary.html @@ -0,0 +1,30 @@ + + + + + + Dictionary + + + + +
+

Dictionary

+ + +
+ + +
+ +
+
+ +
+
+ + + \ No newline at end of file diff --git a/Dictionary.js b/Dictionary.js new file mode 100644 index 0000000..1324faa --- /dev/null +++ b/Dictionary.js @@ -0,0 +1,220 @@ +// input lete he +const wordInput = document.getElementById('word-input'); +const searchBtn = document.getElementById('search-btn'); +const resultHeaderContainer = document.getElementById('result-header-container'); +const resultBodyContainer = document.getElementById('result-body-container'); +const stackedViewBtn = document.getElementById('stacked-view-btn'); +const gridViewBtn = document.getElementById('grid-view-btn'); + +const wotdContainer = document.getElementById('wotd-container'); + +//Event Listeners yani input dekhne vale +searchBtn.addEventListener('click', () => searchWord(wordInput.value)); +wordInput.addEventListener('keyup', (event) => { + if (event.key === 'Enter') { + searchWord(wordInput.value); + } +}); +stackedViewBtn.addEventListener('click', setStackedView); +gridViewBtn.addEventListener('click', setGridView); + +// Main Search Function cpu +async function searchWord(word) { + word = word.trim(); + if (word === '') { + resultHeaderContainer.innerHTML = ''; + resultBodyContainer.innerHTML = '

Please enter a word.

'; + return; + } + + setStackedView(); // ye padhna baki + try { + const apiUrl = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`; + const response = await fetch(apiUrl); + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.title || 'Word not found.'); + } + const data = await response.json(); + displayResult(data); + } catch (error) { + resultHeaderContainer.innerHTML = ''; + resultBodyContainer.innerHTML = `

${error.message}

`; + } +} + +// --- Display Function --- +function displayResult(data) { + const entry = data[0]; + const word = entry.word; + const sourceUrl = entry.sourceUrls?.[0]; + + let headerHtml = `

${word}

`; + entry.phonetics.forEach(phonetic => { + if (phonetic.text && phonetic.audio) { + headerHtml += `
${phonetic.text}
`; + } else if (phonetic.text) { + headerHtml += `
${phonetic.text}
`; + } + }); + headerHtml += `
`; + resultHeaderContainer.innerHTML = headerHtml; + + let bodyHtml = ''; + entry.meanings.forEach(meaning => { + bodyHtml += `

${meaning.partOfSpeech}

    `; + meaning.definitions.forEach(def => { + bodyHtml += `
  1. ${def.definition}

    ${def.example ? `

    "${def.example}"

    ` : ''}
  2. `; + }); + bodyHtml += `
`; + if (meaning.synonyms && meaning.synonyms.length > 0) { + // ADD 'synonym-section' class here + bodyHtml += ``; + } + if (meaning.antonyms && meaning.antonyms.length > 0) { + // ADD 'antonym-section' class here + bodyHtml += ``; + } + bodyHtml += `
`; + }); + + + resultBodyContainer.innerHTML = bodyHtml; +} + +// iss se grid ya stack change ho raha he +function setStackedView() { + resultBodyContainer.classList.remove('grid-view'); + stackedViewBtn.classList.add('active'); + gridViewBtn.classList.remove('active'); +} +function setGridView() { + resultBodyContainer.classList.add('grid-view'); + gridViewBtn.classList.add('active'); + stackedViewBtn.classList.remove('active'); +} + + + + +/*searchBtn.addEventListener('click', searchWord); +wordInput.addEventListener('keyup', (event) => { + if (event.key === 'Enter') { + searchWord(); + } +}); + +stackedViewBtn.addEventListener('click', setStackedView); +gridViewBtn.addEventListener('click', setGridView); + +async function searchWord() { + console.log("Searching..."); +} +async function searchWord() { + const word = wordInput.value.trim(); + if (word === '') { + resultContainer.innerHTML = '

Please enter a word.

'; + return; + } + setStackedView(); + try { + const apiUrl = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`; + const response = await fetch(apiUrl); + if (!response.ok) { + const errorData = await response.json(); + throw new Error('Word not found. Sorry we will add it soon'); + } + const data = await response.json(); + displayResult(data); + } catch (error) { + resultContainer.innerHTML = `

${error.message}

`; + } +} +function displayResult(data) { + const entry = data[0]; + console.log(entry) + const word = entry.word; + + const sourceUrl = entry.sourceUrls?.[0]; + let headerHtml = ` +
+

${word}

+
+ `; + + entry.phonetics.forEach(phonetic => { + if (phonetic.text && phonetic.audio) { + headerHtml += ` +
+ ${phonetic.text} + + +
+ `; + } else if (phonetic.text) { + headerHtml += `
${phonetic.text}
`; + } + }); + headerHtml += `
`; + + let meaningsHtml = ''; + entry.meanings.forEach(meaning => { + meaningsHtml += `
`; + meaningsHtml += `

${meaning.partOfSpeech}

`; + meaningsHtml += `
    `; + meaning.definitions.forEach(def => { + meaningsHtml += `
  1. `; + meaningsHtml += `

    ${def.definition}

    `; + if (def.example) { + meaningsHtml += `

    "${def.example}"

    `; + } + meaningsHtml += `
  2. `; + }); + meaningsHtml += `
`; + + // Synonyms Section (now with clickable buttons) + if (meaning.synonyms && meaning.synonyms.length > 0) { + meaningsHtml += ``; + } + + // Antonyms Section + if (meaning.antonyms && meaning.antonyms.length > 0) { + meaningsHtml += ``; + } + meaningsHtml += `
`; + }); + + // --- Add Source URL at the bottom --- + let footerHtml = ''; + if(sourceUrl) { + footerHtml = ` +
+

Source: ${sourceUrl}

+
+ `; + } + + // Combine all parts and display + resultContainer.innerHTML = headerHtml + meaningsHtml + footerHtml; +} +// --- View Control Functions --- +function setStackedView() { + resultContainer.classList.remove('grid-view'); + stackedViewBtn.classList.add('active'); + gridViewBtn.classList.remove('active'); +} + +function setGridView() { + resultContainer.classList.add('grid-view'); + gridViewBtn.classList.add('active'); + stackedViewBtn.classList.remove('active'); +} + */ \ No newline at end of file diff --git a/Index.html b/Index.html new file mode 100644 index 0000000..d422d64 --- /dev/null +++ b/Index.html @@ -0,0 +1,194 @@ + + + + + + Weather App + + + +
+

🌤️ Location Weather Dashboard

+
+ +
+
+ + + +
+ + +
+

Current Weather

+ {% if weather %} + {% if weather.error %} +

{{ weather.error }}

+ {% else %} +
+ icon +
+

City: {{ weather.city }}

+

Condition: {{ weather.condition }}

+

🌡️ Temp: {{ weather.temperature }}{{ unit_symbol }}

+

🤔 Feels Like: {{ weather.feels_like }}{{ unit_symbol }}

+

⬆️ Max: {{ weather.temp_max }}{{ unit_symbol }} | ⬇️ Min: {{ weather.temp_min }}{{ unit_symbol }}

+

💨 Wind: {{ weather.wind }} m/s

+

💧 Humidity: {{ weather.humidity }}%

+

🔵 Pressure: {{ weather.pressure }} hPa

+

🌅 Sunrise: {{ weather.sunrise }} | 🌇 Sunset: {{ weather.sunset }}

+ {% endif %} + {% else %} +

Enter a city or leave blank to auto-detect location.

+ {% endif %} +
+ + +
+

5-Day Forecast

+ {% if forecast %} + {% if forecast.error %} +

{{ forecast.error }}

+ {% else %} +
+ {% for day in forecast %} +
+

{{ day.date }}

+
+ icon +
+

{{ day.condition }}

+

🌡️ {{ day.temp }}{{ unit_symbol }}

+

💨 {{ day.wind }} m/s

+
+ {% endfor %} +
+ {% endif %} + {% else %} +

Forecast will appear here.

+ {% endif %} +
+
+ + + + diff --git a/Readme.md b/Readme.md index e69de29..fb39e70 100644 --- a/Readme.md +++ b/Readme.md @@ -0,0 +1 @@ +I will add a authentication for Youtube using google sign in \ No newline at end of file diff --git a/ai/brain.js b/ai/brain.js new file mode 100644 index 0000000..60860ed --- /dev/null +++ b/ai/brain.js @@ -0,0 +1,142 @@ +// --- Element References --- +const wordInput = document.getElementById('word-input'); +const searchBtn = document.getElementById('search-btn'); +const resultHeaderContainer = document.getElementById('result-header-container'); +const resultBodyContainer = document.getElementById('result-body-container'); +const stackedViewBtn = document.getElementById('stacked-view-btn'); +const gridViewBtn = document.getElementById('grid-view-btn'); +const wotdContainer = document.getElementById('wotd-container'); +const historyList = document.getElementById('history-list'); + +// --- Event Listeners --- +searchBtn.addEventListener('click', () => searchWord(wordInput.value)); +wordInput.addEventListener('keyup', (event) => { + if (event.key === 'Enter') searchWord(wordInput.value); +}); +stackedViewBtn.addEventListener('click', setStackedView); +gridViewBtn.addEventListener('click', setGridView); + +// --- Functions to run on page load --- +window.addEventListener('load', () => { + fetchWordOfTheDay(); + displayHistory(); +}); + +// --- History Management --- +function updateAndDisplayHistory(word) { + let history = JSON.parse(localStorage.getItem('searchHistory')) || []; + // Remove existing entry to move it to the top + history = history.filter(item => item.toLowerCase() !== word.toLowerCase()); + // Add new word to the front + history.unshift(word); + // Keep history to a reasonable size (e.g., 15 words) + if (history.length > 15) history.pop(); + // Save to localStorage + localStorage.setItem('searchHistory', JSON.stringify(history)); + displayHistory(); +} + +function displayHistory() { + const history = JSON.parse(localStorage.getItem('searchHistory')) || []; + historyList.innerHTML = history.map(word => + `` + ).join(''); +} + +// --- Word of the Day --- +async function fetchWordOfTheDay() { + wotdContainer.innerHTML = `

Loading Word of the Day...

`; + try { + const response = await fetch('https://random-word-api.herokuapp.com/word'); + const [word] = await response.json(); + // Use main search function to display its definition in the WOTD container + await searchWord(word, true); + } catch (error) { + wotdContainer.innerHTML = `

Could not fetch Word of the Day.

`; + } +} + +// --- Main Search Function --- +async function searchWord(word, isWotd = false) { + word = word.trim(); + if (word === '') { + resultBodyContainer.innerHTML = '

Please enter a word.

'; + return; + } + + const headerTarget = isWotd ? wotdContainer : resultHeaderContainer; + const bodyTarget = isWotd ? wotdContainer : resultBodyContainer; + + if (!isWotd) setStackedView(); // Reset view only for manual searches + headerTarget.innerHTML = ''; + bodyTarget.innerHTML = `

Searching for "${word}"...

`; + + try { + const response = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`); + if (!response.ok) throw new Error('Word not found.'); + + const data = await response.json(); + displayResult(data, isWotd); + + // Add to history only on successful manual searches + if (!isWotd) { + updateAndDisplayHistory(word); + } + } catch (error) { + if (!isWotd) { + resultHeaderContainer.innerHTML = ''; + resultBodyContainer.innerHTML = `

${error.message}

`; + } else { + // If WOTD fails, try another word + fetchWordOfTheDay(); + } + } +} + +// --- Display Function (Refactored for WOTD) --- +function displayResult(data, isWotd) { + const entry = data[0]; + const word = entry.word; + + let html = `
+ ${isWotd ? '

Word of the Day

' : ''} +

${word}

+
`; + entry.phonetics.forEach(p => { + if (p.text && p.audio) html += `
${p.text}
`; + else if (p.text) html += `
${p.text}
`; + }); + html += `
`; + + entry.meanings.forEach(meaning => { + html += `

${meaning.partOfSpeech}

    `; + meaning.definitions.forEach(def => { + html += `
  1. ${def.definition}

    ${def.example ? `

    "${def.example}"

    ` : ''}
  2. `; + }); + html += `
`; + if (meaning.synonyms?.length > 0) html += ``; + if (meaning.antonyms?.length > 0) html += ``; + }); + + if (isWotd) { + wotdContainer.innerHTML = html; + } else { + // Split HTML for regular search + const headerMatch = html.match(/
.*?<\/div>/); + const bodyContent = html.replace(headerMatch[0], ''); + resultHeaderContainer.innerHTML = headerMatch[0]; + resultBodyContainer.innerHTML = bodyContent; + } +} + +// --- View Control Functions --- +function setStackedView() { + resultBodyContainer.classList.remove('grid-view'); + stackedViewBtn.classList.add('active'); + gridViewBtn.classList.remove('active'); +} +function setGridView() { + resultBodyContainer.classList.add('grid-view'); + gridViewBtn.classList.add('active'); + stackedViewBtn.classList.remove('active'); +} \ No newline at end of file diff --git a/ai/index.html b/ai/index.html new file mode 100644 index 0000000..51df1fe --- /dev/null +++ b/ai/index.html @@ -0,0 +1,38 @@ + + + + + + Lexica + + + +
+
+
+
+
+ +
+ + +
+
+
+

Type a word above to get started!

+
+
+
+
+
+

Search History

+
+
+
+
+ + + \ No newline at end of file diff --git a/ai/look.css b/ai/look.css new file mode 100644 index 0000000..9e9f2b6 --- /dev/null +++ b/ai/look.css @@ -0,0 +1,68 @@ +/* --- NEW: Main Layout --- */ +.main-container { + display: flex; + gap: 30px; + width: 100%; + max-width: 1200px; + margin: 0 auto; +} +.content-column { + flex-grow: 1; + min-width: 0; /* Prevents flexbox overflow */ +} +.history-column { + flex-basis: 250px; /* Fixed width for the sidebar */ + flex-shrink: 0; +} + +/* --- NEW: Word of the Day --- */ +#wotd-container { + background-color: #fff8e1; + border: 1px solid #ffecb3; + border-radius: 8px; + padding: 20px; + margin-bottom: 20px; +} +#wotd-container h2 { + font-family: 'Merriweather', serif; + margin-top: 0; + text-align: center; + color: #f57f17; +} + +/* --- NEW: History List --- */ +#history-container { + background-color: #ffffff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0,0,0,0.05); +} +#history-list { + display: flex; + flex-direction: column; + gap: 8px; + max-height: 500px; + overflow-y: auto; +} +.history-item { + width: 100%; + padding: 8px; + border: 1px solid #e0e0e0; + background-color: #f9f9f9; + border-radius: 4px; + text-align: left; + cursor: pointer; + font-size: 0.95rem; +} +.history-item:hover { + background-color: #eef4ff; + border-color: #007bff; +} + +/* --- NEW: Empty State --- */ +.empty-state { + text-align: center; + color: #888; + font-size: 1.1rem; + padding: 50px 0; +} \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..a6eeee8 --- /dev/null +++ b/app.py @@ -0,0 +1,82 @@ +from flask import Flask, render_template, request +import requests +from datetime import datetime + +app = Flask(__name__) + +API_KEY = "YOUR_API_KEY" # replace with your key +CURRENT_URL = "http://api.openweathermap.org/data/2.5/weather" +FORECAST_URL = "http://api.openweathermap.org/data/2.5/forecast" +IPINFO_URL = "http://ipinfo.io/json" + + +@app.route("/", methods=["GET", "POST"]) +def home(): + weather_data = None + forecast_data = None + city = None + units = request.form.get("units", "metric") # default to Celsius + unit_symbol = "°C" if units == "metric" else "°F" + + if request.method == "POST": + # City from input OR detect via IP + city = request.form.get("city") + if not city: + try: + ip_data = requests.get(IPINFO_URL).json() + city = ip_data.get("city", "London") # fallback + except: + city = "London" + + # --- Current weather --- + current_url = f"{CURRENT_URL}?q={city}&appid={API_KEY}&units={units}" + current_response = requests.get(current_url) + + if current_response.status_code == 200: + current_json = current_response.json() + weather_data = { + "city": current_json["name"], + "condition": current_json["weather"][0]["description"].title(), + "temperature": current_json["main"]["temp"], + "feels_like": current_json["main"]["feels_like"], + "temp_min": current_json["main"]["temp_min"], + "temp_max": current_json["main"]["temp_max"], + "humidity": current_json["main"]["humidity"], + "pressure": current_json["main"]["pressure"], + "wind": current_json["wind"]["speed"], + "sunrise": datetime.fromtimestamp(current_json["sys"]["sunrise"]).strftime("%H:%M"), + "sunset": datetime.fromtimestamp(current_json["sys"]["sunset"]).strftime("%H:%M"), + "icon": current_json["weather"][0]["icon"] + } + + # --- 5-day forecast (every 3 hours → pick one per day) --- + forecast_url = f"{FORECAST_URL}?q={city}&appid={API_KEY}&units={units}" + forecast_response = requests.get(forecast_url) + + if forecast_response.status_code == 200: + forecast_json = forecast_response.json() + forecast_data = [] + for i in range(0, len(forecast_json["list"]), 8): # one per day + day = forecast_json["list"][i] + forecast_data.append({ + "date": day["dt_txt"].split(" ")[0], + "condition": day["weather"][0]["description"].title(), + "temp": day["main"]["temp"], + "wind": day["wind"]["speed"], + "icon": day["weather"][0]["icon"] + }) + else: + forecast_data = {"error": "Unable to fetch forecast."} + else: + weather_data = {"error": "City not found!"} + + return render_template("index.html", + weather=weather_data, + forecast=forecast_data, + city=city, + units=units, + unit_symbol=unit_symbol) + + +if __name__ == "__main__": + app.run(debug=True) diff --git a/try1.js b/try1.js new file mode 100644 index 0000000..fdc8585 --- /dev/null +++ b/try1.js @@ -0,0 +1,78 @@ +const wordInput = document.getElementById('word-input'); +const searchBtn = document.getElementById('search-btn'); +const resultContainer = document.getElementById('result-container'); + +searchBtn.addEventListener('click', searchWord); +wordInput.addEventListener('keyup', (event) => { + if (event.key === 'Enter') { + searchWord(); + } +}); + +async function searchWord() { + const word = wordInput.value.trim(); + if (word === '') { + resultContainer.innerHTML = '

Please enter a word.

'; + return; + } + + try { + const apiUrl = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`; + const response = await fetch(apiUrl); + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.title || 'Word not found.'); + } + const data = await response.json(); + displayResult(data); + } catch (error) { + resultContainer.innerHTML = `

${error.message}

`; + } +} + +function displayResult(data) { + const entry = data[0]; + const word = entry.word; + const phonetics = entry.phonetics?.find(p => p.text)?.text || ''; + const audioSource = entry.phonetics?.find(p => p.audio)?.audio; + + let html = ` +
+

${word}

+
+ ${phonetics} + ${audioSource ? `` : ''} +
+ ${audioSource ? `` : ''} +
+ `; + + // ** THE MAJOR CHANGE IS HERE: LOOP THROUGH ALL MEANINGS ** + entry.meanings.forEach(meaning => { + html += `
`; + html += `

${meaning.partOfSpeech}

`; + + // Loop through all definitions for this part of speech + html += `
    `; + meaning.definitions.forEach(def => { + html += `
  1. `; + html += `

    ${def.definition}

    `; + if (def.example) { + html += `

    "${def.example}"

    `; + } + html += `
  2. `; + }); + html += `
`; + + // Display synonyms if they exist + if (meaning.synonyms && meaning.synonyms.length > 0) { + html += `
`; + html += `

Synonyms

`; + html += `

${meaning.synonyms.join(', ')}

`; + html += `
`; + } + html += `
`; + }); + + resultContainer.innerHTML = html; +} \ No newline at end of file