Plant Info Database
Trefle.io is an API that will provide plant data for a vast amount of botanic species.
Here is a simply code that uses requests, json and webbrowser libraries harmoniously.
Code below demonstrates a simple access to Trefle.io using a Python code. You will need to replace your own token with the “XXXXX” parameters. You can register here for free to get a unique API key.
import requests
import json
import webbrowser
f = r"http://trefle.io/api/plants?q=Chrysanthemum"
def plants(f):
paramss = {"token": "XXXXXXXXXXXXXXXXXXXXXXXX"}
data = requests.get(f, params = paramss)
tt = json.loads(data.text)
return tt
a = plants(f)
for i in a:
#webbrowser.open(i["link"]+"?token=XXXXXXXXXXXXXXXXXXXXXXX")
print(i["slug"])
plants(f)
If you need a refresher on user defined functions lesson in Python here is a link to our Defining Functions Lesson.
Source of API: Trefle.io