<commit_before><commit_msg>Create speciesFromLampyr.py<commit_after># Lampyr filter
""" Basic code to take the html output from Lampyr and produce the a list of
    just the species names. """

import urllib

def getLampyrDatafromAPI(lat, lon, commonOnly, nSpecies):
    """ get the data straight from Lampyr """
    if commonOnly:
        comstr = "no"
    else:
        comstr = "yes"
    page = urllib.URLopener().open("http://www.lampyr.org/app/getNClosestTaxonIDSpeciesCommon.php?lat={}&lon={}&submit=submit-value&common={}&N={}".format(lat,lon,comstr,nSpecies))
    dataStream = page.readlines()    
    return dataStream

def findSpeciesNames(dataList):
    """ filter the html output from Lampyr for species names """
    speciesList = []
    for line in dataList:
        if line.find("<a href=\"taxonInfo.php?") != -1:
            spName = line[line.find("<i>")+3:]
            spName = spName[:spName.find("<")]
            speciesList.append(spName)
    return speciesList    

def main():
    """ main loop """
    
    # sample parameters; the lat/lon represent Tucson
    lat = 32.222150
    lon = -110.926445
    commonOnly = False
    nSpecies = 50

    data = getLampyrDatafromAPI(lat,lon,commonOnly,nSpecies)
    species = findSpeciesNames(data)

    # test
    for s in species:
        print s

main()

""" to use more effectively,
    getLampyrDatafromAPI(lat,lon,commonOnly,nSpecies)
        this calls the Lampyr API with the specified inputs and returns
        a list containing the Lampyr output webpage as html
        lat and lon are the location to be serached, commonOnly is a boolean
        specifying whether to only include common names (for our purposes
        should probably always be False), and nSpecies is the number of
        species desired as output

    findSpeciesNames(data)
        this takes the list generated by the previous function and simply
        filters it for the species names, creating its own list just
        containing the names

    how we want to output the list from findSpeciesNames will depend on the
    precise usage

'""

{'fraction_non_alphanumeric': 0.08826335877862596, 'fraction_numerical': 0.010019083969465648, 'mean_word_length': 2.9791271347248576, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6572000', 'n_tokens_mistral': 625, 'n_tokens_neox': 606, 'n_words': 210}