From fe9f32bbddda697c0784c0015c49b391e010ef47 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Mon, 5 May 2014 03:06:52 +0100 Subject: add amo-changelog, a script for fetching version history from the amo website --- amo-changelog | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 amo-changelog (limited to 'amo-changelog') diff --git a/amo-changelog b/amo-changelog new file mode 100755 index 0000000..02b035b --- /dev/null +++ b/amo-changelog @@ -0,0 +1,57 @@ +#!/usr/bin/python + +# Copyright (c) 2014, Jakub Wilk +# Copyright (c) 2014, Ximin Luo +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +from __future__ import print_function + +import argparse +import urllib2 +import xml.etree.cElementTree as etree +import sys + +URL_TEMPLATE = "https://addons.mozilla.org/en-US/addon/{ext}/versions/format:rss" + +def main(): + ap = argparse.ArgumentParser( + description="fetch Version History of an addon from the Mozilla Extensions website.") + ap.add_argument("extension", + help="Extension short-name, as used on addons.mozilla.org.") + options = ap.parse_args() + + url = URL_TEMPLATE.format(ext=options.extension) + try: + fp = urllib2.urlopen(url) + except urllib2.HTTPError as e: + print("For extension '%s', error fetching '%s': %s" % (options.extension, url, e), file=sys.stderr) + return 1 + try: + for event, element in etree.iterparse(fp): + if element.tag != "item": + continue + title = element.find("title").text + print(title) + print("=" * len(title)) + descel = element.find("description") + if descel is not None and descel.text: + print(descel.text.rstrip("\n")) + else: + print("[no description]") + print("") + finally: + fp.close() + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3