#!/usr/bin/env python
import urllib2, re, glob, shutil

dlpage = urllib2.urlopen("https://www.sqlite.org/download.html")
version, = re.findall(r'''['"][0-9]{4}/sqlite-autoconf-([0-9]+)\.tar\.gz['"]''', dlpage.read())
version = '.'.join(reversed([str(int(version[max(i-2,0):i])) for i in xrange(len(version), 0, -2)]))

newBuildFile = "sqlite-" + version + ".build"
buildFile, = glob.glob("sqlite-*.build")

if buildFile != newBuildFile:
    print "mv {old} {new}".format(old=buildFile, new=newBuildFile)
    shutil.move(buildFile, newBuildFile)
