diff --git a/versions/python b/versions/python index 0aab24ec0435a1497ee08b58f0be7be7f8ebe871..319c1839f54aede669e087c4765dbeb897c52719 100755 --- a/versions/python +++ b/versions/python @@ -1,3 +1,34 @@ #!/usr/bin/env python -print('2.7.13') -print('3.6.3') \ No newline at end of file + +from vendor import requests +from vendor import parse + +# The Source of Truth. +SOURCE_URI = 'https://www.python.org/downloads/' + +# The Parse template for finding the truth amongst the HTML. +PARSE_VERSION_TEMPLATE = '<a href="/downloads/release/python-{}/">Python {}</a>' + + +def yield_versions(): + """Discovers currently–released Python versions from Python.org.from + Yields them as an iterator.""" + + # Make the HTTP request. + r = requests.get('https://www.python.org/downloads/') + + # + for result in parse.findall(PARSE_VERSION_TEMPLATE, r.text): + # Print each version release number. + yield result[1] + + +def main(): + """Print each version number to stdout.""" + for version in yield_versions(): + print(version) + + +# If executed directly, run main automatically. +if __name__ == '__main__': + main()