本文整理汇总了Python中hs_restclient.HydroShare.getResourceList方法的典型用法代码示例。如果您正苦于以下问题:Python HydroShare.getResourceList方法的具体用法?Python HydroShare.getResourceList怎么用?Python HydroShare.getResourceList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hs_restclient.HydroShare
的用法示例。
在下文中一共展示了HydroShare.getResourceList方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def home(request):
"""
Controller for the app home page.
"""
logger = logging.getLogger('django')
logger.error('Entering controller.py...')
res_output = ""
client_id = getattr(settings, "SOCIAL_AUTH_HYDROSHARE_KEY", "None")
client_secret = getattr(settings, "SOCIAL_AUTH_HYDROSHARE_SECRET", "None")
token = request.user.social_auth.get(provider='hydroshare').extra_data['token_dict']
token_dict_str = "Token: {0}".format(str(token))
logger.error(token_dict_str)
auth = HydroShareAuthOAuth2(client_id, client_secret, token=token)
try:
logger.error("Fetching resource list from playground.hydroshare.org")
hs = HydroShare(auth=auth, hostname='playground.hydroshare.org')
for resource in hs.getResourceList():
res_output += str(resource)
context = {"res_output": res_output, "token_dict_str": token_dict_str}
return render(request, 'oauth_user_demo/home.html', context)
except TokenExpiredError as e:
# TODO: redirect back to login view, giving this view as the view to return to
logger.error("TokenExpiredError: TODO: redirect to login view")
raise e
示例2: test_get_resource_list
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def test_get_resource_list(self):
hs = HydroShare()
res_list = hs.getResourceList()
for (i, r) in enumerate(res_list):
self.assertEquals(r['resource_title'], self.resource_titles[i])
self.assertEquals(r['resource_id'], self.resource_ids[i])
示例3: get_resource_list
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def get_resource_list():
hs = HydroShare()
resource_list = []
for resource in hs.getResourceList(types=['RasterResource']):
res_name = '{} [creator: {}]'.format(resource['resource_title'], resource['creator'])
resource_list.append((res_name, resource['resource_id']))
return resource_list
示例4: test_get_resource_list_filter_date
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def test_get_resource_list_filter_date(self):
hs = HydroShare()
from_date = date(2015, 5, 20)
res_list = hs.getResourceList(from_date=from_date)
for (i, r) in enumerate(res_list):
self.assertTrue(datetime.strptime(r['date_created'], '%m-%d-%Y').date() >= from_date)
to_date = date(2015, 5, 21) # up to and including 5/21/2015
res_list = hs.getResourceList(to_date=to_date)
for (i, r) in enumerate(res_list):
self.assertTrue(datetime.strptime(r['date_created'], '%m-%d-%Y').date() < to_date)
from_date = date(2015, 5, 19)
to_date = date(2015, 5, 22) # up to and including 5/21/2015
res_list = hs.getResourceList(from_date=from_date, to_date=to_date)
for (i, r) in enumerate(res_list):
self.assertTrue(datetime.strptime(r['date_created'], '%m-%d-%Y').date() >= from_date)
self.assertTrue(datetime.strptime(r['date_created'], '%m-%d-%Y').date() < to_date)
示例5: Test_All_Resources
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def Test_All_Resources(request):
try:
start = time()
res_count = 0
num_success = 0
num_errors = 0
error_resource_list = []
ACCEPTABLE_ERRORS_LIST = ['This resource is too large to open in HydroShare GIS',
'There is no projection information associated with this resource',
'Resource contains insufficient geospatial information']
set_currently_testing(True)
auth = HydroShareAuthBasic(username='test', password='test')
hs = HydroShare(auth=auth)
valid_res_types = ['GeographicFeatureResource', 'RasterResource', 'RefTimeSeriesResource',
'GenericResource', 'ScriptResource']
resource_list = hs.getResourceList(types=valid_res_types)
num_resources = 0
for res in hs.getResourceList(types=valid_res_types):
if res['public']:
num_resources += 1
for res in resource_list:
res_id = None
try:
if res['public']:
res_count += 1
res_id = res['resource_id']
print "Currently testing resource %s of %s: %s" % (res_count, num_resources, res_id)
if res['resource_type'] == 'GenericResource':
response = get_res_files_list(hs, res_id)
if response['success']:
res_files_list = response['results']['generic_res_files_list']
num_files_failed = 0
for i, res_file in enumerate(res_files_list):
response = process_generic_res_file(hs, res_id, res_file,
request.user.username, i)
if response['success']:
pass
else:
error_acceptable = False
for error in ACCEPTABLE_ERRORS_LIST:
if error in response['message']:
error_acceptable = True
break
if error_acceptable:
pass
else:
num_files_failed += 1
error_resource_list.append('https://www.hydroshare.org/resource/%s on file %s'
% (res_id, res_file))
print 'ERROR ENCOUNTERED:'
print 'RES_ID: %s' % res_id
print 'MESSAGE: %s' % response['message']
if num_files_failed == 0:
num_success += 1
else:
num_errors += 1
else:
response = process_nongeneric_res(hs, res_id)
if response['success']:
num_success += 1
else:
error_acceptable = False
for error in ACCEPTABLE_ERRORS_LIST:
if error in response['message']:
error_acceptable = True
break
if error_acceptable:
num_success += 1
else:
num_errors += 1
error_resource_list.append('https://www.hydroshare.org/resource/%s' % res_id)
print 'ERROR ENCOUNTERED:'
print 'RES_ID: %s' % res_id
print 'MESSAGE: %s' % response['message']
except Exception as e:
num_errors += 1
error_resource_list.append('https://www.hydroshare.org/resource/%s' % res_id)
print 'ERROR ENCOUNTERED:'
print 'RES_ID: %s' % res_id
print 'MESSAGE: %s' % str(e)
print "%d%% complete" % (res_count * 100 / num_resources)
elapsed = str(timedelta(seconds=time()-start))
results = '''
ALL TESTS COMPLETE!
SUMMARY
TIME ELAPSED: {0}
TOTAL RESOURCES TESTED: {1}
TOTAL FAILED: {2}
PERCENT FAILED: {3}
TOTAL SUCCESSFUL: {4}
PERCENT SUCCESSFUL: {5}
#.........这里部分代码省略.........
示例6: test_get_resource_list_filter_type
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def test_get_resource_list_filter_type(self):
hs = HydroShare()
res_list = hs.getResourceList(types=('RasterResource',))
for (i, r) in enumerate(res_list):
self.assertEquals(r['resource_type'], 'RasterResource')
示例7: test_get_resource_list_filter_creator
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceList [as 别名]
def test_get_resource_list_filter_creator(self):
hs = HydroShare()
res_list = hs.getResourceList(creator='bmiles')
for (i, r) in enumerate(res_list):
self.assertEquals(r['creator'], 'bmiles')