Created
October 13, 2012 21:36
-
-
Save ztiromoritz/3886215 to your computer and use it in GitHub Desktop.
Find JAR in Central via SHA1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # Using REST-API of http://search.maven.org to find artifacts by sha1sum | |
| import sys | |
| import json | |
| import urllib2 | |
| import hashlib | |
| def hashfile(filepath): | |
| sha1 = hashlib.sha1() | |
| f = open(filepath, 'rb') | |
| try: | |
| sha1.update(f.read()) | |
| finally: | |
| f.close() | |
| return sha1.hexdigest() | |
| def request( hash ): | |
| url = 'http://search.maven.org/solrsearch/select?q=1:"' + \ | |
| hash+'"&wt=json&rows=20' | |
| response = urllib2.urlopen(url).read() | |
| return json.loads(response); | |
| def getAllPaths( doc ): | |
| prefix='http://search.maven.org/remotecontent?filepath='; | |
| group=doc["g"] | |
| groupPath=group.replace(".","/") | |
| name=doc["a"] | |
| version=doc["v"] | |
| fullPrefix = prefix + groupPath + "/" + name + "/" + \ | |
| version + "/" + name + "-" + version | |
| result=[] | |
| for ec in doc["ec"]: | |
| result.append( fullPrefix + ec ) | |
| return result | |
| filename = sys.argv[1] | |
| sha1=hashfile( sys.argv[1] ) | |
| obj = request( sha1 ) | |
| num = obj["response"]["numFound"] | |
| print sha1 + ' ' + filename | |
| if num > 0: | |
| for path in getAllPaths( obj["response"]["docs"][0] ): | |
| print "\t" + path; | |
| else: | |
| print "NOT FOUND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment