From ccd4b73baab80939c5bef61d738564504e3207a1 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Mon, 15 Feb 2021 20:29:20 -0500 Subject: template: be able to replace existing dates --- zachwalk.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'zachwalk.py') diff --git a/zachwalk.py b/zachwalk.py index fd8ed64..b45d333 100755 --- a/zachwalk.py +++ b/zachwalk.py @@ -7,7 +7,7 @@ import ssl import fileinput from dateutil.parser import parse -DEFAULT = '1970-01-01' +DEFAULT = parse('1970-01-01').date() def getnewestdate(url): """load the url, and find the newest date listed in a link""" @@ -42,14 +42,26 @@ def gnd(fp): pass return DEFAULT +def replaceDateIfNewer(desc, newestdate): + try: + tup = parse(desc, fuzzy_with_tokens=True) + date = tup[0].date() + except: + return f'{newestdate} - {desc}' + if newestdate > date: + return str(newestdate) + ' '.join(tup[1]) + return desc + def main(): for line in fileinput.input(): #stdin or file from argv if line[0:2] == '=>': # plz don't use multiple spaces. url = line.split(' ')[1] desc = getdesc(line) + olddate = gnd(url) newestdate = getnewestdate(url) - print(f'=> {url} {newestdate} - {desc}') + desc = replaceDateIfNewer(desc, newestdate) + print(f'=> {url} {desc}') else: print(line.rstrip()) -- cgit 1.4.1