-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
41 lines (33 loc) · 1.03 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import json
import feedparser
import hitman
# get hitman directory
# hitman.directory()
def is_file_latest(f, url):
d = feedparser.parse(url)
# print d,url,file
if d.entries[0].enclosures:
if f == d.entries[0].enclosures[0]['href'].split('/')[-1]:
return True
else:
return False
def clean_downloads():
settings = hitman.get_settings()
if 'dl' in settings:
dl_dir = settings['dl']
else:
dl_dir = os.path.join(os.path.expanduser("~"), "Downloads")
listing = os.listdir(dl_dir)
for localfile, data in hitman.get_downloads().iteritems():
# db[localfile] = JSON obj {'url': url,
# 'date': time.ctime(), 'feed': feed_url}
if localfile in listing:
values = json.loads(data)
# check if file is the latest
if is_file_latest(localfile, values['feed']):
pass
else:
os.remove(os.path.join(dl_dir, localfile))
if __name__ == "__main__":
clean_downloads()