Example #1
0
def timesince(date, default="Just Now"):
    """
    Returns string representing "time since" e.g.
    3 days ago, 5 hours ago
    """
    now = helper.now()
    if not isinstance(date, datetime):
        date = helper.str_to_datetime(date)
    diff = now - date

    periods = (
        (diff.days / 365, "year", "years"),
        (diff.days / 30, "month", "months"),
        (diff.days / 7, "week", "weeks"),
        (diff.days, "day", "days"),
        (diff.seconds / 3600, "hour", "hours"),
        (diff.seconds / 60, "minute", "minutes"),
        (diff.seconds, "second", "seconds"),
    )

    for period, singular, plural in periods:
        if period:
            return "%d %s ago" % (period, singular if period == 1 else plural)

    return default
Example #2
0
 def _extract_company_data(self, name, code):
     return {
         "name": name,
         "code": code,
         #"quandlCode": data['dataset_code'],
         "description": name,
         "stockExchangeCode": 'NSE',
         "type": 'Time Series',
         "frequency": 'daily',
         "refreshedAt": helper.now(),
         #"oldestAvailableDate": helper.now(),
         "newAvailableDate": helper.now(),
         "history": [],
         "historyCount": 0,
         "weight": 1
     }
Example #3
0
 def transform(self, data):
     return {
         "date": data['cm_adj_low_dt'],
         "open": data['open'],
         "high": data['dayHigh'],
         "low": data['dayLow'],
         "last": data['lastPrice'],
         "close": data['previousClose'],
         "totalTradeQuantity": data['quantityTraded'],
         "turnover": None,
         "refreshedAt": helper.now()
     }
Example #4
0
def transform_nsetools_stock(data):
    """ Will not be used. Using in stockapis.NSE"""
    return {
        "date": data['cm_adj_low_dt'],
        "open": data['open'],
        "high": data['dayHigh'],
        "low": data['dayLow'],
        "last": data['lastPrice'],
        "close": data['previousClose'],
        "totalTradeQuantity": data['quantityTraded'],
        "turnover": '-',
        "refreshedAt": helper.now()
    }
Example #5
0
 def get_auth_user(self, token):
     token = self.filter(token=token, expiresAt__gt=helper.now()).first()
     if not token:
         raise SException('Invalid authorization token', 401)
     return token.user