Exemple #1
0
    def get(self, user=None):
        self.response.headers["Content-Type"] = "text/plain"
        if user: to_list = [Count.all().filter('user = '******'time < ' , now - timedelta(days=150)).fetch(100)
            not_visited_recently = Count.all().filter('login < ', now - timedelta(days=60 )).fetch(100)
            to_list = [x for x in not_marked_recently + not_visited_recently if x.email is None][:MAX_MAILS_PER_REQUEST]

        for person_info in to_list:
            last_visited = person_info.login or person_info.time
            movies       = read_250_from_db()
            compare_days = (now - last_visited).days
            new_movies   = extract_new(movies, read_250_from_db(compare_days))      # Extract new movies since compare_days ago

            if new_movies:
                user_count  = mark_seen_movies(movies, user)                        # Count the number of movies the person has seen
                person_info = user_prop(person_info.user, set_count = user_count)   # and save it in the datastore
                if person_info:
                    vars = dict(locals().items() + globals().items())
                    mail.send_mail('*****@*****.**', person_info.user.email(),
                        'New movies on the IMDb Top 250',
                        template.render('campaign.txt', vars),
                        html=template.render('campaign.html', vars))
                    logging.info('Sent campaign email to ' + person_info.user.email())
                    self.response.out.write(person_info.user.email() + '\n')
                    person_info.email = now
                    person_info.put()
Exemple #2
0
 def get(self):
     CHUNK = 500
     users = []
     for row in Contacts.all().fetch(1000): users += pickle.loads(row.users)
     if not users: new = Count.all().order('__key__').fetch(CHUNK)
     else:         new = Count.all().filter('__key__ > ', users[-1].key()).order('__key__').fetch(CHUNK)
     if new:
         users += new
         contacts = Contacts()
         contacts.users = pickle.dumps(users)
         contacts.put()
         if len(new) >= CHUNK:
             taskqueue.add(url='/contact/generate', method='GET')
Exemple #3
0
 def get(self):
     CHUNK = 500
     users = []
     for row in Contacts.all().fetch(1000):
         users += pickle.loads(row.users)
     if not users: new = Count.all().order('__key__').fetch(CHUNK)
     else:
         new = Count.all().filter(
             '__key__ > ', users[-1].key()).order('__key__').fetch(CHUNK)
     if new:
         users += new
         contacts = Contacts()
         contacts.users = pickle.dumps(users)
         contacts.put()
         if len(new) >= CHUNK:
             taskqueue.add(url='/contact/generate', method='GET')
Exemple #4
0
    def get(self, user=None):
        self.response.headers["Content-Type"] = "text/plain"
        if user:
            to_list = [
                Count.all().filter('user = '******'time < ', now - timedelta(days=150)).fetch(100)
            not_visited_recently = Count.all().filter(
                'login < ', now - timedelta(days=60)).fetch(100)
            to_list = [
                x for x in not_marked_recently + not_visited_recently
                if x.email is None
            ][:MAX_MAILS_PER_REQUEST]

        for person_info in to_list:
            last_visited = person_info.login or person_info.time
            movies = read_250_from_db()
            compare_days = (now - last_visited).days
            new_movies = extract_new(movies, read_250_from_db(
                compare_days))  # Extract new movies since compare_days ago

            if new_movies:
                user_count = mark_seen_movies(
                    movies,
                    user)  # Count the number of movies the person has seen
                person_info = user_prop(
                    person_info.user,
                    set_count=user_count)  # and save it in the datastore
                if person_info:
                    vars = dict(locals().items() + globals().items())
                    mail.send_mail('*****@*****.**',
                                   person_info.user.email(),
                                   'New movies on the IMDb Top 250',
                                   template.render('campaign.txt', vars),
                                   html=template.render('campaign.html', vars))
                    logging.info('Sent campaign email to ' +
                                 person_info.user.email())
                    self.response.out.write(person_info.user.email() + '\n')
                    person_info.email = now
                    person_info.put()