def query_most_recent(self, hash_key, hash_value, sort_key, date_str, limit=1):
"""Method to query for the record most recently in the past based on the date_str
Date_str must be in ISO-8601
Args:
hash_key (str): Hash key name
sort_key (str): Sort key name
date_str (str): The date string containing the day to query in UTC time
Returns:
dict
"""
response = self.table.query(KeyConditionExpression=Key(hash_key).eq(hash_value) & Key(sort_key).lte(date_str),
Limit=limit,
ScanIndexForward=False,
Select="ALL_ATTRIBUTES")
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise Exception("Error getting item: {}".format(response['ResponseMetadata']))
if "Items" in response:
if response["Items"]:
return response["Items"]
else:
return []
else:
return []
评论列表
文章目录