forked from Pavel_Durov/python_bot
#5 another way
This commit is contained in:
parent
7090ab218e
commit
4a3f799284
@ -28,21 +28,22 @@ def get_posts_to_be_removed(chat_id, type=None, max_id=None):
|
|||||||
else:
|
else:
|
||||||
posts = [p for p in collections.get_posts_removal_collection().find({'chat_id': chat_id}, skip=0, limit=1100) ]
|
posts = [p for p in collections.get_posts_removal_collection().find({'chat_id': chat_id}, skip=0, limit=1100) ]
|
||||||
|
|
||||||
posts_ret = []
|
posts_ret = [ p for p in posts ]
|
||||||
for p in posts:
|
# # for p in posts:
|
||||||
last_time = datetime.datetime.strptime(p['datetimes'], '%Y-%m-%d %H:%M:%S')
|
# # last_time = datetime.datetime.strptime(p['datetimes'], '%Y-%m-%d %H:%M:%S')
|
||||||
timediff = (datetime.datetime.now() - last_time).total_seconds()
|
# # timediff = (datetime.datetime.now() - last_time).total_seconds()
|
||||||
|
|
||||||
if timediff > 60:
|
# # if timediff > 60:
|
||||||
posts_ret.append(p)
|
# # posts_ret.append(p)
|
||||||
|
|
||||||
if max_id:
|
if max_id:
|
||||||
posts_ret = [ p for p in posts_ret if p['msg_id'] != max_id]
|
posts_ret = [ p for p in posts_ret if p['msg_id'] != max_id]
|
||||||
else:
|
else:
|
||||||
posts_ret = [ p for p in posts_ret if p['msg_id'] != max([pp['msg_id'] for pp in posts_ret])]
|
posts_ret = [ p for p in posts_ret if p['msg_id'] != max([pp['msg_id'] for pp in posts_ret])]
|
||||||
### оставлять последний пост
|
|
||||||
|
|
||||||
|
|
||||||
|
#### TODO удалять все предыдущие без учёта времени
|
||||||
|
|
||||||
return posts_ret
|
return posts_ret
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('ошибка DB :: получение постов на удаление')
|
print('ошибка DB :: получение постов на удаление')
|
||||||
|
Loading…
Reference in New Issue
Block a user