Created
November 26, 2012 06:27
-
-
Save itguy51/4146838 to your computer and use it in GitHub Desktop.
Python Stuff.
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
import urllib2 | |
import io | |
import HTMLParser | |
defs = ["Genotype", "Phenotype", "epistasis", "Co-dominance", "incomplete dominance", "autosomal", "dominant", "recessive", "prokaryote", "pleiotropy", "genetic pre-determinism", "Punnet square", "Gregor Mendel", "sexual dimorphism", "heterozygous", "homozygous", "allele"] | |
unef = [] | |
for i in defs: | |
try: | |
url = "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=" + i + "&sl=en&tl=en&restrict=pr%2Cde&client=te" | |
json = urllib2.urlopen(url).read() | |
(true,false,null) = (True,False,None) | |
json = json[:-10].replace("dict_api.callbacks.id100(", "") | |
profiles = eval(json) | |
try: | |
h = HTMLParser.HTMLParser() | |
s = h.unescape(profiles['webDefinitions'][0]['entries'][0]['terms'][0]['text']) | |
print i + " - " + urllib2.unquote(urllib2.quote(s.encode("utf8"))).decode("utf8") | |
except KeyError: | |
unef.append(i) | |
except urllib2.HTTPError: | |
unef.append(i) | |
print "Unable to define:" | |
for d in unef: | |
print d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment