Skip to content

Commit

Permalink
v0.1.0 (#2)
Browse files Browse the repository at this point in the history
* add publishers

* fix lint issues

* refactor extractors

* add settings page

* add theme provider

* add dep: share_plus

* add settings page

* refactor article page

* change layout

* centralize store operations

* add redirection setting

* set datatype for publishedAt, add toString method

* use store

* add sort to articles

* fix icons

* fix next articles not loading

* fix images loading against the setting

* fix ladder url

* bump version

* remove unnecessary string formatter

* fix issue when saving custom categories

* add icons

* refactor url
  • Loading branch information
ksh-b authored Dec 29, 2023
1 parent c44cad5 commit 2c698af
Show file tree
Hide file tree
Showing 20 changed files with 982 additions and 212 deletions.
31 changes: 12 additions & 19 deletions lib/extractor/general/national/india/thewire.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class TheWire extends Publisher {
@override
String get iconUrl => "$homePage/favicon-32x32.png";

@override
String get searchEndpoint => "/search";

Future<Map<String, String>> extractCategories() async {
Map<String, String> map = {};
var response = await http.get(Uri.parse(homePage));
Expand All @@ -44,7 +41,7 @@ class TheWire extends Publisher {
@override
Future<NewsArticle?> article(String url) async {
var response = await http
.get(Uri.parse('$homePage/wp-json/thewire/v2/posts/detail/$url'));
.get(Uri.parse('$homePage$url'));
if (response.statusCode == 200) {
var data = json.decode(response.body);
var postDetail = data["post-detail"][0];
Expand Down Expand Up @@ -74,10 +71,9 @@ class TheWire extends Publisher {
return super.articles(category: category, page: page);
}

Future<Set<NewsArticle?>> extract(
String apiUrl, Map<String, String> params, bool isSearch) async {
Future<Set<NewsArticle?>> extract(String apiUrl, bool isSearch) async {
Set<NewsArticle?> articles = {};
final response = await http.get(Uri.parse(apiUrl), headers: params);
final response = await http.get(Uri.parse(apiUrl));
if (response.statusCode == 200) {
List data;
if (isSearch) {
Expand All @@ -90,7 +86,7 @@ class TheWire extends Publisher {
var author = element['post_author_name'][0]["author_name"];
var thumbnail = element['hero_image'][0]; //element['thumbnail']['url'];
var time = element["post_date_gmt"];
var articleUrl = '${element['post_name']}';
var articleUrl = '/wp-json/thewire/v2/posts/detail/${element['post_name']}';
var excerpt = element['post_excerpt'];
articles.add(NewsArticle(
this,
Expand All @@ -113,26 +109,23 @@ class TheWire extends Publisher {
if (category == '/') {
category = 'home';
}
String apiUrl =
'$homePage/wp-json/thewire/v2/posts/$category/recent-stories';
Map<String, String> params = {
'per_page': '10',
'page': '$page',
};
return extract(apiUrl, params, false);
String apiUrl = '$homePage/wp-json/thewire/v2/posts/$category/recent-stories?page=$page&per_page=10';
return extract(apiUrl, false);
}

@override
Future<Set<NewsArticle?>> searchedArticles(
{required String searchQuery, int page = 1}) {
String apiUrl = '$homePage/wp-json/thewire/v2/posts$searchEndpoint';
String apiUrl = '$homePage/wp-json/thewire/v2/posts/search';
Map<String, String> params = {
'keyword': searchQuery,
'orderby': 'rel',
'per_page': '5',
'page': '1',
'per_page': '10',
'page': '$page',
'type': 'opinion',
};
return extract(apiUrl, params, true);
Uri uri = Uri.parse(apiUrl).replace(queryParameters: params);
String fullUrl = uri.toString();
return extract(fullUrl, true);
}
}
127 changes: 127 additions & 0 deletions lib/extractor/general/world/aljazeera.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import 'package:intl/intl.dart';
import 'package:whapp/model/article.dart';
import 'package:whapp/model/publisher.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:html/parser.dart' as html_parser;
import 'package:whapp/utils/time.dart';

class AlJazeera extends Publisher {
@override
String get name => "Al Jazeera";

@override
String get homePage => "https://www.aljazeera.com";

@override
Future<Map<String, String>> get categories => extractCategories();

@override
bool get hasSearchSupport => false;

Future<Map<String, String>> extractCategories() async {
return {
"Features": "features",
"Economy": "economy",
"Opinion": "opinion",
"Science & Technology": "tag/science-and-technology",
"Sport": "sports",
};
}

@override
Future<NewsArticle?> article(String url) async {
var response = await http.get(Uri.parse('$homePage$url'));
if (response.statusCode == 200) {
var document = html_parser.parse(utf8.decode(response.bodyBytes));

var article = document.getElementById("main-content-area");

var titleElement = article?.querySelector('h1');
var excerptElement = article?.querySelector('em');
var thumbnailElement = article?.querySelector('img');
var articleElement = article?.querySelector('.wysiwyg');
var authorElement = article?.querySelector('.author-link');
var timeElement = article?.querySelector('.date-simple span[aria-hidden]');
var title = titleElement?.text;
var content = articleElement?.text;
var author = authorElement?.text;
var excerpt = excerptElement?.text;
var thumbnail = "$homePage${thumbnailElement?.attributes["src"]}";
var time = timeElement?.text;

if (time!=null) {
time = DateFormat('d MMM yyyy').parse(time).toString();
}
return NewsArticle(
this,
title ?? "",
content ?? "",
excerpt ?? "",
author ?? "",
url,
thumbnail,
parseDateString(time?.trim() ?? ""),
);
}
return null;
}

@override
Future<Set<NewsArticle?>> articles({
String category = "features",
int page = 1,
}) async {
return super.articles(category: category, page: page);
}

@override
Future<Set<NewsArticle?>> categoryArticles({
String category = "/",
int page = 1,
}) async {
Set<NewsArticle?> articles = {};

if (category == "/") {
category = "features";
}

var url = Uri.parse('https://www.aljazeera.com/graphql?wp-site=aje&operationName=ArchipelagoAjeSectionPostsQuery&variables={"category":"features","categoryType":"categories","postTypes":["blog","episode","opinion","post","video","external-article","gallery","podcast","longform","liveblog"],"quantity":10,"offset":14}&extensions={}');
var headers = {'wp-site': 'aje'};

var response = await http.get(url, headers: headers);

if (response.statusCode == 200) {
final Map<String, dynamic> data = json.decode(response.body);
var articlesData = data["data"]["articles"];
for (var element in articlesData) {
var title = element['title'];
var author = element['author'].isNotEmpty?element['author'][0]['name']:"";
var thumbnail = element['featuredImage']['sourceUrl'];
var time = element['date'];
var articleUrl = element['link'];
var excerpt = element['excerpt'];
articles.add(NewsArticle(
this,
title ?? "",
"",
excerpt,
author ?? "",
articleUrl,
thumbnail ?? "",
parseDateString(time?.trim() ?? ""),
));
}
}

return articles;
}

@override
Future<Set<NewsArticle?>> searchedArticles({
required String searchQuery,
int page = 1,
}) async {
return {};
}
}
Loading

0 comments on commit 2c698af

Please sign in to comment.