Added Eclipse Version Scraping script

This commit is contained in:
Marcel Kapfer (mmk2410) 2017-02-11 01:47:24 +01:00
parent 0e4c7da82f
commit 23c5e83c23
5 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# This file allows you to configure the Dart analyzer.
#
# The commented part below is just for inspiration. Read the guide here:
# https://www.dartlang.org/guides/language/analysis-options
analyzer:
strong-mode: true

7
eclipse-version-scraping/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
# Files and directories created by pub
.packages
.pub/
packages
pubspec.lock
*.iml
.idea/

View file

@ -0,0 +1,16 @@
# Eclipse Version Scraping
Since Eclipse does not provide a convenient (or I did not find one) way to get informed when a new version is released it is quite difficult to keep my unofficial packages up-to-date.
So I wrote this script to scrape the eclipse.org page and set it up as a cron job to get notified, one a new version of Eclipse releases.
## Usage
`dart bin/main.dart [options] recipient`
Where options are one of the following:
- `-h` or `--help`: prints a help and exits
- `-f` or `--file`: specify a file, `./version.txt` is used by default
The recipient is the person that gets mailed, if a new version is released.

View file

@ -0,0 +1,103 @@
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:html/parser.dart' as parser;
import 'package:html/dom.dart';
/// Entry point of the script.
main(List<String> args) async {
String path = "./version.txt";
String recipient = "";
String eclipseUrl = "https://eclipse.org/downloads/eclipse-packages/";
String oldVersion = "";
/// Parse the given arguments.
if (args.length == 3) {
if (args[0] == "--file" || args[0] == "-f") {
path = args[1];
recipient = args[2];
} else {
help();
}
} else if (args.length == 1){
if (args[0] == "--help" || args[0] == "-h") {
help();
} else {
recipient = args[0];
}
} else if (args.length == 0) {
help();
}
if (!recipient.contains("@")) {
print("No correct mail address given.");
exit(-1);
}
http.Response response = await http.get(eclipseUrl);
if (response.body.trim().isEmpty) {
print("Website not available");
exit(1);
}
Document document = parser.parse(response.body);
String version = document.getElementById("descriptionText").text;
if (version.trim().isEmpty) {
print("No version information available.");
exit(1);
}
if (!version.contains("(") || !version.contains(")")) {
print("Version format seems to have changed.");
print("Version string: $version");
exit(2);
}
version = version.split("(")[1].split(")")[0].trim();
File file = new File(path);
if (await file.exists()) {
oldVersion = await file.readAsString();
oldVersion = oldVersion.trim();
} else {
oldVersion = "";
}
if (oldVersion == version) {
print("No version change");
exit(0);
}
file.writeAsString(version);
print("A new version is available!");
/// Send mail using the mail command.
await Process.run(
"mail",
["-s", "\"New Eclipse Version: $version\"", recipient],
runInShell: true
);
}
/// Print the help text and exit the program.
help() {
print("""
Eclipse Version Scraping
2017 (c) Marcel Kapfer
Licensed under GNU GPL v3
dart bin/main.dart [options] recipient
-h | --help Print this help and exit
-f | --file File to use for saving the version.""");
exit(0);
}

View file

@ -0,0 +1,6 @@
name: eclipse_version_scraping
version: 0.0.1
description: Scrape the number of the latest version from the eclipse.org page.
dependencies:
html: ^0.13.1
http: ^0.11.3