From 26cf5722b2895f380fbf131d291388cf387c45f9 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 25 Apr 2019 22:12:39 +0200 Subject: [PATCH] remove utils.py --- transWhat/buddy.py | 5 ++++- transWhat/session.py | 19 +++++++++++++++++- transWhat/utils.py | 48 -------------------------------------------- 3 files changed, 22 insertions(+), 50 deletions(-) delete mode 100644 transWhat/utils.py diff --git a/transWhat/buddy.py b/transWhat/buddy.py index e3c226a..fb65f94 100644 --- a/transWhat/buddy.py +++ b/transWhat/buddy.py @@ -4,10 +4,13 @@ import logging import time import utils import base64 +import hashlib import deferred from deferred import call +def sha1hash(data): + hashlib.sha1(data).hexdigest() class Buddy(): def __init__(self, owner, number, nick, statusMsg, groups, image_hash): @@ -197,7 +200,7 @@ class BuddyList(dict): except KeyError: nick = "" groups = [] - image_hash = pictureData.then(utils.sha1hash) + image_hash = pictureData.then(sha1hash) call(self.logger.debug, 'Image hash is %s' % image_hash) call(self.update, buddynr, nick, groups, image_hash) # No image diff --git a/transWhat/session.py b/transWhat/session.py index 7a28898..843a0fc 100644 --- a/transWhat/session.py +++ b/transWhat/session.py @@ -23,6 +23,23 @@ import deferred from deferred import call from yowsupwrapper import YowsupApp +def ago(secs): + periods = ["second", "minute", "hour", "day", "week", "month", "year", "decade"] + lengths = [60, 60, 24, 7,4.35, 12, 10] + + j = 0 + diff = secs + + while diff >= lengths[j]: + diff /= lengths[j] + diff = round(diff) + j += 1 + + period = periods[j] + if diff > 1: period += "s" + + return "%d %s ago" % (diff, period) + class MsgIDs: def __init__(self, xmppId, waId): @@ -656,7 +673,7 @@ class Session(YowsupApp): def onSuccess(buddy, lastseen): timestamp = time.localtime(time.localtime()-lastseen) timestring = time.strftime("%a, %d %b %Y %H:%M:%S", timestamp) - self.sendMessageToXMPP(buddy, "%s (%s) %s" % (timestring, utils.ago(lastseen), str(lastseen))) + self.sendMessageToXMPP(buddy, "%s (%s) %s" % (timestring, ago(lastseen), str(lastseen))) def onError(errorIqEntity, originalIqEntity): self.sendMessageToXMPP(errorIqEntity.getFrom(), "LastSeen Error") diff --git a/transWhat/utils.py b/transWhat/utils.py deleted file mode 100644 index a5cf08b..0000000 --- a/transWhat/utils.py +++ /dev/null @@ -1,48 +0,0 @@ -__author__ = "Steffen Vogel" -__copyright__ = "Copyright 2015-2017, Steffen Vogel" -__license__ = "GPLv3" -__maintainer__ = "Steffen Vogel" -__email__ = "post@steffenvogel.de" - -""" - This file is part of transWhat - - transWhat is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - any later version. - - transwhat is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with transWhat. If not, see . -""" - -import base64 -import hashlib - -def ago(secs): - periods = ["second", "minute", "hour", "day", "week", "month", "year", "decade"] - lengths = [60, 60, 24, 7,4.35, 12, 10] - - j = 0 - diff = secs - - while diff >= lengths[j]: - diff /= lengths[j] - diff = round(diff) - j += 1 - - period = periods[j] - if diff > 1: period += "s" - - return "%d %s ago" % (diff, period) - -def decodePassword(password): - return base64.b64decode(bytes(password)) - -def sha1hash(data): - return hashlib.sha1(data).hexdigest()