Last active
December 31, 2015 22:19
-
-
Save uranusjr/8052858 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 | |
import os | |
from threading import Timer | |
last_file = None | |
def file_modified(name1, name2): | |
time1 = os.path.getmtime(name1) | |
time2 = os.path.getmtime(name2) | |
result = 0 | |
if time1 > time2: | |
result = 1 | |
elif time1 < time2: | |
result = -1 | |
return result | |
def try_read(): | |
os.chdir('/home/uranusjr/Pictures') | |
ok_file_exists = os.path.exists('OK') | |
if ok_file_exists: | |
os.remove('OK') | |
file_list = sorted(os.listdir('.'), cmp=file_modified, reverse=True) | |
global last_file | |
if last_file != file_list[0]: # Has new file | |
print 'New file!!', file_list[0] | |
last_file = file_list[0] | |
timer = Timer(1.0, try_read) | |
timer.start() | |
def main(): | |
try_read() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment