def checkURL(self, url): msg = False try: request = urllib.request.urlopen(url) if request.code == 200: if request.code == 200 and not url.startswith('https://'): try: tmp = url.split('//') request = requests.get("https://" + tmp[-1]) msg = errors.http() except: msg = errors.okay() elif request.code < 400 and request.code >= 300: msg = errors.check_link() elif request.code >= 400: msg = errors.broken_url() else: msg = errors.check_link() except urllib.request.HTTPError as e: msg = errors.broken_url() except urllib.request.URLError as e: msg = errors.check_link() if not msg and not url.startswith('ftp'): msg = errors.okay() elif url.startswith('ftp'): msg = errors.ftp() else: pass return msg
def checkEquatorCrossingTime(self, val, length): #print("Input of checkEquatorCrossingTime() is ...") if length == 1: return self.__checkTimeStr( val, errors.not_provided(), errors.okay(), errors_date_format_error(val), errors_date_format_day_error(val), errors_date_format_month_error(val), errors_date_format_inserttime_future_error(val)) ''' try: if val == None: return errors.not_provided() if not val.endswith("Z"): return "DateTime error" val = val.replace("Z", "") t_record = datetime.strptime(val, '%Y-%m-%dT%H:%M:%S') if t_record.microsecond / 1000 > 999: return "DateTime error" t_now = datetime.now() if t_record.year > t_now.year: return "DateTime error" return "OK - quality check" except ValueError: return "DateTime error" ''' else: for i in range(0, length): return self.__checkTimeStr( val['EquatorCrossingDateTime'], errors.not_provided(), errors.okay(), errors_date_format_error(val), errors_date_format_day_error(val), errors_date_format_month_error(val), errors_date_format_inserttime_future_error(val)) '''
def checkCollectionVersionID(self, sname): #print("Input of checkCollectionVersionID() is " + sname) if sname == None: return "np - Ensure the DataSetId field is provided." else: return errors.okay()
def checkTemporalSingleTime(self, val): #print("Input of checkTemporalSingleTime() is " + val) return self.__checkTimeStr( val, errors.not_provided(), errors.okay(), errors_date_format_error(val), errors_date_format_day_error(val), errors_date_format_month_error(val), errors_date_format_inserttime_future_error(val)) '''
def checkProductionDateTime(self, prodTime, insertTime): #print("Input of checkProductionDateTime() is " + prodTime + ', ' + insertTime) return self.__checkTimeStr( val, errors.not_provided(), errors.okay(), errors_date_format_error(val), errors_date_format_day_error(val), errors_date_format_month_error(val), errors_date_format_inserttime_future_error(val)) '''
def checkDataSetId(set, val): #print("Input of checkDataSetId() is " + val) if val == None: return "np - Ensure that the ShortName and VersionId fields are provided." elif val.isupper() or val.islower(): return "Recommend that the Dataset Id use mixed case to optimize human readability." else: return errors.okay()
def checkDayNightFlag(set, val): #print("Input of checkDayNightFlag() is " + val) DNFlags = ('DAY', 'NIGHT', 'BOTH', 'UNSPECIFIED') if val == None: return errors.not_provided() elif val.upper() not in DNFlags: return "Invalid value for DayNightFlag. Valid values include: DAY; NIGHT; BOTH; UNSPECIFIED" else: return errors.okay()
def checkOnlineResourceURL(self, val, length): #print("Input of checkOnlineResourceURL() is ...") #print("Input of checkOnlineAccessURL() is ...") check = [] broken = [] okay = [] ftp = [] http = [] if length == 1: if val == None: return errors.not_provided() error = self.checkURL(val) + '\n' + val[i]['URL'] return error else: error = '' for i in range(0, length): if val[i]['URL'] == None: return errors.not_provided() else: if self.checkURL(val[i]['URL']) == errors.check_link(): check.append(val[i]['URL']) elif self.checkURL(val[i]['URL']) == errors.broken_url(): broken.append(val[i]['URL']) elif self.checkURL(val[i]['URL']) == errors.http(): http.append(val[i]['URL']) elif self.checkURL(val[i]['URL']) == errors.ftp(): ftp.append(val[i]['URL']) elif self.checkURL(val[i]['URL']) == errors.okay(): okay.append(val[i]['URL']) if len(check) > 0: error += errors.check_link() + '\n' + '\n'.join(check) if len(broken) > 0: error += errors.broken_url() + '\n' + '\n'.join(check) if len(http) > 0: error += errors.http() + '\n' + '\n'.join(check) if len(ftp) > 0: error += errors.ftp() + '\n' + '\n'.join(check) if len(okay) > 0 and (len(check) == 0 or len(broken) == 0 or len(http) == 0 or len(ftp) == 0): error += errors.okay() return error
def checkOnlineResourceType(self, val, length): #print("Input of checkOnlineResourceType() is ...") ResourcesTypes = list() response = requests.get(ResourcesTypeURL).text.split('\n') data = csv.reader(response) next(data) # Skip the first two row information next(data) for item in data: ResourcesTypes += item[0:1] ResourcesTypes = list(set(ResourcesTypes)) UmmEnumTypes = self.enums['RelatedUrlTypeEnum'] UmmEnumTypes.extend(self.enums['RelatedURLSubTypeEnum']) listA = [ "THREDDS CATALOG", "THREDDS DATA", "THREDDS DIRECTORY", "GET WEB MAP FOR TIME SERIES", "GET RELATED VISUALIZATION", "GIOVANNI", "WORLDVIEW", "GET MAP SERVICE" ] listB = [ "GET WEB MAP SERVICE (WMS)", "GET WEB COVERAGE SERVICE (WCS)", "OPENDAP DATA (DODS)" ] Results = [[], [], [], [], []] if length == 1: val = [val] for v in val: try: t = v['Type'] if t in listA: Results[1].append(t) elif t in listB: Results[2].append(t) elif t in UmmEnumTypes: Results[3].append(t) else: Results[4].append(t) except Exception as e: return "Each Online Resource URL must be accompanied by a URL Type. Valid values can be found in the UMM-Common schema. A type may be selected from either the URL Type enum or the URL Subtype enum. https://git.earthdata.nasa.gov/projects/EMFD/repos/unified-metadata-model/browse/v1.10/umm-cmn-json-schema.json" if Results[4]: return "Invalid URL Types: " + "; ".join( Results[4] ) + "\nA valid type may be selected from either the URL Type enum or the URL Subtype enum. https://git.earthdata.nasa.gov/projects/EMFD/repos/unified-metadata-model/browse/v1.10/umm-cmn-json-schema.json" # result = "; ".join(['; '.join(r) for r in Results[1:3] if r]) elif Results[2]: return "OK - two points for data accessability score for providing an advanced service for visualization, subsetting or aggregation which also meets common framework requirements for standard API based data access." elif Results[1]: return "OK - one point for data accessability score for providing an advanced service for visualization, subsetting or aggregation" elif Results[0]: return errors.okay() else: return errors.not_provided()
def checkCampaignShortName(self, val, campaignNum): #print("Input of checkCampaignShortName() is ...") CampaignKeys = list() CampaignLongNames = list() response = requests.get(ProjectURL).text.split('\n') data = csv.reader(response) next(data) # Skip the first two line information next(data) for item in data: if len(item) != 0: CampaignKeys += item[1:2] CampaignLongNames += item[2:3] CampaignKeys = list(set(CampaignKeys)) CampaignLongNames = list(set(CampaignLongNames)) if campaignNum == 1: if val == None: return errors.not_provided() elif val not in CampaignKeys: if val in CampaignLongNames: return val + ": incorrect keyword order" else: return "The keyword does not conform to GCMD." else: return errors.okay() else: for i in range(campaignNum): if val[i]['Campaign']['ShortName'] == None: return errors.not_provided() elif val[i]['Campaign']['ShortName'] not in CampaignKeys: if val[i]['Campaign']['ShortName'] in CampaignLongNames: return val[i]['Campaign'][ 'ShortName'] + ": incorrect keyword order" else: return "The keyword does not conform to GCMD." else: return errors.okay()
def checkInsertTime(self, val): #print("Input of checkInsertTime() is " + val) try: if val == None: return errors.not_provided() if not val.endswith("Z"): return "InsertTime error." val = val.replace("Z", "") t_record = datetime.strptime(val, '%Y-%m-%dT%H:%M:%S') if t_record.microsecond / 1000 > 999: return "InsertTime error." t_now = datetime.now() if t_record.year > t_now.year: return "InsertTime error." return errors.okay() except ValueError: return "InsertTime error."
def checkLastUpdate(self, updateTime, prodTime): #print("Input of checkLastUpdate() is " + updateTime + ', ' + prodTime) try: if updateTime == None: return errors.not_provided() elif not updateTime.endswith("Z"): return "LastUpdate time error." updateTime = updateTime.replace("Z", "") t_record = datetime.strptime(updateTime, '%Y-%m-%dT%H:%M:%S') prodTime = prodTime.replace("Z", "") p_record = datetime.strptime(prodTime, '%Y-%m-%dT%H:%M:%S') if t_record.microsecond / 1000 > 999: return "LastUpdate time error." t_now = datetime.now() if t_record.year > t_now.year or t_record < p_record: return "LastUpdate time error." return errors.okay() except ValueError: return "LastUpdate time error."
def checkGranuleUR(self, val): #print("Input of checkGranuleUR() is " + val) if val == None: return "Provide a granule UR for this granule. This is a required field." else: return errors.okay()