-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,362 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:dio_smart_retry/dio_smart_retry.dart'; | ||
|
||
Dio dio() { | ||
return Dio()..options = BaseOptions(validateStatus: (status) => true); | ||
final dio_ = Dio(); | ||
dio_.options = BaseOptions(validateStatus: (status) => true); | ||
dio_.interceptors.add( | ||
RetryInterceptor( | ||
dio: dio_, | ||
logPrint: print, | ||
retries: 3, | ||
retryDelays: const [ | ||
Duration(seconds: 2), | ||
Duration(seconds: 3), | ||
Duration(seconds: 5), | ||
], | ||
), | ||
); | ||
return dio_; | ||
} |
145 changes: 145 additions & 0 deletions
145
lib/extractor/general/national/bangladesh/prothamalo.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import 'package:raven/brain/dio_manager.dart'; | ||
import 'package:raven/model/article.dart'; | ||
import 'package:raven/model/publisher.dart'; | ||
|
||
class ProthamAlo extends Publisher { | ||
@override | ||
String get name => "প্রথম আলো"; | ||
|
||
@override | ||
String get homePage => "https://www.prothomalo.com"; | ||
|
||
@override | ||
Future<Map<String, String>> get categories => extractCategories(); | ||
|
||
@override | ||
Category get mainCategory => Category.bangladesh; | ||
|
||
@override | ||
bool get hasSearchSupport => true; | ||
|
||
Future<Map<String, String>> extractCategories() async { | ||
return { | ||
"সর্বশেষ": "latest", | ||
"রাজনীতি": "politics", | ||
"বাংলাদেশ": "bangladesh", | ||
"অপরাধ": "crime-bangladesh", | ||
"বিশ্ব": "world-all", | ||
"বাণিজ্য": "business-all", | ||
"মতামত": "opinion-all", | ||
"খেলা": "sports-all", | ||
"বিনোদন": "entertainment-all", | ||
"জীবনযাপন": "lifestyle-all", | ||
}; | ||
} | ||
|
||
@override | ||
Future<Set<NewsArticle>> categoryArticles( | ||
{String category = "latest", int page = 1}) async { | ||
Set<NewsArticle> articles = {}; | ||
var limit = 10; | ||
var offset = limit * (page - 1); | ||
String apiUrl = | ||
"$homePage/api/v1/collections/$category?offset=$offset&limit=$limit"; | ||
await dio().get(apiUrl).then( | ||
(response) { | ||
if (response.statusCode == 200) { | ||
var articlesData = response.data; | ||
var data = articlesData["items"]; | ||
for (var element in data) { | ||
var title = element['item']['headline'][0]; | ||
var author = element['story']["author-name"]; | ||
var thumbnail = element['story']["hero-image-s3-key"] ?? | ||
element['story']["alternative"]["home"]["default"]["hero-image"] | ||
["hero-image-s3-key"] ?? | ||
""; | ||
var time = element['story']["published-at"]; | ||
var articleUrl = element['story']['slug']; | ||
var excerpt = element['story']['summary']; | ||
var tags = | ||
element['story']['sections'].map((e) => e['name']).toList(); | ||
articles.add( | ||
NewsArticle( | ||
publisher: name, | ||
title: title ?? "", | ||
content: "", | ||
excerpt: excerpt ?? "", | ||
author: author ?? "", | ||
url: articleUrl, | ||
thumbnail: thumbnail ?? "", | ||
category: category, | ||
publishedAt: time, | ||
tags: List<String>.from(tags), | ||
), | ||
); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
return articles; | ||
} | ||
|
||
@override | ||
Future<Set<NewsArticle>> searchedArticles( | ||
{required String searchQuery, int page = 1}) async { | ||
Set<NewsArticle> articles = {}; | ||
var limit = 10; | ||
var offset = limit * (page - 1); | ||
String apiUrl = | ||
"$homePage/route-data.json?path=/search&q=$searchQuery&offset=$offset&limit=$limit"; | ||
await dio().get(apiUrl).then( | ||
(response) { | ||
if (response.statusCode == 200) { | ||
var articlesData = response.data; | ||
var data = articlesData["data"]["stories"]; | ||
for (var element in data) { | ||
var title = element['headline'][0]; | ||
var author = element["author-name"]; | ||
var thumbnail = element["hero-image-s3-key"] ?? ""; | ||
var time = element["published-at"]; | ||
var articleUrl = element['slug']; | ||
var excerpt = element['summary']; | ||
var tags = element['sections'].map((e) => e['name']).toList(); | ||
articles.add(NewsArticle( | ||
publisher: name, | ||
title: title ?? "", | ||
content: "", | ||
excerpt: excerpt ?? "", | ||
author: author ?? "", | ||
url: articleUrl, | ||
thumbnail: thumbnail ?? "", | ||
category: searchQuery, | ||
publishedAt: time, | ||
tags: List<String>.from(tags),),); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
return articles; | ||
} | ||
|
||
@override | ||
Future<NewsArticle> article(NewsArticle newsArticle) async { | ||
await dio() | ||
.get('$homePage/route-data.json?path=${newsArticle.url}') | ||
.then((response) { | ||
if (response.statusCode == 200) { | ||
var data = (response.data); | ||
var content = ""; | ||
var cards = data["data"]["story"]["cards"]; | ||
for (var card in cards) { | ||
if (card["story-elements"][0]["type"] == "text") { | ||
content += card["story-elements"][0]["text"]; | ||
} else if (card["story-elements"][0]["type"] == "image") { | ||
var image = card["story-elements"][0]["image-s3-key"]; | ||
content += "<p><img src='$image'/></p>"; | ||
} | ||
} | ||
newsArticle.content = content; | ||
} | ||
}); | ||
return newsArticle; | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
lib/extractor/general/national/bangladesh/prothamalo_english.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import 'package:raven/brain/dio_manager.dart'; | ||
import 'package:raven/model/article.dart'; | ||
import 'package:raven/model/publisher.dart'; | ||
|
||
class ProthamAloEn extends Publisher { | ||
@override | ||
String get name => "Prothom Alo"; | ||
|
||
@override | ||
String get homePage => "https://en.prothomalo.com"; | ||
|
||
@override | ||
Future<Map<String, String>> get categories => extractCategories(); | ||
|
||
@override | ||
Category get mainCategory => Category.bangladesh; | ||
|
||
@override | ||
bool get hasSearchSupport => true; | ||
|
||
Future<Map<String, String>> extractCategories() async { | ||
return { | ||
"Bangladesh": "bangladesh", | ||
"International": "international", | ||
"Sports": "sports", | ||
"Opinion": "opinion", | ||
"Business": "business", | ||
"Youth": "youth", | ||
"Entertainment": "entertainment", | ||
"Lifestyle": "lifestyle", | ||
}; | ||
} | ||
|
||
@override | ||
Future<Set<NewsArticle>> categoryArticles( | ||
{String category = "latest", int page = 1}) async { | ||
Set<NewsArticle> articles = {}; | ||
var limit = 10; | ||
var offset = limit * (page - 1); | ||
String apiUrl = | ||
"$homePage/api/v1/collections/$category?offset=$offset&limit=$limit"; | ||
await dio().get(apiUrl).then( | ||
(response) { | ||
if (response.statusCode == 200) { | ||
var articlesData = response.data; | ||
var data = articlesData["items"]; | ||
for (var element in data) { | ||
var title = element['item']['headline'][0]; | ||
var author = element['story']["author-name"]; | ||
var thumbnail = element['story']["hero-image-s3-key"] ?? | ||
element['story']["alternative"]["home"]["default"]["hero-image"] | ||
["hero-image-s3-key"] ?? | ||
""; | ||
var time = element['story']["published-at"]; | ||
var articleUrl = element['story']['slug']; | ||
var excerpt = element['story']['summary']; | ||
var tags = | ||
element['story']['sections'].map((e) => e['name']).toList(); | ||
articles.add( | ||
NewsArticle( | ||
publisher: name, | ||
title: title ?? "", | ||
content: "", | ||
excerpt: excerpt ?? "", | ||
author: author ?? "", | ||
url: articleUrl, | ||
thumbnail: thumbnail ?? "", | ||
category: category, | ||
publishedAt: time, | ||
tags: List<String>.from(tags), | ||
), | ||
); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
return articles; | ||
} | ||
|
||
@override | ||
Future<Set<NewsArticle>> searchedArticles( | ||
{required String searchQuery, int page = 1}) async { | ||
Set<NewsArticle> articles = {}; | ||
var limit = 10; | ||
var offset = limit * (page - 1); | ||
String apiUrl = | ||
"$homePage/route-data.json?path=/search&q=$searchQuery&offset=$offset&limit=$limit"; | ||
await dio().get(apiUrl).then( | ||
(response) { | ||
if (response.statusCode == 200) { | ||
var articlesData = response.data; | ||
var data = articlesData["data"]["stories"]; | ||
for (var element in data) { | ||
var title = element['headline'][0]; | ||
var author = element["author-name"]; | ||
var thumbnail = element["hero-image-s3-key"] ?? ""; | ||
var time = element["published-at"]; | ||
var articleUrl = element['slug']; | ||
var excerpt = element['summary']; | ||
var tags = element['sections'].map((e) => e['name']).toList(); | ||
articles.add(NewsArticle( | ||
publisher: name, | ||
title: title ?? "", | ||
content: "", | ||
excerpt: excerpt ?? "", | ||
author: author ?? "", | ||
url: articleUrl, | ||
thumbnail: thumbnail ?? "", | ||
category: searchQuery, | ||
publishedAt: time, | ||
tags: List<String>.from(tags),),); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
return articles; | ||
} | ||
|
||
@override | ||
Future<NewsArticle> article(NewsArticle newsArticle) async { | ||
await dio() | ||
.get('$homePage/route-data.json?path=${newsArticle.url}') | ||
.then((response) { | ||
if (response.statusCode == 200) { | ||
var data = (response.data); | ||
var content = ""; | ||
var cards = data["data"]["story"]["cards"]; | ||
for (var card in cards) { | ||
if (card["story-elements"][0]["type"] == "text") { | ||
content += card["story-elements"][0]["text"]; | ||
} else if (card["story-elements"][0]["type"] == "image") { | ||
var image = card["story-elements"][0]["image-s3-key"]; | ||
content += "<p><img src='$image'/></p>"; | ||
} | ||
} | ||
newsArticle.content = content; | ||
} | ||
}); | ||
return newsArticle; | ||
} | ||
} |
Oops, something went wrong.