Skip to content

Commit

Permalink
Check release date in AutoFreezer
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed May 26, 2020
1 parent 4b5e1d6 commit a388d93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
12 changes: 7 additions & 5 deletions netkan/netkan/auto_freezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def _ids(self):

def _too_old(self, ident, update_cutoff):
status = ModStatus.get(ident)
release_date = getattr(status, 'release_date', None)
if release_date:
return release_date < update_cutoff
last_indexed = getattr(status, 'last_indexed', None)
if not last_indexed:
# Never indexed since the start of status tracking = 4+ years old
# ... except for mods that were updated by the old webhooks :(
return False
else:
if last_indexed:
return last_indexed < update_cutoff
# Never indexed since the start of status tracking = 4+ years old
# ... except for mods that were updated by the old webhooks :(
return False

def _add_freezee(self, ident):
self.netkan_repo.index.move([
Expand Down
3 changes: 3 additions & 0 deletions netkan/netkan/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def status_attrs(self, new=False):
attrs['ModIdentifier'] = self.ModIdentifier
if self.indexed:
attrs['last_indexed'] = datetime.now(timezone.utc)
release_date = getattr(self.ckan, 'release_date', None)
if release_date:
attrs['release_date'] = release_date
return attrs

def _process_ckan(self):
Expand Down
16 changes: 15 additions & 1 deletion netkan/netkan/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from hashlib import sha1
import uuid
import urllib.parse
import dateutil.parser


class Netkan:
Expand Down Expand Up @@ -94,14 +95,27 @@ class Ckan:
'application/x-compressed-tar': 'tar.gz',
'application/zip': 'zip',
}
ISODATETIME_PROPERTIES = [
'release_date'
]

def __init__(self, filename=None, contents=None):
if filename:
self.filename = Path(filename)
self.contents = self.filename.read_text()
else:
self.contents = contents
self._raw = json.loads(self.contents)
self._raw = json.loads(self.contents, object_hook=self._custom_parser)

def _custom_parser(self, dct):
# Special handling for DateTime fields
for k in self.ISODATETIME_PROPERTIES:
if k in dct:
try:
dct[k] = dateutil.parser.isoparse(dct[k])
except:
pass
return dct

def __getattr__(self, name):
if name in self._raw:
Expand Down
1 change: 1 addition & 0 deletions netkan/netkan/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Meta:
last_checked = UTCDateTimeAttribute(null=True)
last_indexed = UTCDateTimeAttribute(null=True)
last_inflated = UTCDateTimeAttribute(null=True)
release_date = UTCDateTimeAttribute(null=True)
success = BooleanAttribute()
frozen = BooleanAttribute(default=False)
resources = MapAttribute(default={})
Expand Down

0 comments on commit a388d93

Please sign in to comment.