239 lines
6.3 KiB
Plaintext
239 lines
6.3 KiB
Plaintext
{
|
|
"metadata": {
|
|
"name": "",
|
|
"signature": "sha256:119083da302750be98f1c8ed76602a0fee361ec43f5dc3d6a88d949b2afdbcd4"
|
|
},
|
|
"nbformat": 3,
|
|
"nbformat_minor": 0,
|
|
"worksheets": [
|
|
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "heading",
|
|
"level": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"Logic of notification send dates"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"https://github.com/Gluejar/regluit/blob/ea5adba871ac3448d8cf3d01c632041739a5ac8f/core/tasks.py#L190\n",
|
|
"\n",
|
|
"\n",
|
|
"````Python\n",
|
|
" unclaimed = Gift.objects.filter(used=None)\n",
|
|
" for gift in unclaimed:\n",
|
|
" \"\"\"\n",
|
|
" send notice every 7 days\n",
|
|
" \"\"\"\n",
|
|
" unclaimed_duration = (now() - gift.acq.created ).days\n",
|
|
" if unclaimed_duration > 0 and unclaimed_duration % 7 == 0 : # first notice in 7 days\n",
|
|
" notification.send_now([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n",
|
|
" notification.send_now([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)\n",
|
|
"````"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"from regluit.core.models import Gift\n",
|
|
"\n",
|
|
"unclaimed = Gift.objects.filter(used=None)\n",
|
|
"\n",
|
|
"def to_send(now_):\n",
|
|
"\n",
|
|
" for gift in unclaimed:\n",
|
|
" \"\"\"\n",
|
|
" send notice every 7 days\n",
|
|
" \"\"\"\n",
|
|
" unclaimed_duration = (now_ - gift.acq.created ).days\n",
|
|
" if unclaimed_duration > 0 and unclaimed_duration % 7 == 0 : # first notice in 7 days\n",
|
|
" print (\"send notice\", now_, gift.acq.created, now_-gift.acq.created, gift.acq.user, gift.giver )\n",
|
|
"# notification.send_now([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n",
|
|
"# notification.send_now([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"prompt_number": 12
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"[gift.acq.created for gift in unclaimed]"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"import time, datetime\n",
|
|
"structTime = list(time.localtime())\n",
|
|
"# replace time with 2:15am\n",
|
|
"structTime[3:6] = [2, 15, 0]\n",
|
|
"now_ = datetime.datetime(*structTime[:7])\n",
|
|
"\n",
|
|
"for k in range(10):\n",
|
|
" date_ = now_ + datetime.timedelta(days=k)\n",
|
|
" to_send(date_)\n"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "heading",
|
|
"level": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"Testing by futzing with gifts (instead of creating them de novo)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"To where is the emails of senders / recipients attached?\n",
|
|
"\n",
|
|
"\n",
|
|
" notification.send_now([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n",
|
|
" notification.send_now([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"gift = unclaimed[0]\n",
|
|
"\n",
|
|
"# is there where email going to?\n",
|
|
"\n",
|
|
"for gift in unclaimed:\n",
|
|
" print (gift.giver, gift.acq.user)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"from django.contrib.auth.models import User\n",
|
|
"\n",
|
|
"ry_gmail = User.objects.get(email=\"raymond.yee@gmail.com\")\n",
|
|
"ry_gluejar = User.objects.get(email=\"rdhyee@gluejar.com\")"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"# replace gift.user -> ry_gmail\n",
|
|
"# replace gift.acq.user -> ry_gluejar\n",
|
|
"\n",
|
|
"for gift in unclaimed:\n",
|
|
" gift.giver = ry_gmail\n",
|
|
" gift.user = ry_gmail\n",
|
|
" gift.save()\n",
|
|
" gift.acq.user = ry_gluejar\n",
|
|
" gift.acq.save()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"# now mess with date of acq and fire off notices\n",
|
|
"\n",
|
|
"from regluit.core import tasks\n",
|
|
"tasks.notify_unclaimed_gifts"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"from regluit.utils.localdatetime import now\n",
|
|
"now()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"# let's set things so none of the acq dates fall on week boundaries so no messages get sent\n",
|
|
"import datetime\n",
|
|
"non_action_dt = now() - datetime.timedelta(days=5)\n",
|
|
"\n",
|
|
"for gift in unclaimed:\n",
|
|
" gift.acq.created = non_action_dt\n",
|
|
" gift.acq.save()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"# should not be any notices fired\n",
|
|
"tasks.notify_unclaimed_gifts()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"prompt_number": 13
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"# now set the first gift to fire\n",
|
|
"\n",
|
|
"action_dt = now() - datetime.timedelta(days=7)\n",
|
|
"gift0 = unclaimed[0]\n",
|
|
"gift0.acq.created = action_dt\n",
|
|
"gift0.acq.save()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"# should be notices\n",
|
|
"tasks.notify_unclaimed_gifts()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": []
|
|
}
|
|
],
|
|
"metadata": {}
|
|
}
|
|
]
|
|
} |