def run_test(): mobi_file = mailbot.get_file('http://archiveofourown.org/works/829218?view_adult=true') print mobi_file print "now testing MIME packing" mime = mailbot.pack_MIME(mail_to, 'http://archiveofourown.org/works/829218?view_adult=true') print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'now sending...' mailbot.send_mail(mime, mail_to) print 'done!'
def run_test(): mobi_file = mailbot.get_file( 'http://archiveofourown.org/works/829218?view_adult=true') print mobi_file print "now testing MIME packing" mime = mailbot.pack_MIME( mail_to, 'http://archiveofourown.org/works/829218?view_adult=true') print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'now sending...' mailbot.send_mail(mime, mail_to) print 'done!'
def auto_ticket(request): #you thought you were going to break things by not having an e-mail? ha! if not request.user.email: return redirect('account/email') if request.method == 'POST': game = AutoCode() #!!! #let's talk about security sometime...(...later)(...never) up = UserProfile.objects.get(user = request.user) if 'ticket_random' in request.POST: if up.ticket_decrement(1): if not game.code_rand(request.user.email): #this wouldn't be necessary if I didn't do these 'function evaluates t/f' things up.ticket_increment(1) return HttpResponse('Oops<br>You have been refunded.') else: return HttpResponse('not enough tickets: '+str(up.ticket_count)) elif 'ticket_selection' in request.POST: gsf = GameSelectForm(request.POST) if gsf.is_valid(): if up.ticket_decrement(2): if not game.code_select(request.user.email, gsf.cleaned_data['gameselect'].id): up.ticket_increment(2) return HttpResponse('Oops<br>You have been refunded.') else: return HttpResponse('not enough tickets: '+str(up.ticket_count)) else: return HttpResponse('invalid choice') #TODO print game print str(game.code) attach_code = game subject = 'Here is your requested code!' if attach_code: url_get = game.get_url_get() url_return = game.get_url_return() #hahaha, oh wow what is this mess message = '<br>' + 'Here is a code for ' + str(game.game) +'.<br> To redeem it, go to '+url_get+'<br>If you would like to return it to us, go to '+url_return else: message = '<br>Unfortunately, we are out of codes for '+str(game.game) + '.' print message donation_mail = mailbot.pack_MIME(message, request.user.email, subject) mailbot.send_mail(donation_mail, request.user.email) diagnostic = str(game.game.id) return HttpResponse('Check your email for your gift of '+str(game.game)+ '<br>'+diagnostic) return HttpResponse('huh?')
def bid_form(request): if request.method == 'POST': bid_form = BidForm(request.POST) auction = Auction.objects.get(uuid = request.GET.get('auction_id')) #structural validation if bid_form.is_valid(): #logical validation if not bid_form.is_kosher(request.GET.get('auction_id')): return HttpResponse('your bid is no longer valid, try again') bid_id = bid_form.save_bid(request.GET.get('auction_id')) #mail time! I should stop using this #one of these days, google is going to completely deprecate this #laaaaazy message = "Hey " + unicode(bid_form.cleaned_data['name']) + ",<p>You've submitted a bid for " + unicode(auction.item_name) + " for the amount of " + unicode(bid_form.cleaned_data['amount']) + ".<p>Your bid page can be found <a href='" + unicode(LAZY_TLD) +"/silent_auction/bid/" + unicode(bid_id) + "'>here</a>.<p>Thanks for bidding and good luck!" mail = mailbot.pack_MIME(message, bid_form.cleaned_data['email'], 'Your bid for ' + unicode(auction.item_name)) print mail mailbot.send_mail(mail, bid_form.cleaned_data['email']) return redirect('/silent_auction/bid/' + unicode(bid_id)) else: return HttpResponse('your bid is structurally <i>wrong</i>, somehow') else: auction_id = request.GET.get('auction_id') if auction_id == None: return redirect('/silent_auction/') auction = get_object_or_404(Auction.objects.filter(uuid = auction_id)) #auto fill if logged in, saving precious seconds! if request.user.is_authenticated(): form = BidForm(initial = { 'amount': auction.top_bid + 1, 'name' : request.user.username, 'email' : request.user.email, }) else: form = BidForm(initial = { 'amount': auction.top_bid + 1, }) context = { 'form' : form, 'auction' : auction, 'auction_id' : auction_id, } return render(request, 'silent_auction/bid_form.html', context)
def handle(self, *args, **options): my_settings = Settings.objects.all()[0] queryset = Code.objects.filter(uuid_assigned = True).exclude(uuid_claimed = True) print datetime.datetime.utcnow() for code in queryset: if code.uuid_expired.replace(tzinfo = None) > datetime.datetime.utcnow() and code.uuid_expired.replace(tzinfo = None)- datetime.timedelta(1) < datetime.datetime.utcnow(): print 'warning issued for ' + str(code) message = 'Your code for ' + str(code.game.game) + ' is expiring in one day.<br> Go to ' + my_settings.global_url + 'get?code='+code.uuid +' to redeem it.' mailbot.send_mail(mailbot.pack_MIME(message, code.assigned, 'Your code is expiring'), code.assigned) if code.uuid_expired.replace(tzinfo = None) < datetime.datetime.utcnow(): print 'resetting ' + str(code) code.uuid_reset() code.game.update_count() print '~~~~~'
def auto_donate(request): #you thought you were going to break things by not having an e-mail? ha! if not request.user.email: return redirect('account/email') if request.method == 'POST': #TODO: game selection not necessarily hardcoded game_id = DONATION_GIVEAWAY_ID #TODO: donation message based on real donation info #I don't actually have systems for that. This isn't a real marathon site! donation = 'Thank you for your donation of ' + str(random.randint(2,100)) + ' ' + random.choice(['US Dollars', 'Bahraini Dinars', 'Icelandic Krona', 'Pakistani Rupees', 'Qatari Rial','Tanzanian Shillings','South Korean Won','Colombian Pesos','Estonian Kroon']) +'.' game = AutoCode() print game attach_code = game.code_select(request.user.email, game_id) subject = 'Thank you for "donating"' if attach_code: url_get = game.get_url_get() url_return = game.get_url_return() #hahaha, oh wow what is this mess message = donation + '<br>' + 'Here is a code for ' + str(game.game) +'.<br> To redeem it, go to '+url_get+'<br>If you would like to return it to us, go to '+url_return + '<br>This link will expire in 7 days, so don\'t forget to redeem it!' else: message = donation + '<br>Unfortunately, we are out of codes for '+str(game.game) + '.' print message donation_mail = mailbot.pack_MIME(message, request.user.email, subject) mailbot.send_mail(donation_mail, request.user.email) update_ticket = UserProfile.objects.get(user = request.user) update_ticket.ticket_increment(1) if update_ticket.donation_update(): print 'yes' context = { 'donation': donation, 'game' : game.game, } return render(request, 'dispenser/auto_donate.html', context) else: return redirect('/dispenser/auto')