aws.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:donatemates 作者: donatemates 项目源码 文件源码
def query_24hr(self, hash_key, hash_value, sort_key, date_str):
        """Method to query for a date range for the day provided in the date_str

        Date_str must be in ISO-8601

        This assumes you are "centering" the 24hr block from midnight-midnight EST

        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:
            list
        """
        # Convert ISO time to be EST
        date_in = arrow.get(date_str)
        date_in_est = date_in.to('EST')

        # Compute start date str
        start_date = date_in_est.replace(hour=0, minute=0)

        # Compute end date str
        date_range = start_date.span('day')

        response = self.table.update_item(Key={hash_key: hash_value},
                                          KeyConditionExpression="{} >= :morning AND {} <= :midnight".format(sort_key,
                                                                                                             sort_key),
                                          ExpressionAttributeValues={':morning': date_range[0].isoformat(),
                                                                     ':midnight': date_range[1].isoformat()},
                                          ReturnValues="UPDATED_NEW")

        if response['ResponseMetadata']['HTTPStatusCode'] != 200:
            raise Exception("Error getting item: {}".format(response['ResponseMetadata']))

        if "Items" in response:
            return response["Items"]
        else:
            return []
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号