File size: 1,001 Bytes
5273d83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests


class MANDI_PRICE:
    def __init__(self):
        self.base_url = "https://enam.gov.in/web/Ajax_ctrl/trade_data_list"
        # "https://enam.gov.in/web/dashboard/trade-data",
        # "https://enam.gov.in/web/dashboard/trade_data_list",


    def get_mandi_price(self,
        state_name,
        apmc_name,
        commodity_name,
        from_date,
        to_date
    ):
        # Prepare the payload for POST request
        payload = f"language=en&stateName={state_name}&apmcName={apmc_name}&commodityName={commodity_name}&fromDate={from_date}&toDate={to_date}"

        headers = {
            "Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "Referer": "https://enam.gov.in/web/dashboard/trade-data",
            "Accept": "application/json, text/javascript, */*; q=0.01",
        }

        response = requests.post(
            self.base_url,
            json=payload,
            headers=headers,
        )

        return response.json()