Skip to content

Instantly share code, notes, and snippets.

View dwcaraway's full-sized avatar

Dave Caraway dwcaraway

  • Microsoft
  • Virginia
  • 07:05 (UTC -04:00)
View GitHub Profile
@dwcaraway
dwcaraway / get.py
Created November 13, 2013 21:45
harvester checks for name
def harvesters_info_show(context,data_dict):
check_access('harvesters_info_show',context,data_dict)
available_harvesters = []
for harvester in PluginImplementations(IHarvester):
info = harvester.info()
if not info or 'name' not in info:
log.error('Harvester %r does not provide the harvester name in the info response' % str(harvester))
continue
@dwcaraway
dwcaraway / gist:6675971
Created September 23, 2013 19:51
Example Common Core Metadata with Distribution containing multiple resources.
{
"comment": "This is an example of using the Distribution field to identify a number of resources related to a dataset. See also http://project-open-data.github.io/schema/#expanded-fields",
"distribution": [
{
"accessURL": "https://api.data.gov/unicorns",
"format": "application/json"
},
{
"accessURL": "https://static.data.gov/coolfile.csv",
"format": "text/csv"
@dwcaraway
dwcaraway / model_save.py
Created September 18, 2013 13:02
Possible bug in model_save.py
def package_extras_save(extra_dicts, obj, context):
allow_partial_update = context.get("allow_partial_update", False)
if extra_dicts is None and allow_partial_update:
return
model = context["model"]
session = context["session"]
extras_list = obj.extras_list
old_extras = dict((extra.key, extra) for extra in extras_list)
@dwcaraway
dwcaraway / dictization_functions.py
Created September 9, 2013 19:47
augment_data function in dictization_functions.py. I found the ##fill junk and extras portion confusing
def augment_data(data, schema):
'''add missing, extras and junk data'''
flattented_schema = flatten_schema(schema)
key_combinations = get_all_key_combinations(data, flattented_schema)
full_schema = make_full_schema(data, schema)
new_data = copy.copy(data)
## fill junk and extras
@dwcaraway
dwcaraway / test_navl.py
Created September 8, 2013 23:46
Test of the augment_data function in dictization_functions.py
def test_augment_data_no_extras():
data = {
('foo',):'bar',
('foo2',):'bar2'
}
schema = {}
augmented_data = augment_data(data, schema)