dose history implementation

This commit is contained in:
mogad0n 2020-10-31 20:41:10 +05:30
parent 83095f61b1
commit 5379925407

View File

@ -131,7 +131,7 @@ class Tripsit(callbacks.Plugin):
"""<drugA> <drugB> """<drugA> <drugB>
fetches known interactions between the substances provided. fetches known interactions between the substances provided.
""" """
r = requests.get(url_combo, params={"drugA": drugA, "drugB": drugB}).json() r = requests.get(url_combo, params={f"drugA": drugA, f"drugB": drugB}).json()
if not r["err"] and r["data"][0]: if not r["err"] and r["data"][0]:
interaction = r["data"][0] interaction = r["data"][0]
drug_a = interaction["interactionCategoryA"] drug_a = interaction["interactionCategoryA"]
@ -158,7 +158,7 @@ class Tripsit(callbacks.Plugin):
if nick in self.db: if nick in self.db:
self.db[nick]['timezone'] = timezone self.db[nick]['timezone'] = timezone
else: else:
self.db[nick] = {'timezone': timezone} self.db[nick] = {'timezone': timezone }
irc.replySuccess() irc.replySuccess()
set = wrap(set, ["something"]) set = wrap(set, ["something"])
@ -212,7 +212,7 @@ class Tripsit(callbacks.Plugin):
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4])) dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
dose_td_s = dose_td.total_seconds() dose_td_s = dose_td.total_seconds()
time = time - dose_td time = time - dose_td
doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method} doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method }
doses = self.db[nick].get('doses') doses = self.db[nick].get('doses')
if doses: if doses:
doses.append(doseLog) doses.append(doseLog)
@ -226,6 +226,7 @@ class Tripsit(callbacks.Plugin):
dose_td = 0 dose_td = 0
if ago is not None and len(ago) == 4: if ago is not None and len(ago) == 4:
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4])) dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
dose_td_s = dose_td.total_seconds()
time = time - dose_td time = time - dose_td
doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method } doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method }
doses = [doseLog] doses = [doseLog]
@ -243,13 +244,15 @@ class Tripsit(callbacks.Plugin):
@wrap([optional('positiveInt')]) @wrap([optional('positiveInt')])
def lastdose(self, irc, msg, args, history): def lastdose(self, irc, msg, args, history):
"""This command takes no arguments """<n>
retrieves your last logged dose
retrieves your <n>th last logged dose
""" """
nick = msg.nick nick = msg.nick
if nick in self.db: if nick in self.db:
if history: if history:
lastdose = self.db[nick]['doses'][int(history)] hist = -int(history)
lastdose = self.db[nick]['doses'][-int(history)]
else: else:
lastdose = self.db[nick]['doses'][-1] lastdose = self.db[nick]['doses'][-1]
dose = lastdose['dose'] dose = lastdose['dose']
@ -278,3 +281,4 @@ Class = Tripsit
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: