0

I was trying to read s3 file which is a fee summary report and now i am trying to Check if the report is present and if the report is older than specified time (configurable) and return boolean my code is shown below,

import boto3
import json
import os

BUCKET_NAME = os.getenv('')
KEY = os.getenv('')


def send_notification():
    report = get_report()
    print(bool(report))
    print(report)


def get_report():
    s3_client = boto3.client('s3')
    response = s3_client.get_object(Bucket=BUCKET_NAME, Key=KEY)
    data = response['Body'].read()
    report = json.loads(data)
    return report

I need to set a time locally and compare it with the date which is there on the fee summary report and return a boolean value. Kindly looking for someone's help. Thanks in advance.

annie
  • 11
  • 1
  • 1
  • 5

1 Answers1

0

Let's say you have a column of dates. You can convert the time to your desired timezone, e.g. "America/Los_Angeles" using the datetime and pytz module.

import datetime as dt
import pytz

dates = ["2017-01-01 14:00:00","2017-01-01 14:00:00", "2017-01-01 14:00:00","2017-01-01 14:30:00"]

for d in dates:
    start = dt.datetime.strptime(d, "%Y-%m-%d %H:%M:%S")
    start = start.replace(tzinfo=pytz.utc)
    local_tz = pytz.timezone("America/Los_Angeles")  # convert to desired timezone

To check if a time is greater than any specific time, let's say 9 o'clock, use:

utc = pytz.utc
loc_dt = utc.localize(datetime.datetime.today().replace(hour=9, minute=0))

today = utc.localize(datetime.datetime.today())

if loc_dt < today:
    print("True")
Ka Wa Yip
  • 2,546
  • 3
  • 22
  • 35