Python Examples

Example: Get all diseases for 'tomato'

 

Get data directly from our API using Python and it's "requests" package

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import json
import requests

def main():
    #First we need the name of the plant, from which we want to know all known diseases
    plant_name = 'TOMATO'
    #Replace this with your country code. For example de, in, ...
    language = 'en'
    #Replace <YOUR_API_KEY> with your api key
    headers = {'api_key': '<YOUR_API_KEY>'}
    url = 'http://api.peat-cloud.com/diseases/%s/%s' %(plant_name, language)
    req = requests.get(url, headers=headers) 
    #Evaluate response
    if req.status_code == 401:
        print req.text
    elif req.status_code == 200:
        data = req.text 
        print data 

if __name__ == '__main__':
    main()

This would print the full list of tomato pathogens and pests. The following JSON shows 'one of n' results. There are more than 170 pathogens and pests in our database, but numbers differ greatly between host species. (e.g. Plantix API contains a lot of Tomato diseases, but just a small number of pathogens that affects Raspberry due to it's little global importance - though they are very tasty).

All relevant data comes in the response[data] array

{"code": 200,
"data": [
{
"PEAT_id": 120002,
"affectedPart": [
                "LEAF",   
                "FRUIT",  
                "SHOOT"  
                ], 
"alternative_treatment":"Remove and destroy infected fruits and leaves immediately. Do not compost. 
                         You can install a simple, transparent rain shelter for the tomato plants with 
                         the help of a tarpaulin and wooden stakes. It should be open at the sides to 
                         allow ventilation of the plants. ",  

"bullet_points": "Grey or brown wrinkled stains on fruits. Hardened fruit flesh. Brown spots grow from the leaf margins.
                  White covering on the underside of leaves. ",  

"chemical_treatment": "Use fungicides based on Mandipropamid, Chlorothalonil, Fluazinam, Triphenyltin, Mancozeb to combat Late Blight. ",
"class": "Fungi", 
"class_eng": "Fungi", 
"disease_name": "Tomato Late Blight", 
"disease_name_eng": "Tomato Late Blight", 

"preventive_measures": "Try to keep plants dry. Install a simple rain shelter. Avoid waterlogging. Ventilate your greenhouse. 
                        Plant more resilient varieties. Tomatoes and potatoes should not be cultivated next to each other. 
                        Disinfect all tools after pruning. Use plant fortifier for general strengthening of the plants",  

"relevance": 1.0,
"scientific_name": "Phytophthora infestans", 
"spread_risk": "intermediate",

"symptoms": "Brownish-green spots appear on the leaf margins and leaf tops. Later the leaves turn completely brown. 
             On the underside of the leaves grows a white covering separating the healthy and dead leaf tissue. 
             In some cases, the sharply delimited brown spots also appear on the stalks, along with the white covering. 
             Greyish-green to dirty-brown and wrinkled stains appear on the fruits. At these spots, the fruit flesh is hardened. ",  

"tags": [
        "ccPatch",  
        "covering",  
        "wilt" ],  

Example: Request all known symptoms for a specific disease

And if you want to get all symptoms for a specific disease, you can query the api with this script and it will send you all information about all symptoms of this disease.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import json
import requests

def main():
    #The name of the disease, where we want to get the symptoms from
    #peat_id of the disease magnesium deficiency
    disease_id = '700004'
    #Replace this with your country code. For example de, in, ...
    language = 'en'

    #Replace <YOUR_API_KEY> with your api key
    headers = {'api_key': '<YOUR_API_KEY>'}

    #Send request
    url = 'http://api.peat-cloud.com/disease_id/%s/%s' %(disease_id, language)
    req = requests.get(url,headers=headers)
    #Evaluate response
    if req.status_code == 401:
        print 'Authentication failed'
    elif req.status_code == 200:
        print req.text

if __name__ == '__main__':
    main()

   

warning: this page is under active development

 

PEAT