MospiMicrodata 1.0__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,2 @@
1
+ # MospiMicrodata/__init__.py
2
+ __all__ = ["getDatasets"]
@@ -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,6 @@
1
+ MospiMicrodata/MospiMicrodata.py,sha256=cjyZmzIZs7Rf2-Wtwm-C7KkmBaT9MW4szX6HO0vLqDw,2456
2
+ MospiMicrodata/__init__.py,sha256=-8619xSyD3L8zcOtAAFjbcUoT_pcd1qT00FmzVEB1hQ,55
3
+ mospimicrodata-1.0.dist-info/METADATA,sha256=FPYbBTdln_uhJrfYgPMQxKv8O8rTAa1c7Z_GqMjADWo,434
4
+ mospimicrodata-1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ mospimicrodata-1.0.dist-info/top_level.txt,sha256=8sp7d273VvEAKokvuzPw2ve7hp7Lg2zB4h404LYf9Pk,15
6
+ mospimicrodata-1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ MospiMicrodata