Exemplo n.º 1
0
 def cleanup(self):
     """Marks dead entries as vaporized"""
     #update data model
     #todo: remove this after the data model has been upgraded
     #vapUrls = VapUrl.all()
     #for vapUrl in vapUrls:
     #    if vapUrl.vaporized == None:
     #        vapUrl.vaporized = False
     #        vapUrl.put()
     
     # timed out
     vapUrls = VapUrl.all()
     vapUrls.filter('vaporized =', False)
     vapUrls.order('exp_datetime')
     vapUrls.filter('exp_datetime <', datetime.datetime.now())
     for vapUrl in vapUrls:
         vapUrl.vaporized = True
         vapUrl.put()
         
     # visited out
     vapUrls = VapUrl.all()
     vapUrls.filter('vaporized =', False)
     vapUrls.order('visits_remaining')
     vapUrls.filter('visits_remaining <', 1)
     for vapUrl in vapUrls:
         vapUrl.vaporized = True
         vapUrl.put()
Exemplo n.º 2
0
 def create(self, url, max_time, max_visits):
     """Creates a new VapUrl and returns it if successful"""
     random.seed(str(random.random()) + url)
     name = ''.join([random.choice('abcdefghijklmnopqrstuvwxyz-0123456789') for i in range(10)])
     
     vapUrl = None
     try:
         vapUrl = VapUrl()
         vapUrl.name = name
         vapUrl.link = db.Link(url)
         vapUrl.vaporized = False
         vapUrl.exp_datetime = datetime.datetime.now() + datetime.timedelta(minutes=max_time)
         vapUrl.visits_max = max_visits
         vapUrl.visits_remaining = max_visits
         vapUrl.put()
     except:
         vapUrl = None
     
     if vapUrl != None:
         counters = Counter.all()
         counters.filter('type = ', 'creates/alltime')
         if counters.count() > 0:
             counter = counters[0]
             #TODO: make transactional
             counter.count += 1
             counter.put()
         else:
             counter = Counter()
             counter.type = 'creates/alltime'
             counter.count = 1
             counter.put()
     return vapUrl;
Exemplo n.º 3
0
 def get(self):
     template_data = {
         'version': os.environ['CURRENT_VERSION_ID'][:os.environ['CURRENT_VERSION_ID'].rfind('.')].replace('-','.')
     }
     
     vapurlController = VapurlController()
     vapurlController.cleanup()
     
     name = self.request.get('id')
     vapUrls = VapUrl.all()
     vapUrls.filter('name =', name)
     if vapUrls.count() > 0:
         vapUrl = vapUrls[0]
         template_data['have_info'] = True
         template_data['name'] = vapUrl.name
         template_data['create_datetime'] = vapUrl.create_datetime
         template_data['exp_datetime'] = vapUrl.exp_datetime
         if vapUrl.visits_max:
             template_data['visits_used'] = (vapUrl.visits_max - vapUrl.visits_remaining)
         else:
             template_data['visits_used'] = 'unknown'
         template_data['visits_remaining'] = vapUrl.visits_remaining
             
     path = os.path.join(os.path.dirname(__file__), 'templates/info.html')
     self.response.out.write(template.render(path, template_data))
Exemplo n.º 4
0
    def redirectByName(self, name):
        destination = None
        
        vapUrls = VapUrl.all()
        vapUrls.filter('name =', name)
        vapUrls.filter('vaporized =', False)
        vapUrls.filter('exp_datetime >=', datetime.datetime.now())
        # can't use more than one inequality filter :(
        #vapUrls.filter('visits_remaining >', 0)
        
        if vapUrls.count() > 0:
            vapUrl = vapUrls[0]
            if vapUrl.visits_remaining > 0:
                destination = vapUrl.link
                vapUrl.visits_remaining -= 1
                vapUrl.put()
            
        if destination == None:
            destination = '/' # we didn't go anywhere, so let's go home
        else:    
            counters = Counter.all()
            counters.filter('type = ', 'visits/alltime')
            if counters.count() > 0:
                counter = counters[0]
                #TODO: make transactional
                counter.count += 1
                counter.put()
            else:
                counter = Counter()
                counter.type = 'visits/alltime'
                counter.count = 1
                counter.put()

        self.redirect(destination)