Exemplo n.º 1
0
            status = 1
        elif botanical_found:
            status = 1
        else:
            print(chalk.red.bold("plant "), common_name, botanical_name,
                  chalk.red.bold(" not found in data"))
            common_not_found = 1
            botanical_not_found = 1
            both_found = 0
            botanical_found = 0
            common_found = 0
            status = 0

        with open('mbg-data.csv', 'a') as writeFile:
            writer = csv.writer(writeFile)
            print(common_not_found)
            print(botanical_not_found)
            if (common_not_found == 0 or botanical_not_found == 0):
                writer.writerow([
                    '', common_name, botanical_name, status, common_found,
                    botanical_found, both_found, r.url,
                    'http://www.missouribotanicalgarden.org/' +
                    plant_seach_link, ''
                ])
            else:
                print(chalk.magenta("Plant was not found on MGB site"))
                writer.writerow([
                    '', common_name, botanical_name, status, common_found,
                    botanical_found, both_found, r.url, 'not found', ''
                ])
Exemplo n.º 2
0
 # Requst the plantFinder for plant based on common name
 botanical_name_req = {'basic': botanicalName}
 # print(chalk.green(commonNameOriginal))
 time.sleep(1)
 r = requests.get('http://www.missouribotanicalgarden.org/PlantFinder/PlantFinderProfileResults.aspx', params=botanical_name_req)
 # print(chalk.yellow.bold('common name search url'),r.url)
 soup = BeautifulSoup(r.text,'html.parser')
 span = soup.find(id="dnn_ctr4158_SearchResults_lblNoResults")
 if span:
   # print(chalk.red(span.text))
   if span.text == "We're sorry, but no results were found matching your criteria.  Please revise your search criteria.":
     print(chalk.red.bold('plant not found with botanical name'),botanicalName)
     botanical_not_found = 1
     with open('MBGBotanicalNames-output.csv','a') as writeFile:
       writer = csv.writer(writeFile)
       print(chalk.magenta("writing to csv that plant was not found"))
       writer.writerow(
         ['Not found',
         '0',  # Common Name Original 
         '0',  # Common Name - MGB
         botanicalName,
         '0',  # Botanical Name - MGB
         '0',  # type 
         '0',  # family
         '0',  # native range
         '0',  # zone
         '0',  # zone low
         '0',  # zone high
         '0',  # height
         '0',  # height low
         '0',  # heigh high
Exemplo n.º 3
0
    if (price < lowPrice):
        print(chalk.green.bold('Sending text to ' + buyingOrSelling))
        client.messages.create(
            to=myNumber,
            from_=twilioNumber,
            body="Price dropped below ${:.2f}! Time to {} some shares of {}!".
            format(lowPrice, buyingOrSelling, tickerSymbol))
        break
    # Wait for price increase
    elif (price > highPrice):
        print(chalk.green.bold('Sending text to ' + buyingOrSelling))
        client.messages.create(
            to=myNumber,
            from_=twilioNumber,
            body="Price increased above ${:.2f}! Time to {} your shares of {}!"
            .format(highPrice, buyingOrSelling, tickerSymbol))
        break
    else:
        # price = chalk.green("$" + price)
        print(
            chalk.magenta('Current price: ') +
            chalk.green.bold('$' + str(price)) +
            chalk.magenta(' Continuing to monitor ') +
            chalk.magenta.bold(tickerSymbol) + chalk.magenta(' prices...'))

    time.sleep(30)
    price = getPrice(price)

# Shut down driver
driver.quit()
def findHeightWordInSentences(lemmatizedSentences, plantName, category,
                              wikiLink):
    foundHeight = False
    with open('plantHeightData.csv', 'a', newline='') as csvfile:
        writer = csv.writer(csvfile)
        for sentence in lemmatizedSentences:
            for word in sentence:
                if (word == 'height' or word == 'tall'):
                    print(chalk.green.bold('height found for'), plantName)
                    foundHeight = True
                    sentenceThatContainHeightKeyword = " ".join(
                        str(x) for x in sentence)
                    # print(sentenceThatContainHeightKeyword,'\n')
                    # filterdSentence = tokenizer.tokenize(sentenceThatContainHeightKeyword)
                    # sentenceThatContainHeightKeyword = " ".join(str(x) for x in filterdSentence)
                    # print("plant Name is :" ,plantName, sentenceThatContainHeightKeyword);
                    doc = nlp(sentenceThatContainHeightKeyword)
                    count = 0
                    plant_height_data = []
                    for token in doc:
                        t = token.text
                        if t == 'm' or t == 'meter' or t == 'metre' or t == 'ft' or t == 'foot' or t == 'cm' or t == 'centimetre' or t == 'in':
                            # if len(doc) > (token.i+1):
                            # next_token = doc[token.i + 1]
                            prev_token = doc[token.i - 1]
                            if prev_token.like_num:
                                count += 1
                                # print("token",token," token.i",token.i," len(doc)",len(doc))
                                token_sentence = doc[prev_token.i:token.i + 1]
                                print("case#1",
                                      chalk.yellow.bold(token_sentence))
                                plant_height_data.append(token_sentence)
                                if doc[prev_token.i -
                                       2].like_num:  # 1 to 2 unit
                                    count += 1
                                    token_sentence = doc[prev_token.i -
                                                         2:token.i + 1]
                                    print("case#2",
                                          chalk.blue.bold(token_sentence))
                                    plant_height_data.append(token_sentence)
                                else:
                                    pass
                            else:  #get data for case#3 x-x unit
                                if prev_token.is_punct == False:
                                    token_sentence = doc[prev_token.i:token.i +
                                                         1]
                                    print("case#3",
                                          chalk.magenta(
                                              token_sentence))  #x-x uni
                                    plant_height_data.append(token_sentence)
                                else:
                                    pass  # do nothing if theres a punct mark

                                # if next_token.lower_ == "m" or next_token.lower_ == 'ft' or next_token.lower_ == 'meter' or next_token.lower_ == 'metre' or next_token.lower_ == 'cm' or next_token.lower_ == 'in' or next_token.lower_ == 'foot':
                                # count += 1
                                # token_sentence = doc[prev_token.i:next_token.i + 1]
                                # print('Height sentence',token_sentence)
                                # unit = token_sentence[len(token_sentence) - 1:len(token_sentence)]
                                # print(unit)
                                # writer.writerow([plantName,category,unit,'',token_sentence,'',wikiLink,sentenceThatContainHeightKeyword,''])

                    # unit cleanup
                    plant_height_data_str = []
                    plant_height_data_str_ft = ''
                    plant_height_data_str_cm = ''
                    plant_height_data_str_m = ''
                    plant_height_data_str_in = ''
                    for valueWithUnit in plant_height_data:
                        stringData = valueWithUnit.text
                        stringData = stringData.replace("-", " ")
                        stringData = stringData.replace("centimetre", "cm")
                        stringData = stringData.replace("foot", "ft")
                        stringData = stringData.replace("meter", "m")
                        stringData = stringData.replace("inch", "in")
                        stringData = stringData.replace('–', ' ')
                        stringData = stringData.replace('to', ' ')
                        stringData = stringData.replace(',', '')
                        stringData = stringData.replace('1/2', '0.5')

                        if stringData.find('in') > 0:
                            plant_height_data_str_in = plant_height_data_str_in + stringData
                            plant_height_data_str_in = plant_height_data_str_in.replace(
                                'in', '')
                        if stringData.find('ft') > 0:
                            plant_height_data_str_ft = plant_height_data_str_ft + stringData
                            plant_height_data_str_ft = plant_height_data_str_ft.replace(
                                'ft', '')
                        if stringData.find(' m') > 0:
                            plant_height_data_str_m = plant_height_data_str_m + stringData
                            plant_height_data_str_m = plant_height_data_str_m.replace(
                                'm', '')
                        if stringData.find(' cm') > 0:
                            plant_height_data_str_cm = plant_height_data_str_cm + stringData
                            plant_height_data_str_cm = plant_height_data_str_cm.replace(
                                'cm', '')

                        plant_height_data_str.append(stringData)

                    print(chalk.red(plantName), plant_height_data)
                    print(chalk.green(plantName), plant_height_data_str)

                    # inch
                    # remove all characters
                    plant_height_data_str_in = removeAlphabets(
                        plant_height_data_str_in)
                    print(chalk.yellow(plantName), 'inch values',
                          plant_height_data_str_in)
                    plant_height_data_str_in = plant_height_data_str_in.split()
                    try:
                        plant_height_data_str_in = list(
                            map(float, plant_height_data_str_in))
                        plant_height_data_str_in = sorted(
                            plant_height_data_str_in)
                        print(chalk.cyan.bold(plantName), 'inch values',
                              plant_height_data_str_in)
                    except ValueError:
                        pass

                    # ft
                    plant_height_data_str_ft = removeAlphabets(
                        plant_height_data_str_ft)
                    print(chalk.yellow(plantName), 'ft values',
                          plant_height_data_str_ft)
                    plant_height_data_str_ft = plant_height_data_str_ft.split()
                    try:
                        plant_height_data_str_ft = list(
                            map(float, plant_height_data_str_ft))
                        plant_height_data_str_ft = sorted(
                            plant_height_data_str_ft)
                        print(chalk.cyan.bold(plantName), 'ft values',
                              plant_height_data_str_ft)
                    except ValueError:
                        pass
                    # m
                    plant_height_data_str_m = removeAlphabets(
                        plant_height_data_str_m)
                    print(chalk.yellow(plantName), 'm values',
                          plant_height_data_str_m)
                    plant_height_data_str_m = plant_height_data_str_m.split()
                    try:
                        plant_height_data_str_m = list(
                            map(float, plant_height_data_str_m))
                        plant_height_data_str_m = sorted(
                            plant_height_data_str_m)
                        print(chalk.cyan.bold(plantName), 'm values',
                              plant_height_data_str_m)
                    except ValueError:
                        pass

                    # cm
                    plant_height_data_str_cm = removeAlphabets(
                        plant_height_data_str_cm)
                    print(chalk.yellow(plantName), 'cm values',
                          plant_height_data_str_cm)
                    plant_height_data_str_cm = plant_height_data_str_cm.split()
                    try:
                        plant_height_data_str_cm = list(
                            map(float, plant_height_data_str_cm))
                        plant_height_data_str_cm = sorted(
                            plant_height_data_str_cm)
                        print(chalk.cyan.bold(plantName), 'cm values',
                              plant_height_data_str_cm)
                    except ValueError:
                        pass

                    if (len(plant_height_data_str_in) > 0):
                        temp = ['x'] * 10
                        for index, value in enumerate(
                                plant_height_data_str_in):
                            temp[index] = value

                        writer.writerow([
                            plantName, category, 'in', temp[0], temp[1],
                            temp[2], temp[3], temp[4], temp[5], temp[6],
                            temp[7], temp[8], temp[9], wikiLink,
                            sentenceThatContainHeightKeyword
                        ])

                    if (len(plant_height_data_str_cm) > 0):
                        temp = ['x'] * 10
                        for index, value in enumerate(
                                plant_height_data_str_cm):
                            temp[index] = value

                        writer.writerow([
                            plantName, category, 'cm', temp[0], temp[1],
                            temp[2], temp[3], temp[4], temp[5], temp[6],
                            temp[7], temp[8], temp[9], wikiLink,
                            sentenceThatContainHeightKeyword
                        ])

                    if (len(plant_height_data_str_ft) > 0):
                        temp = ['x'] * 10
                        for index, value in enumerate(
                                plant_height_data_str_ft):
                            temp[index] = value

                        writer.writerow([
                            plantName, category, 'ft', temp[0], temp[1],
                            temp[2], temp[3], temp[4], temp[5], temp[6],
                            temp[7], temp[8], temp[9], wikiLink,
                            sentenceThatContainHeightKeyword
                        ])

                    if (len(plant_height_data_str_m) > 0):
                        temp = ['x'] * 10
                        for index, value in enumerate(plant_height_data_str_m):
                            temp[index] = value

                        writer.writerow([
                            plantName, category, 'm', temp[0], temp[1],
                            temp[2], temp[3], temp[4], temp[5], temp[6],
                            temp[7], temp[8], temp[9], wikiLink,
                            sentenceThatContainHeightKeyword
                        ])

                    # if (count > 0):
                    # print(count,chalk.red.bold('tokens found in'),plantName,'\n')
                    # else:
                    # writer.writerow([plantName,category,'not found','','not found','',wikiLink,sentenceThatContainHeightKeyword,''])
                    # print(count,chalk.red('tokens matched in'),plantName,'\n')

    if (foundHeight == False):
        print(chalk.red("No Height for "), plantName)
        with open('plantHeightData.csv', 'a', newline='') as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow([
                plantName, category, 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x',
                'x', 'x', 'x', wikiLink, 'x'
            ])