I have a demo xls sheet which consist of a column named "Date" in which both date and time are given. I have some videos saved on the cloud with epoch as its name(ie. 1580984820_1580984820.mp4). now I want to write the urls of these videos in the same excel sheet. I made a python code for this but there is some error in the logic which i dont know how to solve.
CODE
ACCESS_KEY = 'xyz'
SECRET_KEY = 'abc'
session = Session(aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
s3 = session.resource('uv')
your_bucket = s3.Bucket('pqr')
df = pd.read_excel('new.xls') ## with only column named as "Date"##
for date_times in df["Date"]:
pattern1 = '%d/%m/%Y %H:%M:%S'
full_epoch = int(time.mktime(time.strptime(date_times, pattern1))) ##Converting dates into epoch time ##
full_epoch += 43200 ## Just to match with the folder name on cloud
date = date_times.split("")[0]
dates = date.replace('/', '-')
pattern2 = '%d-%m-%Y'
date_epoch = int(time.mktime(time.strptime(dates, pattern2)))
dates_epoch = date_epoch + 46800 ##Because the name of the folder is the epoch time of that date##
for s3_file in `your_bucket.objects.filter(Delimiter='/', Prefix='path/to/the/folder/'):`
s3_new=s3_file.key
s3_new=s3_new.split("/")[-1] ## video file names are in 1234567890_1234567890.mp4 format with 1234567890 being the start time of the video.
video_epoch=s3_new.split('_')[0]
if int(full_epoch) - int(vid_epoch) == 0 : ## to sort the video url link to only one, so that only one video url gets printed after every date ##
video_url = str("url_of_the_video")
df["Video URL"] = video_url
df.to_excel("new.xls")
The problem I am facing is that I am not able to write different URLs for different entries. Also what I want do is the code should check for 10-20 entries only in the datasheet at once.