def _record(timestamp_key): if request: RedisSet(timestamp_key + ":unique_ips").sadd( util.ip_to_int(request.META.get('REMOTE_ADDR'))) if user: RedisSet(timestamp_key + ":uniques").sadd(user.id) RedisKey(timestamp_key + ":count").incr(1)
def __init__(self, name): self.name = name.lower().strip().replace('#', '') self.base_key = 'tag:{}:posts'.format(self.name) self.new = RedisSortedSet(self.base_key) self.images_only = RedisLastBumpedBuffer(self.base_key + ':images', 1000) self.popular = RedisLastBumpedBuffer(self.base_key + ':popular', 1000) self.post_count = RedisKey(self.base_key + ':count')
def branch_count(self, experiment_name, branch_name): return int( RedisKey(self.basekey + ":" + "experiment:%s:%s:count" % (experiment_name, branch_name)).get() or 0)
def hourly_count(self, datetime): return int( RedisKey(self.basekey + ":" + datetime.strftime("%Y.%m.%d.%H") + ":count").get() or 0)
def daily_count(self, day): return int(RedisKey(self.daykey(day, 'count')).get() or 0)
def timestamp_key(self): return RedisKey(self.basekey + ":last_timestamp")
def __init__(self, type_id, name="", value=None, preference=None, limited=False, hidden=False, unusable=False, cost=None, title="", shop_filename=None, shop_text="", purchasable=None, achievement=None, admin_only=False, maximum=None, hide_from_inventory=False, seasonal=False): """ admin: Whether this sticker is only available for admins. shop_filename: Defaults to "name.png" if unspecified here. purchasable: Leave this as `None` and it will be determined from the cost and achievement status. Set it to `False` to override this and force it to not be sold in the shop. """ if cost is not None: cost = int(cost) if value is None: if cost is None or cost < 1: value = 1 else: value = math.sqrt(cost + 1) else: value = float(value) self._purchasable = purchasable if purchasable and not cost: raise ValueError('A sticker without a cost cannot be purchasable.') if shop_filename is None: shop_filename = u'{0}.png'.format(name) self.type_id = type_id self.name = name self.value = value self.preference = preference if preference is not None else type_id self._is_limited = bool(limited or cost or maximum) # not placeable anymore, but should still show up on existing posts. self._is_unusable = unusable # not placeable anymore nor should it show up on already stickered posts. self.is_hidden = hidden self.cost = cost self.title = title self.shop_filename = shop_filename self.shop_text = shop_text self.achievement = achievement self.admin_only = admin_only self.maximum = maximum self.user_remaining = None self.inventory_hash = None if self.maximum: self.inventory_hash = RedisKey("sticker:%s:remaining" % self.name) self.seasonal = seasonal self.hide_from_inventory = hide_from_inventory