This repository has been archived by the owner on Apr 22, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmirrorkan_db.py
70 lines (53 loc) · 1.88 KB
/
mirrorkan_db.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import json
import os
from dateutil.parser import parse
class Database:
def __init__(self, path):
self.path = path
if os.path.exists(path):
return
with open(path, 'w') as db_file:
db_file.write('{}')
def add_mod(self, url, filename, lastModified):
db = None
with open(self.path, 'r') as db_file:
db = json.load(db_file)
db[url] = (lastModified, filename)
if db is not None:
with open(self.path, 'w') as db_file:
json.dump(db, db_file)
def is_newer(self, url, lastModified):
with open(self.path, 'r') as db_file:
db = json.load(db_file)
if url not in db:
return True
lastModifiedCached = db[url][0]
if lastModifiedCached == 'LastModifiedHeaderMissing':
return True
dateCached = parse(lastModifiedCached)
dateIncoming = parse(lastModified)
if dateIncoming > dateCached:
return True
return False
return True
def get_lastmodified(self, url):
with open(self.path, 'r') as db_file:
db = json.load(db_file)
if url not in db:
return None
return db[url][0]
return None
def get_filename(self, url):
with open(self.path, 'r') as db_file:
db = json.load(db_file)
if url not in db:
return None
return db[url][1]
return None
def is_cached(self, url):
with open(self.path, 'r') as db_file:
db = json.load(db_file)
if url not in db:
return False
return True
return False