Restructure project

This commit is contained in:
Lucidiot 2018-04-13 19:42:28 +02:00
parent 0da7e52459
commit 7429e23b08
No known key found for this signature in database
GPG Key ID: 2C2A322692E18B6B
17 changed files with 61 additions and 107 deletions

17
.gitattributes vendored
View File

@ -1,17 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

View File

@ -1,3 +0,0 @@
from pygov import usda
__author__ = 'shane'

View File

@ -1 +0,0 @@
__author__ = 'scarroll'

View File

@ -1 +0,0 @@
__author__ = 'scarroll'

View File

@ -1,24 +0,0 @@
__author__ = 'scarroll'
import json
from pygov.base.client import DataGovClientBase, get_response_data
from pygov.census.domain import StatePopulationRecord
class CensusClient(DataGovClientBase):
def __init__(self, api_gov_key, version="v1"):
super(CensusClient, self).__init__('census/', api_gov_key, use_format=False)
self.version = version
self.acs_api = "american-community-survey/{}".format(self.version)
def get_action_uri(self, year, action):
return "{}/{}".format(year, action)
def get_state_population_by_year(self, year):
uri = self.build_uri(self.acs_api, self.get_action_uri(year, 'populations/states'))
response = get_response_data(uri)
results = []
for item in response[1:len(response)]:
results.append(StatePopulationRecord(item[0], item[1], item[2], year))
return results

View File

@ -1,13 +0,0 @@
__author__ = 'scarroll'
class StatePopulationRecord(object):
def __init__(self, population, state_name, state_id, year):
self.population = population
self.state_name = state_name
self.state_id = state_id
self.year = year
def __str__(self):
return "{} ({!s}): {!s}".format(self.state_name, self.year, self.population)

View File

@ -1 +0,0 @@
__author__ = 'sdc'

View File

@ -1,19 +0,0 @@
__author__ = 'scarroll'
import unittest
from pygov.census.client import CensusClient
class CensusTests(unittest.TestCase):
def setUp(self):
self.censusClient = CensusClient('DEMO_KEY')
def test_list_nutrients(self):
data = self.censusClient.get_state_population_by_year(2013)
for item in data:
print item
if __name__ == "__main__":
unittest.main()

View File

@ -1,4 +0,0 @@
__author__ = 'scarroll'
from client import UsdaClient
from enums import *
from domain import Food, FoodReport, Nutrient

View File

@ -1,12 +1,36 @@
__author__ = 'scarroll'
import os
from setuptools import setup, find_packages
from distutils.core import setup
setup(
name='pygov',
version='0.5dev',
packages=['pygov', 'pygov.usda', 'pygov.base'],
license='The MIT License (MIT)',
description='pygov enables easy access to the US Government''s data APIs (http://api.data.gov/docs/).',
long_description=open('README.rst').read(),
)
name='python-usda',
version='0.1',
author='Lucidiot',
packages=find_packages(
exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
package_data={
'': ['*.md', 'LICENSE', 'README'],
}
license='GNU General Public License 3',
description="A fork of pygov focused on USDA nutritional database API",
long_description=open('README.md').read(),
keywords="api usda nutrition food",
url="https://github.com/Lucidiot/python-usda",
classifiers=[
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Intended Audience :: Developers",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6"
],
project_urls={
"Source Code": "https://github.com/Lucidiot/python-usda",
"Gitter Chat": "https://gitter.im/BrainshitPseudoScience/Lobby",
}
)

6
usda/__init__.py Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from client import UsdaClient
from enums import *
from domain import Food, FoodReport, Nutrient

View File

@ -1,4 +1,5 @@
__author__ = 'scarroll'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import urllib
import urllib2
@ -27,4 +28,4 @@ class DataGovClientBase(object):
if 'format' not in kwargs and self.use_format:
kwargs['format'] = 'json'
params = urllib.urlencode(kwargs)
return "{0}{1}{2}/{3}?{4}".format(uri_base, self.uri_part, api, uri_action, params)
return "{0}{1}{2}/{3}?{4}".format(uri_base, self.uri_part, api, uri_action, params)

View File

@ -1,8 +1,9 @@
__author__ = 'scarroll'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pygov.usda.enums import *
from pygov.usda.domain import Nutrient, Food, FoodReport
from pygov.base.client import DataGovClientBase, get_response_data
from .enums import *
from .domain import Nutrient, Food, FoodReport
from .base import DataGovClientBase, get_response_data
class UsdaClient(DataGovClientBase):
@ -46,4 +47,4 @@ class UsdaClient(DataGovClientBase):
return self.__build_item_list(response_data, Food)
def __build_food_report(self, response_data):
return FoodReport(response_data)
return FoodReport(response_data)

View File

@ -1,4 +1,5 @@
__author__ = 'scarroll'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class UsdaObject(object):
@ -97,4 +98,4 @@ class FoodReport(UsdaObject):
self.nutrients = nutrients
self.report_type = report_type
self.foot_notes = foot_notes
self.food_group = food_group
self.food_group = food_group

View File

@ -1,4 +1,5 @@
__author__ = 'scarroll'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from enum import Enum
@ -23,4 +24,4 @@ class UsdaNdbListType(Enum):
class UsdaNdbReportType(Enum):
basic = "b"
full = "f"
stats = "s"
stats = "s"

3
usda/tests/__init__.py Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Unit tests for the usda package."""

View File

@ -1,8 +1,8 @@
__author__ = 'shane'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from pygov.usda.client import UsdaClient
from ..client import UsdaClient
class UsdaTests(unittest.TestCase):
@ -23,7 +23,7 @@ class UsdaTests(unittest.TestCase):
self.assertIsNotNone(food)
food_report = self.usdaClient.get_food_report(food.id)
self.assertIsNotNone(food_report)
print food_report
print(food_report)
if __name__ == "__main__":
unittest.main()