Skip to content

Instantly share code, notes, and snippets.

@kickingvegas
Created May 23, 2024 20:01
Show Gist options
  • Save kickingvegas/096d6a8771d77e715809110a0007a33e to your computer and use it in GitHub Desktop.
Save kickingvegas/096d6a8771d77e715809110a0007a33e to your computer and use it in GitHub Desktop.
Script to read MELPA package status
#!/usr/bin/env python3
#
# Copyright 2024 Yummy Melon Software
import os
import sys
import argparse
from subprocess import Popen, PIPE, call
import shutil
from datetime import datetime
import xml.etree.ElementTree as ET
import urllib.request
VERSION = "1.0.0"
class CommandLineParser:
def __init__(self,
prog="melpa-package-status",
description="<description>",
epilog="<epilog>",
version=VERSION):
self.parser = argparse.ArgumentParser(
prog=prog,
description=description,
epilog=epilog
)
self.parser.add_argument('-o', '--output',
action='store',
default='-',
help='output file (- for stdout)')
self.parser.add_argument('-v', '--version',
action='version',
version=version,
help='print version information and exit')
self.parser.add_argument('target',
action='store',
help='target file')
def run(self):
return self.parser.parse_args()
class MelpaPackageStatus:
def __init__(self, args):
self.version = VERSION
self.stdout = sys.stdout
self.stdin = sys.stdin
self.stderr = sys.stderr
self.args = args
if args.output != '-':
outfile = open('{0}'.format(args.output), 'w')
self.stdout = outfile
def run(self):
url = 'https://melpa.org/packages/{}-badge.svg'.format(self.args.target)
contents = urllib.request.urlopen(url).read()
root = ET.fromstring(contents)
title = root.findall(".//")[0].text
timestamp = title.split()[1]
self.stdout.write('{}: {}\n'.format(self.args.target, timestamp))
# wrap up
if self.stdout != sys.stdout:
self.stdout.close()
if __name__ == '__main__':
app = MelpaPackageStatus(CommandLineParser().run())
app.run()
@kickingvegas
Copy link
Author

Quick and dirty script to read the current status (build date) of a package on MELPA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment