diff --git a/eclipse-version-scraping/.analysis_options b/eclipse-version-scraping/.analysis_options new file mode 100644 index 0000000..1c3b484 --- /dev/null +++ b/eclipse-version-scraping/.analysis_options @@ -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 diff --git a/eclipse-version-scraping/.gitignore b/eclipse-version-scraping/.gitignore new file mode 100644 index 0000000..b97dbca --- /dev/null +++ b/eclipse-version-scraping/.gitignore @@ -0,0 +1,7 @@ +# Files and directories created by pub +.packages +.pub/ +packages +pubspec.lock +*.iml +.idea/ \ No newline at end of file diff --git a/eclipse-version-scraping/README.md b/eclipse-version-scraping/README.md new file mode 100644 index 0000000..4e50561 --- /dev/null +++ b/eclipse-version-scraping/README.md @@ -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. \ No newline at end of file diff --git a/eclipse-version-scraping/bin/main.dart b/eclipse-version-scraping/bin/main.dart new file mode 100644 index 0000000..4ab2b4b --- /dev/null +++ b/eclipse-version-scraping/bin/main.dart @@ -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 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); +} \ No newline at end of file diff --git a/eclipse-version-scraping/pubspec.yaml b/eclipse-version-scraping/pubspec.yaml new file mode 100644 index 0000000..caaa9d6 --- /dev/null +++ b/eclipse-version-scraping/pubspec.yaml @@ -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