MoSPIMicrodata 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
from typing import List, Dict, Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def listDatasets(pageNo=1) -> List[Dict[str, Any]]:
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
|
|
10
|
+
response = requests.get("https://microdata.gov.in/NADA/index.php/api/listdatasets?page="+str(pageNo),headers=None)
|
|
11
|
+
|
|
12
|
+
data = response.json()
|
|
13
|
+
|
|
14
|
+
return data
|
|
15
|
+
|
|
16
|
+
except Exception as e:
|
|
17
|
+
print('Error while downloading the data:',e)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def getDatasets(folderPath,apiKey):
|
|
24
|
+
|
|
25
|
+
page=1
|
|
26
|
+
|
|
27
|
+
errorFlag=False
|
|
28
|
+
|
|
29
|
+
while True:
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
data=listDatasets(page)
|
|
33
|
+
|
|
34
|
+
if data is None :
|
|
35
|
+
errorFlag=True
|
|
36
|
+
break
|
|
37
|
+
|
|
38
|
+
rows = data["result"]["rows"]
|
|
39
|
+
|
|
40
|
+
indexed_data = [
|
|
41
|
+
{**item, "index": i}
|
|
42
|
+
for i, item in enumerate(rows, start=1)
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
for item in indexed_data:
|
|
46
|
+
print (item["id"]+":"+item["title"])
|
|
47
|
+
|
|
48
|
+
total = int(data["result"]["total"])
|
|
49
|
+
limit = int(data["result"]["limit"])
|
|
50
|
+
|
|
51
|
+
pages = total // limit + (1 if total % limit else 0)
|
|
52
|
+
|
|
53
|
+
user_input = input(f"Total pages:{pages},Page:{page} of {pages},\n Enter Survey index number(put n to Navigate to Next Page): ")
|
|
54
|
+
|
|
55
|
+
if user_input.strip().lower()=='n' :
|
|
56
|
+
page=page+1
|
|
57
|
+
|
|
58
|
+
if int(page) > int(pages) :
|
|
59
|
+
print ("No more Pages left to browse the data.")
|
|
60
|
+
break
|
|
61
|
+
|
|
62
|
+
else :
|
|
63
|
+
continue
|
|
64
|
+
|
|
65
|
+
#End loop
|
|
66
|
+
|
|
67
|
+
if errorFlag==False :
|
|
68
|
+
|
|
69
|
+
idno=None
|
|
70
|
+
|
|
71
|
+
if user_input.isdigit():
|
|
72
|
+
|
|
73
|
+
for item in indexed_data:
|
|
74
|
+
if item["id"]==user_input :
|
|
75
|
+
idno= (item["idno"])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if idno is not None:
|
|
79
|
+
|
|
80
|
+
url="https://microdata.gov.in/NADA/index.php/api/datasets/"+idno+"/fileslist"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
headers = {
|
|
84
|
+
"Host": "microdata.gov.in",
|
|
85
|
+
"X-API-KEY":apiKey
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
response = requests.get(url,headers=headers)
|
|
89
|
+
|
|
90
|
+
data = response.json()
|
|
91
|
+
|
|
92
|
+
folder=folderPath
|
|
93
|
+
|
|
94
|
+
for item1 in data["files"]:
|
|
95
|
+
|
|
96
|
+
url="https://microdata.gov.in/NADA/index.php/api/fileslist/download/"+idno+"/"+item1["base64"]
|
|
97
|
+
|
|
98
|
+
response = requests.get(url,headers=headers)
|
|
99
|
+
|
|
100
|
+
filename = os.path.join(folder, item1["name"])
|
|
101
|
+
|
|
102
|
+
with open(filename, "wb") as f:
|
|
103
|
+
f.write(response.content)
|
|
104
|
+
print(filename+":Downloaded successfully!")
|
|
105
|
+
|
|
106
|
+
else :
|
|
107
|
+
|
|
108
|
+
print('No such index Exists to download the Data.Kindly check the same & try again!')
|
|
109
|
+
|
|
110
|
+
else:
|
|
111
|
+
|
|
112
|
+
print("Invalid Index no.")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
else :
|
|
117
|
+
|
|
118
|
+
print ('Error ocurred while downloading the data!')
|
|
119
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: MoSPIMicrodata
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: This package can be used to download the data from MoSPI Microdata Portal (https://microdata.gov.in). Kindly call the getDatasets method with First parameter as location to save the data and second Parameter as API key generated from MicroData Portal Profile Section.
|
|
5
|
+
Author: DIID,Ministry of Statistics and Programme Implementation
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: requests
|
|
8
|
+
Dynamic: author
|
|
9
|
+
Dynamic: description
|
|
10
|
+
Dynamic: description-content-type
|
|
11
|
+
Dynamic: requires-dist
|
|
12
|
+
Dynamic: summary
|
|
13
|
+
|
|
14
|
+
\# MoSPI Microdata access
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
This package can be used to access the Microdata available from MoSPI microdata Portal (https://microdata.gov.in)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
\# Features
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
use the getDatasets("Path to save the Microdata","your API key downloaded from MosPI Microdata Portal") to choose
|
|
27
|
+
|
|
28
|
+
the Dataset to download.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
For example , you will get the option like this on calling the method
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
277:Annual Survey of Industries 2019-20
|
|
37
|
+
|
|
38
|
+
275:Annual Survey of Industries 2020-21
|
|
39
|
+
|
|
40
|
+
256:Annual Survey of Industries 2023-24
|
|
41
|
+
|
|
42
|
+
255:Comprehensive Modular Survey on Education-NSS 80th Round-2025
|
|
43
|
+
|
|
44
|
+
254:Periodic Labour Force Survey (PLFS), Key Employment Unemployment Indicators for (January 2024 - December 2024)
|
|
45
|
+
|
|
46
|
+
239:Comprehensive Modular Survey on Telecom-NSS 80th Round-2025
|
|
47
|
+
|
|
48
|
+
238:Annual Survey of Unincorporated Sector Enterprises (ASUSE) of 2023-2024
|
|
49
|
+
|
|
50
|
+
237:Household Consumption Expenditure Survey: 2023-24
|
|
51
|
+
|
|
52
|
+
236:Time Use Survey (TUS), January 2024-December 2024
|
|
53
|
+
|
|
54
|
+
230:Urban Frame Survey (UFS) Summary Data
|
|
55
|
+
|
|
56
|
+
224:Household Consumption Expenditure Survey: 2022-23
|
|
57
|
+
|
|
58
|
+
223:Time Use Survey (TUS), January 2019-December 2019
|
|
59
|
+
|
|
60
|
+
222:Annual Survey of Unincorporated Sector Enterprises (ASUSE) of 2022-2023
|
|
61
|
+
|
|
62
|
+
221:Annual Survey of Unincorporated Sector Enterprises (ASUSE) of 2021-2022
|
|
63
|
+
|
|
64
|
+
220:Comprehensive Annual Modular Survey (CAMS),NSS 79th round: 2022-23
|
|
65
|
+
|
|
66
|
+
Total pages:13,Page:1 of 13,
|
|
67
|
+
|
|
68
|
+
Enter Survey index number(put n to Navigate to Next Page):
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
You can choose the Numeric Index no to download the associated datasets
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
\## Installation
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
pip install package-name
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
MospiMicrodata/MospiMicrodata.py,sha256=cjyZmzIZs7Rf2-Wtwm-C7KkmBaT9MW4szX6HO0vLqDw,2456
|
|
2
|
+
MospiMicrodata/__init__.py,sha256=-8619xSyD3L8zcOtAAFjbcUoT_pcd1qT00FmzVEB1hQ,55
|
|
3
|
+
mospimicrodata-1.0.1.dist-info/METADATA,sha256=0R-Y-ZMZFrKo8upetqyggi6h7P4RmiXnMX9k5I--nMs,2194
|
|
4
|
+
mospimicrodata-1.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
mospimicrodata-1.0.1.dist-info/top_level.txt,sha256=8sp7d273VvEAKokvuzPw2ve7hp7Lg2zB4h404LYf9Pk,15
|
|
6
|
+
mospimicrodata-1.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MospiMicrodata
|