Skip to content

Commit

Permalink
Version2
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya chhabra committed Apr 12, 2021
1 parent 493808e commit 33ab07a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Aditya Karan Chhabra
Copyright (c) 2021 ADITYA KARAN CHHABRA and ABHISHEK ARORA

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@
- (Instructions here : [Official Guide](https://data.gov.in/help/how-use-datasets-apis))

## Installation
> - Using PIP
```sh
pip install -U datagovindia
```
-------
> - Clone the Git-Repository
```sh
git clone https://github.com/addypy/datagovindia

sudo python setup.py install

```

## Basic Usage

Expand All @@ -36,7 +44,7 @@ from datagovindia import DataGovIndia

### Initialize Class
```python
datagovin = DataGovIndia("579b454db66ec23bdd0000028bacb6c0f91845af635ee6e722sd9dd44")
datagovin = DataGovIndia("579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b")
```

> Performs :
Expand Down Expand Up @@ -106,7 +114,7 @@ from datagovindia import DataGovIndia
> See : [Official Guide](https://data.gov.in/help/how-use-datasets-apis)
```python
api_key = "579b454db66ec23bdd0000028bacb6c0f91845af635ee6e722sd9dd44"
api_key = "579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b"
```

> ### Initialize Class
Expand Down Expand Up @@ -2481,4 +2489,11 @@ datagovin.get_data("dad7a738fd3b437dad31e1f844e9a575",num_results='all')
> - For the R/CRAN package, visit -
>
> > [github.com/econabhishek/datagovindia](https://github.com/econabhishek/datagovindia)
>
> > [github.com/cran/datagovindia](https://github.com/cran/datagovindia)
>
> Authors :
>
> > - [Aditya Karan Chhabra]((https://github.com/addypy)
>
> > - [Abhishek Arora](https://github.com/econabhishek)
32 changes: 21 additions & 11 deletions datagovindia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
==============================================================================
LICENSE
==============================================================================
MIT License
Copyright (c) 2021 Aditya Karan Chhabra
Copyright (c) 2021 ADITYA KARAN CHHABRA and ABHISHEK ARORA
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -52,7 +53,10 @@ def wipe_resource_id(rsrc_id):
"""Basic cleaning of resource-id string.
"""
rsrc_id = "".join([c for c in str(rsrc_id) if c.isalnum()]).strip()
assert len(rsrc_id)==32, "Resource-ID invalid"
if len(rsrc_id)!=32:
print("{} is not a valid Resource-ID".format(rsrc_id))
else:
pass
return rsrc_id

def scrub_resource_id(rsrc_id):
Expand All @@ -65,7 +69,10 @@ def scrub_resource_id(rsrc_id):
rsrc_id[12:16],
rsrc_id[16:20],
rsrc_id[20:32]])
assert len(rsrc_id)==36, "Resource-ID invalid"
if len(rsrc_id)!=36:
print("{} is not a valid Resource-ID".format(rsrc_id))
else:
pass
return rsrc_id

def calc_loop_steps(n,step_size,offset=0):
Expand Down Expand Up @@ -447,7 +454,9 @@ def validate_key(api_key,attempts=1):
api_validity = False
continue
else:
print("API-Key {} invalid.".format(api_key))
api_validity = False
server_status = True
pass
return {'APIKEY':api_validity,"SERVER":server_status}


Expand Down Expand Up @@ -475,7 +484,7 @@ class DataGovIndia:
For the R/CRAN package, visit -
https://github.com/econabhishek/datagovindia
or
https://github.com/cran/datagovindia
"""
def __init__(self, api_key, enable_multithreading=False):
Expand All @@ -485,7 +494,6 @@ def __init__(self, api_key, enable_multithreading=False):
Args:
=====
`api_key` : API-KEY (str)
Optional:
=========
Expand All @@ -499,10 +507,11 @@ def __init__(self, api_key, enable_multithreading=False):
of your internet connection.
Initialization performs two key tasks:
1) Validates the API-key provided
1) Tests server
- Tests data.gov.in server to check if APIs are functional.
2) Validates the API-key provided
- Once validated, the API-key is stored and does not need to be entered again.
2) Loads latest API meta-data.
3) Loads latest API meta-data.
- Downloads and loads data containing the latest details of available APIs.
"""
Expand Down Expand Up @@ -822,15 +831,16 @@ def get_resource_info(self,rsrc_id):
def get_resource_fields(self,rsrc_id):
"""Get details of fields (variables) available for a `data.gov.in` data resource.
"""
rsrc_id = wipe_resource_id(rsrc_id)

rsrc_id = wipe_resource_id(rsrc_id)
if rsrc_id in self.assets.resource_ids:
fieldcodes = self.idxfieldmap[rsrc_id]
fieldlabels = [self.assets.field_label_map[f] for f in fieldcodes]
fielddtypes = [self.assets.field_dtype_map[f] for f in fieldcodes]
fieldinfo = [{'field_code':fieldcodes[f],'field_label':fieldlabels[f],'field_type':fielddtypes[f]} for f in range(len(fieldcodes))]
return pd.DataFrame(fieldinfo)
else:
print("Resource-ID - {} incorrect.".format(rsrc_id))
print("{} is not a valid Resource-ID".format(rsrc_id))
def get_last_resource(self):
"""Returns the last collected data.
"""
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

setup(
name="datagovindia",
version='0.1',
version='0.2',
author='Aditya Karan Chhabra',
maintainer = 'Abhishek Arora',
author_email='aditya0chhabra@gmail.com',
packages=find_packages(include=['datagovindia', 'datagovindia.*'],exclude=['data','.*gz']),
scripts=['datagovindia/__init__.py','datagovindia/util.py'],
Expand Down

0 comments on commit 33ab07a

Please sign in to comment.