Skip to content

Instantly share code, notes, and snippets.

View dwcaraway's full-sized avatar

Dave Caraway dwcaraway

  • Microsoft
  • Virginia
  • 16:20 (UTC -04:00)
View GitHub Profile
@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)
@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 / 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 / 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 / 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
def default_create_package_schema():
schema = {
'__before': [duplicate_extras_key, ignore],
'id': [empty],
'revision_id': [ignore],
'name': [not_empty, unicode, name_validator, package_name_validator],
'title': [if_empty_same_as("name"), unicode],
'author': [ignore_missing, unicode],
'author_email': [ignore_missing, unicode],
'maintainer': [ignore_missing, unicode],
{% if show_organizations_selector %}
{% set existing_org = data.owner_org %}
<div class="control-group">
<label for="field-organizations" class="control-label">{{ _('Organization') }}</label>
<div class="controls">
<select id="field-organizations" name="owner_org" data-module="autocomplete">
<option value="" {% if not selected_org and data.id %} selected="selected" {% endif %}>{{ _('Select an organization...') }}</option>
{% for organization in organizations_available %}
{# get out first org from users list only if there is not an existing org #}
{% set selected_org = (existing_org and existing_org == organization.id) or (not existing_org and not data.id and organization.id == organizations_available[0].id) %}
@dwcaraway
dwcaraway / test.py
Created November 20, 2013 03:19
trying to help debug weird error with ckan spatial extension.
import ckanext.spatial.validation.validation as v
from lxml import etree
TEST_FILE = 'satellite-systems_dscovr.xml'
with open(TEST_FILE, 'r') as f:
xmlobj = etree.XML(f.read())
validator = v.ISO19139NGDCSchema()
print(validator.is_valid(xmlobj))
@dwcaraway
dwcaraway / lang.py
Created November 20, 2013 20:06
Python script to generate a Javascript regular expression (regex) for BCP 47 / RFC 5646, a port of http://stackoverflow.com/questions/7035825/regular-expression-for-a-language-tag-as-defined-by-bcp47
regular = "(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)"
irregular = "(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)"
grandfathered = "(" + irregular + "|" + regular + ")"
privateUse = "(x(-[A-Za-z0-9]{1,8})+)"
singleton = "[0-9A-WY-Za-wy-z]"
extension = "(" + singleton + "(-[A-Za-z0-9]{2,8})+)"
variant = "([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3})"
region = "([A-Za-z]{2}|[0-9]{3})"
script = "([A-Za-z]{4})"
extlang = "([A-Za-z]{3}(-[A-Za-z]{3}){0,2})"
@dwcaraway
dwcaraway / data.json
Last active December 28, 2015 22:28
Valid data.json / Common Core Metadata entry
[{
"title": "Data Catalog",
"description": "Version 1.0",
"contactPoint": "somebody important",
"keyword": ["catalog"],
"modified": "2013-05-09 06:00:00",
"publisher": "US Department of X",
"person": "Contact Person",
"mbox": "contact.person@agency.gov",
"language": ["aav"],