diff --git a/index.html b/index.html new file mode 100644 index 00000000..8d833f18 --- /dev/null +++ b/index.html @@ -0,0 +1,95 @@ + + + + + + + NewsFinder by Amaan Warsi + + + + + + + + + +
+
+
+ + +
+
+ +
+ +
+
+
+
Offcanvas
+ +
+
+ +
+
+
+
+
+
+ Loading... +
+
+
+
+ + + +
+ + + + + + + + diff --git a/main.js b/main.js new file mode 100644 index 00000000..632c066a --- /dev/null +++ b/main.js @@ -0,0 +1,84 @@ +const getNews = async () => { + var returnData; + const name = (new Date()).toString().split('(')[1].split(" ")[0]; + + const countryResponse = await fetch("https://restcountries.com/v3.1/name/" + name + "?fullText=true"); + const data = await countryResponse.json(); + + // console.log(JSON.stringify(data)); + const country = data[0].cca2; + + const code = country.toLowerCase(); + + if (code == 'ae' || code == 'ar' || code == 'at' || code == 'au' || code == 'be' || code == 'bg' || code == 'br' || code == 'ca' || code == 'ch' || code == 'cn' || code == 'co' || code == 'cu' || code == 'cz' || code == 'de' || code == 'eg' || code == 'fr' || code == 'gb' || code == 'gr' || code == 'hk' || code == 'hu' || code == 'id' || code == 'ie' || code == 'il' || code == 'in' || code == 'it' || code == 'jp' || code == 'kr' || code == 'lt' || code == 'lv' || code == 'ma' || code == 'mx' || code == 'my' || code == 'ng' || code == 'nl' || code == 'no' || code == 'nz' || code == 'ph' || code == 'pl' || code == 'pt' || code == 'ro' || code == 'rs' || code == 'ru' || code == 'sa' || code == 'se' || code == 'sg' || code == 'si' || code == 'sk' || code == 'th' || code == 'tr' || code == 'tw' || code == 'ua' || code == 'us' || code == 've' || code == 'za') { + + returnData = code + + } + else { + returnData = null; + } + getData(returnData, getParam('c'), getParam('s')) + +} + +const getData = async (code, category, search) => { + const api= // YOUR_API_KEY + + try { + + var url; + if (search != null) { + url = 'https://newsapi.org/v2/everything?q=' + search + '&apiKey='+api; + } + else if (code != null) { + if (category != null) { + url = 'https://newsapi.org/v2/top-headlines?country=' + code + '&category=' + category + '&apiKey='+api; + } else { + url = 'https://newsapi.org/v2/top-headlines?country=' + code + '&apiKey='+api; + } + + } else if (code == null && category != null) { + url = 'https://newsapi.org/v2/top-headlines?category=' + category + '&apiKey='+api; + } else { + url = 'https://newsapi.org/v2/top-headlines?language=en&apiKey='+api; + } + + const response = await fetch(url); + const myJson = await response.json(); + document.querySelector('#spinner').style.display = 'none'; + var i = 0; + myJson.articles.map((res) => { + + var d = new Date(res.publishedAt); + var date = d.getDate() + ' ' + d.toLocaleString('default', { month: 'short' }) + ', ' + d.getFullYear(); + var description = (res.description != null) ? res.description : ''; + var notfound = "notfound.jpg" + var content = (res.content != null) ? '

' + res.content + '

' : ''; + var author = (res.author != null) ? '

Author`s: ' + res.author + '

' : ''; + var html = '
' + res.title + '
' + res.source.name + '

' + res.title + '

' + date + '

' + description + '

Details

' + res.title + '

' + author + ' ' + content + 'Url: ' + res.url + '
'; + + document.querySelector('#data').innerHTML += html; + i++; + }) + + + } catch (e) { + console.log(e) + } + +} + +const getParam = (p) => { + const queryString = window.location.search; + + const urlParams = new URLSearchParams(queryString); + + return urlParams.get(p); +} + + +getNews() +document.querySelector("#toggleMode").onclick=()=>{ + document.querySelector("body").classList.toggle("dark"); +}; diff --git a/newsfinder/README.md b/newsfinder/README.md new file mode 100644 index 00000000..e8b77602 --- /dev/null +++ b/newsfinder/README.md @@ -0,0 +1,45 @@ + +# NewsFinder +Get or search top news headlines delivered from reputed leading news websites + +Find original https://github.com/amaanwarsi/newsfinder + + +## API Reference +```http +https://newsapi.org/ +``` + +## Functions and Variables +| Parameter | Type | Description | +| :-------- | :------- | :------------------------- | +| `api` | `string` | **Required**. _ENTER_YOUR_API | + +#### getParam(p) + +Returns the current parameters of URL. +| Parameter | Type | Description | +| :-------- | :------- | :------------------------- | +| `p` | `string` | 'c' for category and 's' for search query | + + +#### getData(code, category, search) + +Print data came through API +| Parameter | Type | Description | +| :-------- | :------- | :------------------------- | +| `code` | `string` | country code for regional based results | +| `category` | `string` | category for news extracted from URL | +| `search` | `string` | query for searching news | + +#### getNews() +Function which handles all of the operations + + +## Features + +- Light/dark mode toggle +- Responsive +- get overview of news +- wide range of categories +- regional based results diff --git a/newsfinder/index.html b/newsfinder/index.html new file mode 100644 index 00000000..730a1d54 --- /dev/null +++ b/newsfinder/index.html @@ -0,0 +1,95 @@ + + + + + + + NewsFinder by Amaan Warsi + + + + + + + + + +
+
+
+ + +
+
+ +
+ +
+
+
+
Offcanvas
+ +
+
+ +
+
+
+
+
+
+ Loading... +
+
+
+
+ + + +
+ + + + + + + + diff --git a/newsfinder/main.js b/newsfinder/main.js new file mode 100644 index 00000000..632c066a --- /dev/null +++ b/newsfinder/main.js @@ -0,0 +1,84 @@ +const getNews = async () => { + var returnData; + const name = (new Date()).toString().split('(')[1].split(" ")[0]; + + const countryResponse = await fetch("https://restcountries.com/v3.1/name/" + name + "?fullText=true"); + const data = await countryResponse.json(); + + // console.log(JSON.stringify(data)); + const country = data[0].cca2; + + const code = country.toLowerCase(); + + if (code == 'ae' || code == 'ar' || code == 'at' || code == 'au' || code == 'be' || code == 'bg' || code == 'br' || code == 'ca' || code == 'ch' || code == 'cn' || code == 'co' || code == 'cu' || code == 'cz' || code == 'de' || code == 'eg' || code == 'fr' || code == 'gb' || code == 'gr' || code == 'hk' || code == 'hu' || code == 'id' || code == 'ie' || code == 'il' || code == 'in' || code == 'it' || code == 'jp' || code == 'kr' || code == 'lt' || code == 'lv' || code == 'ma' || code == 'mx' || code == 'my' || code == 'ng' || code == 'nl' || code == 'no' || code == 'nz' || code == 'ph' || code == 'pl' || code == 'pt' || code == 'ro' || code == 'rs' || code == 'ru' || code == 'sa' || code == 'se' || code == 'sg' || code == 'si' || code == 'sk' || code == 'th' || code == 'tr' || code == 'tw' || code == 'ua' || code == 'us' || code == 've' || code == 'za') { + + returnData = code + + } + else { + returnData = null; + } + getData(returnData, getParam('c'), getParam('s')) + +} + +const getData = async (code, category, search) => { + const api= // YOUR_API_KEY + + try { + + var url; + if (search != null) { + url = 'https://newsapi.org/v2/everything?q=' + search + '&apiKey='+api; + } + else if (code != null) { + if (category != null) { + url = 'https://newsapi.org/v2/top-headlines?country=' + code + '&category=' + category + '&apiKey='+api; + } else { + url = 'https://newsapi.org/v2/top-headlines?country=' + code + '&apiKey='+api; + } + + } else if (code == null && category != null) { + url = 'https://newsapi.org/v2/top-headlines?category=' + category + '&apiKey='+api; + } else { + url = 'https://newsapi.org/v2/top-headlines?language=en&apiKey='+api; + } + + const response = await fetch(url); + const myJson = await response.json(); + document.querySelector('#spinner').style.display = 'none'; + var i = 0; + myJson.articles.map((res) => { + + var d = new Date(res.publishedAt); + var date = d.getDate() + ' ' + d.toLocaleString('default', { month: 'short' }) + ', ' + d.getFullYear(); + var description = (res.description != null) ? res.description : ''; + var notfound = "notfound.jpg" + var content = (res.content != null) ? '

' + res.content + '

' : ''; + var author = (res.author != null) ? '

Author`s: ' + res.author + '

' : ''; + var html = '
' + res.title + '
' + res.source.name + '

' + res.title + '

' + date + '

' + description + '

Details

' + res.title + '

' + author + ' ' + content + 'Url: ' + res.url + '
'; + + document.querySelector('#data').innerHTML += html; + i++; + }) + + + } catch (e) { + console.log(e) + } + +} + +const getParam = (p) => { + const queryString = window.location.search; + + const urlParams = new URLSearchParams(queryString); + + return urlParams.get(p); +} + + +getNews() +document.querySelector("#toggleMode").onclick=()=>{ + document.querySelector("body").classList.toggle("dark"); +}; diff --git a/newsfinder/notfound.jpg b/newsfinder/notfound.jpg new file mode 100644 index 00000000..0a0ebd15 Binary files /dev/null and b/newsfinder/notfound.jpg differ diff --git a/newsfinder/screenshots/IMG_20230326_000548.jpg b/newsfinder/screenshots/IMG_20230326_000548.jpg new file mode 100644 index 00000000..0fb6ac6d Binary files /dev/null and b/newsfinder/screenshots/IMG_20230326_000548.jpg differ diff --git a/newsfinder/screenshots/IMG_20230326_000602.jpg b/newsfinder/screenshots/IMG_20230326_000602.jpg new file mode 100644 index 00000000..11529a27 Binary files /dev/null and b/newsfinder/screenshots/IMG_20230326_000602.jpg differ diff --git a/newsfinder/screenshots/IMG_20230326_000623.jpg b/newsfinder/screenshots/IMG_20230326_000623.jpg new file mode 100644 index 00000000..fdc9ad2a Binary files /dev/null and b/newsfinder/screenshots/IMG_20230326_000623.jpg differ diff --git a/newsfinder/screenshots/IMG_20230326_000631.jpg b/newsfinder/screenshots/IMG_20230326_000631.jpg new file mode 100644 index 00000000..4b1d6728 Binary files /dev/null and b/newsfinder/screenshots/IMG_20230326_000631.jpg differ diff --git a/newsfinder/screenshots/IMG_20230326_000644.jpg b/newsfinder/screenshots/IMG_20230326_000644.jpg new file mode 100644 index 00000000..3e7d8f56 Binary files /dev/null and b/newsfinder/screenshots/IMG_20230326_000644.jpg differ diff --git a/newsfinder/screenshots/Screenshot_2023-03-26-00-00-18-37_f9a7afa717ced9e1fc9be9833291031a.jpg b/newsfinder/screenshots/Screenshot_2023-03-26-00-00-18-37_f9a7afa717ced9e1fc9be9833291031a.jpg new file mode 100644 index 00000000..da696fe7 Binary files /dev/null and b/newsfinder/screenshots/Screenshot_2023-03-26-00-00-18-37_f9a7afa717ced9e1fc9be9833291031a.jpg differ diff --git a/newsfinder/style.css b/newsfinder/style.css new file mode 100644 index 00000000..804be04c --- /dev/null +++ b/newsfinder/style.css @@ -0,0 +1,91 @@ +/* stylelint-disable selector-list-comma-newline-after */ +.dark{ + background: #121212; + filter: invert(1) hue-rotate(180deg); +} +.dark iframe,.dark img,.dark html { + filter: invert(1) hue-rotate(180deg) brightness(105%) contrast(105%); + } +.blog-header { + border-bottom: 1px solid #e5e5e5; +} + +.blog-header-logo { + font-family: "Playfair Display", Georgia, "Times New Roman", serif + /*rtl:Amiri, Georgia, "Times New Roman", serif*/ + ; + font-size: 1.25rem; +} + +.blog-header-logo:hover { + text-decoration: none; +} + +h1, +h2, +h3, +h4, +h5, +h6 { + font-family: "Rubik" Geneva, Verdana, sans-serif + /*rtl:Amiri, Georgia, "Times New Roman", serif*/ + ; +} + +/* + * Blog posts + */ +.blog-post { + margin-bottom: 4rem; +} + +.blog-post-title { + font-size: 2.5rem; +} + +.blog-post-meta { + margin-bottom: 1.25rem; + color: #727272; +} + +/* + * Footer + */ +.blog-footer { + padding: 2.5rem 0; + color: #727272; + text-align: center; + background-color: #f9f9f9; + border-top: .05rem solid #e5e5e5; +} + +.blog-footer p:last-child { + margin-bottom: 0; +} + +.active { + background: #E5E5E5 !important; +} + +.nav-pills .nav-link:hover { + background: #E5E5E5 !important; + +} + +.nav-scroller { + position: relative; + z-index: 2; + height: 2.75rem; + overflow-y: hidden; +} + +.nav-scroller .nav { + display: flex; + flex-wrap: nowrap; + padding-bottom: 1rem; + margin-top: -1px; + overflow-x: auto; + text-align: center; + white-space: nowrap; + -webkit-overflow-scrolling: touch; +}