MospiMicrodata 1.0__tar.gz
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.
- mospimicrodata-1.0/MospiMicrodata/MospiMicrodata.py +119 -0
- mospimicrodata-1.0/MospiMicrodata/__init__.py +2 -0
- mospimicrodata-1.0/MospiMicrodata.egg-info/PKG-INFO +9 -0
- mospimicrodata-1.0/MospiMicrodata.egg-info/SOURCES.txt +8 -0
- mospimicrodata-1.0/MospiMicrodata.egg-info/dependency_links.txt +1 -0
- mospimicrodata-1.0/MospiMicrodata.egg-info/requires.txt +1 -0
- mospimicrodata-1.0/MospiMicrodata.egg-info/top_level.txt +1 -0
- mospimicrodata-1.0/PKG-INFO +9 -0
- mospimicrodata-1.0/setup.cfg +4 -0
- mospimicrodata-1.0/setup.py +14 -0
|
@@ -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,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: MospiMicrodata
|
|
3
|
+
Version: 1.0
|
|
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
|
|
6
|
+
Requires-Dist: requests
|
|
7
|
+
Dynamic: author
|
|
8
|
+
Dynamic: requires-dist
|
|
9
|
+
Dynamic: summary
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
MospiMicrodata/MospiMicrodata.py
|
|
3
|
+
MospiMicrodata/__init__.py
|
|
4
|
+
MospiMicrodata.egg-info/PKG-INFO
|
|
5
|
+
MospiMicrodata.egg-info/SOURCES.txt
|
|
6
|
+
MospiMicrodata.egg-info/dependency_links.txt
|
|
7
|
+
MospiMicrodata.egg-info/requires.txt
|
|
8
|
+
MospiMicrodata.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MospiMicrodata
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: MospiMicrodata
|
|
3
|
+
Version: 1.0
|
|
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
|
|
6
|
+
Requires-Dist: requests
|
|
7
|
+
Dynamic: author
|
|
8
|
+
Dynamic: requires-dist
|
|
9
|
+
Dynamic: summary
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="MospiMicrodata",
|
|
5
|
+
version="1.0",
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
install_requires=[
|
|
8
|
+
"requests"
|
|
9
|
+
],
|
|
10
|
+
author="DIID",
|
|
11
|
+
description="This package can be used to download the data from MoSPI Microdata " \
|
|
12
|
+
"Portal (https://microdata.gov.in). Kindly call the getDatasets method with First parameter as location to save the data and second Parameter as " \
|
|
13
|
+
"API key generated from MicroData Portal Profile Section",
|
|
14
|
+
)
|