Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hall of fame images #105

Merged
merged 6 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
6 changes: 4 additions & 2 deletions lib/Screens/race_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class _RaceDetailsScreenState extends State<RaceDetailsScreen> {
],
labelColor: useDarkMode
? Colors.white
: Theme.of(context).scaffoldBackgroundColor,
: Theme.of(context)
.scaffoldBackgroundColor,
),
Expanded(
child: TabBarView(
Expand Down Expand Up @@ -203,7 +204,8 @@ class _RaceDetailsScreenState extends State<RaceDetailsScreen> {
],
labelColor: useDarkMode
? Colors.white
: Theme.of(context).scaffoldBackgroundColor,
: Theme.of(context)
.scaffoldBackgroundColor,
),
Expanded(
child: TabBarView(
Expand Down
3 changes: 1 addition & 2 deletions lib/api/article_parts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1177,8 +1177,7 @@ class WidgetsList extends StatelessWidget {
[
'tableContent'])
Row(
children: <
Widget>[
children: <Widget>[
for (Map driverDetails
in driverItem)
Container(
Expand Down
26 changes: 13 additions & 13 deletions lib/api/searx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ class SearXSearch {
List<Map> results = [];
List<dom.Element> tempResults = document.getElementsByTagName('article');
for (var element in tempResults) {
if (element.firstChild!.attributes['href']!
.contains('formula1.com/en/latest/article')) {
results.add(
{
'url': element.firstChild!.attributes['href'],
'title': element.children[1].firstChild!.text,
'content': element.children[2].innerHtml
.replaceAll('<span class="highlight">', '**')
.replaceAll('</span>', '**')
.substring(4),
},
);
}
if (element.firstChild!.attributes['href']!
.contains('formula1.com/en/latest/article')) {
results.add(
{
'url': element.firstChild!.attributes['href'],
'title': element.children[1].firstChild!.text,
'content': element.children[2].innerHtml
.replaceAll('<span class="highlight">', '**')
.replaceAll('</span>', '**')
.substring(4),
},
);
}
}
return results;
}
}
61 changes: 33 additions & 28 deletions lib/scraping/formula_one.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import 'dart:convert';
import 'dart:io';

import 'package:boxbox/api/driver_components.dart';
import 'package:boxbox/helpers/convert_ergast_and_formula_one.dart';
Expand Down Expand Up @@ -564,38 +565,42 @@ class FormulaOneScraper {

Future<List<HallOfFameDriver>> scrapeHallOfFame() async {
List<HallOfFameDriver> results = [];
late Uri driverDetailsUrl;

String endpoint = Hive.box('settings')
.get('server', defaultValue: defaultEndpoint) as String;
if (endpoint != defaultEndpoint) {
driverDetailsUrl = Uri.parse(
'$endpoint/en/drivers/hall-of-fame.html',
);
} else {
driverDetailsUrl = Uri.parse(
'https://www.formula1.com/en/drivers/hall-of-fame.html',
);
}
String f1Endpoint =
endpoint != defaultEndpoint ? endpoint : 'https://www.formula1.com';
Uri driverDetailsUrl =
Uri.parse('$f1Endpoint/en/drivers/hall-of-fame.html');

http.Response response = await http.get(driverDetailsUrl);
dom.Document document = parser.parse(response.body);
List<dom.Element>? tempResults =
document.getElementsByClassName('fom-teaser');
for (var element in tempResults) {
results.add(
HallOfFameDriver(
element.children[0].children[1].attributes['alt']!
.toString()
.split(' - ')[0],
element.children[0].children[1].attributes['alt']!
.toString()
.split(' - ')[1],
(endpoint != defaultEndpoint)
? '$endpoint/content/fom-website/en/drivers/hall-of-fame/${element.children[0].children[1].attributes['alt']!.toString().split(' - ')[0].replaceAll(' ', '_')}.html'
: 'https://www.formula1.com/content/fom-website/en/drivers/hall-of-fame/${element.children[0].children[1].attributes['alt']!.toString().split(' - ')[0].replaceAll(' ', '_')}.html',
'https://www.formula1.com/content/fom-website/en/drivers/hall-of-fame/${element.children[0].children[1].attributes['alt']!.toString().split(' - ')[0].replaceAll(' ', '_')}/_jcr_content/image16x9.img.640.medium.jpg',
),
);
if (response.statusCode == HttpStatus.ok) {
dom.Document document = parser.parse(response.body);
List<dom.Element> elements = document.querySelectorAll(
'a.column.column-4[href*="/en/drivers/hall-of-fame/"][href\$=".html"]');

for (dom.Element element in elements) {
List<String> driverInfo = element
.getElementsByClassName('teaser-info-title')
.first
.text
.trim()
.split(' - ');
String driverName = driverInfo[0];
String driverYears = driverInfo[1];

dom.Element imageElement = element
.getElementsByTagName('img')
.firstWhere((e) => e.classes.contains('hidden'));
String driverImage = imageElement.attributes['src'] ?? '';

String driverUrl = f1Endpoint + element.attributes['href']!;

results.add(
HallOfFameDriver(driverName, driverYears, driverUrl, driverImage));
}
}

return results;
}

Expand Down