通过日期在AWS S3中使用boto检索对象
我存储这些数据的格式是:
网站/网站名/对象哈希/横坐标/纵坐标/可能性/年份/月/日期编号/小时/分钟
现在我有了一个存储这些数据的桶。
假设我想要最近的10个存储对象,有什么高效的方法吗?
我已经有了这个桶,那我该怎么做呢?
我之前的解决方案是这样的,用来获取今天的数据,不过我对获取最近的数据的逻辑不太确定:
def getKeys():
b = bucket.list()
theKeys=[]
for key in b:
theKeys.append(key)
return theKeys
def getDecompiledToday():
time = datetime.datetime.now()
year =time.strftime("%Y")
month = time.strftime("%m")
day = time.strftime("%D")
keys = getKeys()
objects = []
for k in keys:
splitK= k.split("/")
if splitK[6]==year and splitK[7]==month and splitK[8]==day:
objets.append(bucket.get_key(k))
return
1 个回答
0
我想出的解决办法。
def getPastAmountDecompiledFromFile(number):
if bucketKeys.__len__() > 0:
Found=[]
latest=bucketKeys[0]
while Found.__len__() < number:
laterFound = False
for k in bucketKeys:
if latest in Found:
latest=k
current = k.split("/")
best = k.split("/")
if k not in Found and latest != k:
if int(current[6]) > int(best[6]):
laterFound=True
if int(current[6]) == int(best[6]) and int(current[7]) > int(best[7]):
laterFound=True
if int(current[6]) == int(best[6]) and int(current[7]) == int(best[7]) and int(current[8]) > int(best[8]):
laterFound=True
if int(current[6]) == int(best[6]) and int(current[7]) == int(best[7]) and int(current[8]) == int(best[8]) and int(current[9]) > int(best[9]):
laterFound=True
if laterFound:
latest = k
if laterFound:
Found.append(latest)
return getKeyFromKeyNames(Found)
else:
getKeysInFile()
getPastAmountDecompiledFromFile(number)
return