def complies_to_level(value, level=None):
    if level == 0:
        return conformsLevel0(value)
    elif level == 1:
        return conformsLevel1(value)
    elif level == 2:
        return conformsLevel2(value)

    return is_valid(value)
예제 #2
0
def result_json(request):
    """Returns boolean result of valid_edtf.py script in json format"""

    # grab the date from the request argument
    date = request.GET.get('date')
    jsonedtfdict = {}
    if date is '' or date is None:
        return HttpResponseBadRequest()
    elif 'level' in request.GET:
        level = request.GET.get('level')
        if level is '' or level is None or int(level) > 2 or int(level) < 0:
            return HttpResponseBadRequest()
        # build dictionary to serialize to json
        funcs = {
            '0': valid_edtf.isLevel0(date),
            '1': valid_edtf.isLevel1(date),
            '2': valid_edtf.isLevel2(date),
        }
        jsonedtfdict = {
            'validEDTF': valid_edtf.is_valid(date) and funcs[level]
        }
    else:
        # build dictionary to serialize to json
        jsonedtfdict = {
            'validEDTF': valid_edtf.is_valid(date)
        }

    # dump the dict to as an HttpResponse
    response = HttpResponse(content_type='application/json; charset=utf-8')
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Headers'] = 'X-Requested-With'
    json.dump(
        jsonedtfdict,
        fp=response,
        indent=4,
        sort_keys=True,
        ensure_ascii=False,
    )
    return response
예제 #3
0
from oauth2client.service_account import ServiceAccountCredentials
from edtf_validate.valid_edtf import is_valid

# use creds to create a client to interact with the Google Drive API
scope = [
    'https://spreadsheets.google.com/feeds' + ' ' +
    'https://www.googleapis.com/auth/drive'
]
creds = ServiceAccountCredentials.from_json_keyfile_name('py_cred.json', scope)
gc = gspread.authorize(creds)

# Find a workbook by name and open the first sheet
sheet = gc.open("Copy of Box 30 - BFMF Metadata - amj").sheet1

# Extract and print all of the values
data = sheet.get_all_values()
headers = data.pop(0)

# Create dataframe from the values, get column date_created, make a list
df = pd.DataFrame(data, columns=headers)
edtf = df.get('date_created')
edtf_list = (list(edtf))

# Loop thru list and validate date_created values
count = 1
for item in edtf_list:
    valitem = is_valid(item)
    count = count + 1
    if valitem == False:
        print(str(count) + "  " + item + "  Invalid")
예제 #4
0
 def test_valid_edtf_interval(self, date):
     assert is_valid(date)
 def test_invalid_edtf_all(self, date):
     assert not is_valid(date)
예제 #6
0
 def test_valid_edtf_datetime(self):
     assert is_valid('2012-10-10T10:10:10Z')
예제 #7
0
 def test_invalid_edtf_datetime(self, date):
     # is_valid should fail if match doesn't exist
     assert not is_valid(date)
 def test_invalid_edtf_interval(self, date):
     assert not is_valid(date)
 def test_valid_edtf_datetime(self):
     assert is_valid('2012-10-10T10:10:10Z')
예제 #10
0
 def test_invalid_edtf_datetime(self, date):
     # is_valid should fail if match doesn't exist
     assert not is_valid(date)