Created
July 14, 2019 07:09
-
-
Save sigmapie8/7cd7369fe9e536b5db97cbea04b0fa4b to your computer and use it in GitHub Desktop.
Sorting files on the basis of date modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def latest_post(): | |
""" | |
returns the last modified post in posts directory | |
""" | |
posts_dic = dict() | |
for dirpath, dirnames, filenames in os.walk(posts_directory): | |
for dirname in dirnames: | |
posts_dic[dirname] = os.stat(dirpath+"/"+dirname).st_mtime | |
return max(posts_dic.keys(), key=(lambda x: posts_dic[x])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment