remove utils.py
This commit is contained in:
parent
8814e462d3
commit
26cf5722b2
|
@ -4,10 +4,13 @@ import logging
|
||||||
import time
|
import time
|
||||||
import utils
|
import utils
|
||||||
import base64
|
import base64
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import deferred
|
import deferred
|
||||||
from deferred import call
|
from deferred import call
|
||||||
|
|
||||||
|
def sha1hash(data):
|
||||||
|
hashlib.sha1(data).hexdigest()
|
||||||
|
|
||||||
class Buddy():
|
class Buddy():
|
||||||
def __init__(self, owner, number, nick, statusMsg, groups, image_hash):
|
def __init__(self, owner, number, nick, statusMsg, groups, image_hash):
|
||||||
|
@ -197,7 +200,7 @@ class BuddyList(dict):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
nick = ""
|
nick = ""
|
||||||
groups = []
|
groups = []
|
||||||
image_hash = pictureData.then(utils.sha1hash)
|
image_hash = pictureData.then(sha1hash)
|
||||||
call(self.logger.debug, 'Image hash is %s' % image_hash)
|
call(self.logger.debug, 'Image hash is %s' % image_hash)
|
||||||
call(self.update, buddynr, nick, groups, image_hash)
|
call(self.update, buddynr, nick, groups, image_hash)
|
||||||
# No image
|
# No image
|
||||||
|
|
|
@ -23,6 +23,23 @@ import deferred
|
||||||
from deferred import call
|
from deferred import call
|
||||||
from yowsupwrapper import YowsupApp
|
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:
|
class MsgIDs:
|
||||||
def __init__(self, xmppId, waId):
|
def __init__(self, xmppId, waId):
|
||||||
|
@ -656,7 +673,7 @@ class Session(YowsupApp):
|
||||||
def onSuccess(buddy, lastseen):
|
def onSuccess(buddy, lastseen):
|
||||||
timestamp = time.localtime(time.localtime()-lastseen)
|
timestamp = time.localtime(time.localtime()-lastseen)
|
||||||
timestring = time.strftime("%a, %d %b %Y %H:%M:%S", timestamp)
|
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):
|
def onError(errorIqEntity, originalIqEntity):
|
||||||
self.sendMessageToXMPP(errorIqEntity.getFrom(), "LastSeen Error")
|
self.sendMessageToXMPP(errorIqEntity.getFrom(), "LastSeen Error")
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
"""
|
|
||||||
|
|
||||||
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()
|
|
Loading…
Reference in a new issue