def get(self, job_id): job = Job.get_by_key_name(job_id) if job and job.state != DONE and job.active == True: job.updated_at = datetime.now() job.state = DONE job.put() # update the email email = job.email email.updated_at = datetime.now() email.put() # count the number of jobs attached to this flyer job_query = Job.all() job_query.filter("flyer =", job.flyer) job_query.filter("active =", True) total_jobs = job_query.count() # count the number of jobs done so far job_query = Job.all() job_query.filter("flyer =", job.flyer) job_query.filter("active =", True) job_query.filter("state =", DONE) done_jobs = job_query.count() # write out self.response.out.write(template.render("templates/finish.html", {"total": total_jobs, "done": done_jobs})) else: self.error(404)
def get(self, email): q = Job.all() q.filter("email =", urllib.unquote(email)) jobs = q.fetch(BOUND) for job in jobs: job.delete() self.response.out.write(template.render("templates/sorry.html", {}))
def post(self, job_id): job = Job.get_by_key_name(job_id) # make sure the job is recent if not(job.active): self.error(404) email = job.email email.enable = False email.updated_at = datetime.datetime.now() email.put() # find the email-club join join_query = EmailToClub.all() join_query.filter("email =", email) joins = join_query.fetch(20) # do the delete for join in joins: join.enable = False join.updated_at = datetime.now() join.put() # mark all the jobs inactive job_query = Job.all() job_query.filter("email =", email) job_query.filter("active =", True) jobs = job_query.fetch(20) for job in jobs: job.active = False job.put() self.response.out.write(template.render("templates/sorry.html", {}))
def post(self, job_id): job = Job.get_by_key_name(job_id) # make sure the job is recent if not(job.active): self.error(404) club = job.flyer.club email = job.email # update the email email.updated_at = datetime.now() email.put() # find the email-club join join_query = EmailToClub.all() join_query.filter("email =", email) join_query.filter("club =", club) join = join_query.get() # do the delete join.enable = False join.updated_at = datetime.now() join.put() # mark all the jobs inactive flyer_query = Flyer.all() flyer_query.filter("club =", club) flyer_query.filter("active =", True) flyers = flyer_query.fetch(20) for flyer in flyers: job_query = Job.all() job_query.filter("email =", email) job_query.filter("flyer =", flyer) job_query.filter("active =", True) job = job_query.get() if job: job.active = False job.put() self.response.out.write(template.render("templates/sorry.html", {}))
def get(self): flyerq = Flyer.all() flyers = flyerq.fetch(BOUND) jobs = Job.all().fetch(BOUND) values = {"flyers": flyers, "jobs": jobs} self.response.out.write(template.render("templates/list.html", values))
def get(self, flyer_id, email): q = Job.all() q.filter("email =", urllib.unquote(email)) q.filter("flyer_id =", flyer_id) job = q.get() if job: job.delete() self.response.out.write(template.render("templates/finish.html", {})) else: self.error(404)
def get(self, flyer_id, email): q = Job.all() q.filter("email =", urllib.unquote(email)) q.filter("flyer_id =", flyer_id) job = q.get() if job: job.delete() self.response.out.write( template.render("templates/finish.html", {})) else: self.error(404)
def get(self): # clean out the old pdfs jobs = Job.all().fetch(BOUND) for job in jobs: job.delete() flyers = Flyer.all().fetch(BOUND) for flyer in flyers: flyer.delete() self.response.out.write( template.render("templates/task.html", {"msg": "Removed everything"}))
def get(self): t = list(time.localtime()) t[2] -= 31 dt = datetime.fromtimestamp(time.mktime(t)) jobs = Job.all() jobs.filter("date <", dt) jobs = jobs.fetch() for job in jobs: job.delete() self.response.out.write(template.render("templates/task.html", {"msg": "Removed old ones"}))
def get(self): # clean out the old jobs t = list(time.localtime()) t[2] -= 7 dt = datetime.datetime.fromtimestamp(time.mktime(t)) jobs = Job.all() jobs.filter("date <", dt) jobs = jobs.fetch(BOUND) for job in jobs: job.delete() self.response.out.write( template.render("templates/task.html", {"msg": "Removed old ones"}))
def get(self): # is it a week day? current_date = datetime.now(CurrentTimeZone()) day = current_date.weekday() # starts 0=monday... 6=sunday if day < 5: # weekday # get all the active jobs job_query = Job.all() job_query.filter("active =", True) jobs = job_query.fetch(2000) # check if the jobs are past their event date flyers = set([j.flyer for j in jobs]) for flyer in flyers: flyer_date = flyer.event_date.replace(tzinfo=CurrentTimeZone()) if current_date > flyer_date: flyer.active = False flyer.put() for job in jobs: if not(job.flyer.active): job.active = False job.put() # only get the un-done jobs jobs = [j for j in jobs if j.active and j.state != 2] # send the emails: bin jobs by email, send emails = set([j.email for j in jobs]) # !!! # email sending pre-computation domain = "http://%s.appspot.com" % get_application_id() fromaddr = "noreply@%s.appspotmail.com" % get_application_id() date = time.strftime("%Y/%m/%d") # send the emails for email in emails: js = [j for j in jobs if j.email == email] msg = mail.EmailMessage(sender="Flyer Guy <%s>" % fromaddr, to=email.email) msg.subject = "[Flyer] Reminder (%s)" % date msg.html = template.render("templates/email.html", {"jobs": js, "domain": domain, "email": email.email}) try: msg.send() except apiproxy_errors.OverQuotaError, (message,): # Log the error. logging.error("Could not send email") logging.error(message) self.response.out.write("Sent emails")
def get(self): jobq = Job.all() jobs = list(jobq.fetch(BOUND)) emails = list(set([j.email for j in jobs])) domain = "http://%s.appspot.com" % get_application_id() for email in emails: js = [j for j in jobs if j.email == email] msg = mail.EmailMessage( sender="Flyer Guy <*****@*****.**>", to=email) msg.subject = "[Flyer] Reminder" msg.html = template.render("templates/email.html", { "jobs": js, "domain": domain, "email": email }) try: msg.send() except apiproxy_errors.OverQuotaError, (message, ): # Log the error. logging.error("Could not send email") logging.error(message)
def get(self): timestamp = time.mktime(datetime.now().timetuple())-24*3600 yesterday = datetime.fromtimestamp(timestamp) # count how many flyers are going out current_date = datetime.now(CurrentTimeZone()) day = current_date.weekday() # starts 0=monday... 6=sunday if day < 5: job_query = Job.all() job_query.filter("active =", True) job_query.filter("state !=", DONE) flyer_count = job_query.count() else: flyer_count = 0 # get new clubs club_query = Club.all() club_query.filter("created_at >", yesterday) new_clubs = club_query.fetch(20) # get new emails email_query = Email.all() email_query.filter("created_at >", yesterday) new_emails = email_query.fetch(100) # get new flyers flyer_query = Flyer.all() flyer_query.filter("created_at >", yesterday) new_flyers = flyer_query.fetch(50) # get new EmailToClub joint_query = EmailToClub.all() joint_query.filter("created_at >", yesterday) new_joints = joint_query.fetch(100) # and get the newly disabled links joint_query = EmailToClub.all() joint_query.filter("updated_at >", yesterday) joint_query.filter("enable =", False) dead_joints = joint_query.fetch(100) if (not(new_clubs) and not(new_emails) and not(new_flyers) and not(new_joints)): self.response.out.write("Nothing to email") return # email sending pre-computation fromaddr = "noreply@%s.appspotmail.com" % get_application_id() date = time.strftime("%Y/%m/%d") # send the emails msg = mail.EmailMessage(sender = "Flyer Guy <%s>" % fromaddr, to = ADMIN_EMAIL) msg.subject = "[Flyer] Admin stats (%s)" % date msg.html = template.render("templates/email_stats.html", {"flyer_count": flyer_count, "clubs": new_clubs, "emails": new_emails, "flyers": new_flyers, "joints": new_joints, "dead_joints": dead_joints}) try: msg.send() except apiproxy_errors.OverQuotaError, (message,): # Log the error. logging.error("Could not send email") logging.error(message)
def get(self): jobs = Job.all().order("title").fetch(MAX_FETCH_LIMIT) job_list = [] for item in jobs: job_list.append(item.to_json_dict("title", "is_starred", "is_active", "is_deleted", "when_created")) self.response.out.write(json.dumps(job_list))