1.3.2 send_mail_for_user_subscribes_that_is_going_to_finish
This commit is contained in:
48
GeneralApp/management/commands/every_1hour_start.py
Normal file
48
GeneralApp/management/commands/every_1hour_start.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from datetime import datetime
|
||||
from BaseModels.mailSender import techSendMail
|
||||
from ...funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
mail_sets = get_mail_send_options()
|
||||
|
||||
log = ''
|
||||
log_begin_DT = datetime.now()
|
||||
msg = str(log_begin_DT)
|
||||
print('-------------')
|
||||
print(msg)
|
||||
|
||||
try:
|
||||
from RoutesApp.search_matches import search_matches
|
||||
msg = search_matches()
|
||||
if msg:
|
||||
print(msg)
|
||||
log += f'\n{msg}'
|
||||
except Exception as e:
|
||||
msg = f'every_1hour_start search_matches fail = {str(e)}'
|
||||
print(msg)
|
||||
techSendMail(mail_sets, msg, title='every_1hour_start search_matches')
|
||||
|
||||
|
||||
if datetime.now().hour == 19:
|
||||
try:
|
||||
from SubscribesApp.reports import send_mail_for_user_subscribes_that_is_going_to_finish
|
||||
msg = send_mail_for_user_subscribes_that_is_going_to_finish()
|
||||
if msg:
|
||||
print(msg)
|
||||
log += f'\n{msg}'
|
||||
except Exception as e:
|
||||
msg = f'send_mail_for_user_subscribes_that_is_going_to_finish search_matches fail = {str(e)}'
|
||||
print(msg)
|
||||
techSendMail(mail_sets, msg, title='every_1hour_start send_mail_for_user_subscribes_that_is_going_to_finish')
|
||||
|
||||
if log:
|
||||
techSendMail(mail_sets, str(msg), title='every_1hour_start get_competitors_prices')
|
||||
|
||||
|
||||
|
||||
print(f'- processing time = {str(datetime.now() - log_begin_DT)} -')
|
||||
|
||||
|
||||
@@ -22,65 +22,9 @@ def test_code(request):
|
||||
|
||||
res = None
|
||||
|
||||
# import allauth
|
||||
# from allauth.socialaccount.models import SocialApp
|
||||
# apps = SocialApp.objects.all()
|
||||
# apps.delete()
|
||||
from SubscribesApp.reports import send_mail_for_user_subscribes_that_is_going_to_finish
|
||||
send_mail_for_user_subscribes_that_is_going_to_finish()
|
||||
|
||||
# from PushMessages.views import send_push
|
||||
# send_push(request.user, 'test_title', 'test_content')
|
||||
|
||||
# from BaseModels.pay_systems.DVL_Group_kaz.api.funcs import create_order
|
||||
# create_order()
|
||||
|
||||
# from AuthApp.models import User
|
||||
# from SubscribesApp.models import SubscribeForUser, Subscribe
|
||||
# subscribes_null_price = Subscribe.objects.filter(price=0)
|
||||
# if not subscribes_null_price:
|
||||
# res = 'Subscribe not found'
|
||||
# else:
|
||||
# subscribe = subscribes_null_price[0]
|
||||
# users_wo_subscribe = User.objects.filter(rel_userSubscribes_for_user=None)
|
||||
# for user in users_wo_subscribe:
|
||||
# u_sub = SubscribeForUser.objects.create(
|
||||
# user=user,
|
||||
# subscribe=subscribe,
|
||||
# paid_period_from_DT=datetime.now(),
|
||||
# paid_period_to_DT=datetime.now() + timedelta(hours=subscribe.period)
|
||||
# )
|
||||
|
||||
# from RoutesApp.search_matches import search_matches
|
||||
# search_matches()
|
||||
|
||||
# try:
|
||||
# # body = request.body
|
||||
# # data = json.loads(body)
|
||||
# # if 'head' not in data or 'body' not in data or 'id' not in data:
|
||||
# # return JsonResponse(status=400, data={"message": "Invalid data format"})
|
||||
# # user_id = data['id']
|
||||
# user = request.user
|
||||
# payload = {'head': '123', 'body': 'qwerty'}
|
||||
# send_user_notification(user=user, payload=payload, ttl=1000)
|
||||
# return JsonResponse(status=200, data={"message": "Web push successful"})
|
||||
# except TypeError:
|
||||
# return JsonResponse(status=500, data={"message": "An error occurred"})
|
||||
|
||||
# routes = Route.objects.all()
|
||||
#
|
||||
# for route in routes:
|
||||
# print(route.id)
|
||||
# required_save = False
|
||||
# if not route.from_city:
|
||||
# route.from_city = get_city_by_type_transport_and_address_point(route.type_transport, route.from_address_point)
|
||||
# required_save = True
|
||||
#
|
||||
# if not route.to_city:
|
||||
# route.to_city = get_city_by_type_transport_and_address_point(route.type_transport,
|
||||
# route.to_address_point)
|
||||
# required_save = True
|
||||
#
|
||||
# if required_save:
|
||||
# route.save()
|
||||
if res:
|
||||
if type(res) == str:
|
||||
return HttpResponse(res)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from datetime import datetime
|
||||
from BaseModels.mailSender import techSendMail
|
||||
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
mail_sets = get_mail_send_options()
|
||||
|
||||
log = ''
|
||||
log_begin_DT = datetime.now()
|
||||
msg = str(log_begin_DT)
|
||||
print('-------------')
|
||||
print(msg)
|
||||
|
||||
try:
|
||||
from ...search_matches import search_matches
|
||||
msg = search_matches()
|
||||
if msg:
|
||||
print(msg)
|
||||
except Exception as e:
|
||||
msg = f'every_1hour_start search_matches fail = {str(e)}'
|
||||
print(msg)
|
||||
techSendMail(mail_sets, msg, title='every_1hour_start search_matches')
|
||||
|
||||
|
||||
|
||||
if msg:
|
||||
techSendMail(mail_sets, str(msg), title='every_1hour_start get_competitors_prices')
|
||||
|
||||
|
||||
|
||||
print(f'- processing time = {str(datetime.now() - log_begin_DT)} -')
|
||||
|
||||
|
||||
@@ -5,6 +5,17 @@ from datetime import datetime, timedelta
|
||||
import json
|
||||
|
||||
|
||||
def get_user_subscribes_that_is_going_to_finish():
|
||||
user_subscribes = SubscribeForUser.objects.filter(
|
||||
enable=True,
|
||||
subscribe__price__gt=0,
|
||||
paid_period_to_DT__lt=datetime.now() + timedelta(days=3),
|
||||
paid_period_to_DT__gt=datetime.now()
|
||||
)
|
||||
|
||||
return user_subscribes
|
||||
|
||||
|
||||
def extension_free_subscribes():
|
||||
subscribe = get_null_price_subscribe()
|
||||
if not subscribe:
|
||||
|
||||
49
SubscribesApp/reports.py
Normal file
49
SubscribesApp/reports.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from .models import *
|
||||
from datetime import datetime, timedelta
|
||||
from .funcs import *
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
def send_mail_for_user_subscribes_that_is_going_to_finish():
|
||||
|
||||
log = ''
|
||||
|
||||
user_subscribes = get_user_subscribes_that_is_going_to_finish()
|
||||
|
||||
for user_subscribe in user_subscribes:
|
||||
try:
|
||||
|
||||
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||
sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True)
|
||||
|
||||
subject = _('tripwb.com - Уведомление о скором окончании срока подписки')
|
||||
|
||||
Dict = {
|
||||
'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg',
|
||||
'project_name': sets['project_name'],
|
||||
'message_title': subject,
|
||||
'user_subscribe': user_subscribe
|
||||
}
|
||||
|
||||
html = render_to_string('mail/m_user_subscribes_that_is_going_to_finish.html', Dict)
|
||||
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
|
||||
mail_sets = get_mail_send_options()
|
||||
to = [user_subscribe.user.email, 'web@syncsystems.net', 'sa@a3-global.com', 'sysadmin.hax@gmail.com']
|
||||
res = admin_send_mail_by_SMTPlib(
|
||||
mail_sets,
|
||||
subject=subject,
|
||||
from_email=mail_sets['sender_email'], to=to,
|
||||
html_content=html
|
||||
)
|
||||
if res and type(res) == str:
|
||||
print(res)
|
||||
# log += f'\n{res}'
|
||||
|
||||
|
||||
except Exception as e:
|
||||
msg = (f'send_mail_for_user_subscribes_that_is_going_to_finish '
|
||||
f'for user {user_subscribe.user} '
|
||||
f'Exception = {str(e)}')
|
||||
print(msg)
|
||||
log += f'\n{msg}'
|
||||
|
||||
return log
|
||||
@@ -0,0 +1,78 @@
|
||||
{% load i18n %}
|
||||
|
||||
<div style="font-family:Calibri,Candara,Segoe,'Segoe UI',Optima,Arial,sans-serif;
|
||||
padding:10px; background-color: #F8F8F8;">
|
||||
<div style="line-height:1.0em; width: 660px">
|
||||
<div style="padding:5px; text-align: center;">
|
||||
<img src="{{ logo }}" alt="{{ project_name }}" style="margin:0;padding:0;">
|
||||
</div>
|
||||
|
||||
<p style="font-weight:700; font-size:25px; text-align:center;
|
||||
padding:0; line-height:1em; text-transform: uppercase; color: #ff613a;
|
||||
margin: auto; max-width: 90%;
|
||||
">
|
||||
{% translate 'Уважаемый' %}, {{ user_subscribe.user }}!
|
||||
</p>
|
||||
<div style="line-height:1.0em; font-size:18px; margin: 5px 30px;
|
||||
box-shadow: -1px 4px 10px 0 rgba(198, 199, 203, 0.20), 0 -1px 10px 0 rgba(198, 199, 203, 0.20);
|
||||
padding: 30px; border-radius: 10px; background-color: #FFF;">
|
||||
<p>{% translate 'Ваша подписка на сайте' %} <a href="{{ domain }}/">TripWithBonus</a> истекает {{ user_subscribe.paid_period_to_DT|date }}</p>
|
||||
<p>{% translate 'Вы можете продлить подписку через свой личный кабинет. Пройдите по ссылке ниже для входа на сайт.' %}</p>
|
||||
<p><b><a href="{{ domain }}/profile/page/my_subscribe/">Моя подписка на TripWithBonus</a></b></p>
|
||||
<p>
|
||||
{% translate 'Спасибо за то, что вы с нами!' %}<br>
|
||||
{% translate 'С уважением,' %}<br>
|
||||
{% translate 'Команда Trip With Bonus.' %}<br>
|
||||
</p>
|
||||
</div>
|
||||
{% for button in message_buttons %}
|
||||
<div style="text-align:center;font-weight: 700;">
|
||||
<a href="{{ button.url }}">
|
||||
<div style="display:inline-block;text-align:center;font-size:18px;padding:5px 10px;margin:5px;border-radius:2px;background-color:#61aeb6;color:#fff;text-decoration:none;line-height:1.0em;cursor:pointer">
|
||||
{{ button.caption }}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{# <div style="text-align:center;width: 660px;line-height:1.1em">#}
|
||||
{# <div style="margin: 40px 10px 10px;">#}
|
||||
{# <hr>#}
|
||||
{# <nobr><b>Адрес:</b></nobr>#}
|
||||
{# <br>#}
|
||||
{# <nobr><b>График работы:</b> пн-вс 12:00 - 24:00</nobr>#}
|
||||
{# <br>#}
|
||||
{# <nobr><b>Телефоны:</b></nobr>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# <div style="text-align: center;margin-top:5px">#}
|
||||
{# <a href="" style="text-decoration: none;">#}
|
||||
{# <div style="color: #311A12;#}
|
||||
{# padding: 10px;#}
|
||||
{# margin: 5px 10px 0 10px;#}
|
||||
{# border: 2px solid #311A12;#}
|
||||
{# border-radius: 5px;#}
|
||||
{# font-size: 20px;#}
|
||||
{# display: inline-block;#}
|
||||
{# font-weight: 700;#}
|
||||
{# text-transform: uppercase;">О ДОСТАВКЕ#}
|
||||
{# </div>#}
|
||||
{# </a>#}
|
||||
{# <a href="" style="text-decoration: none;">#}
|
||||
{# <div style="color: #311A12;#}
|
||||
{# padding: 10px;#}
|
||||
{# margin: 5px 10px 0 10px;#}
|
||||
{# border: 2px solid #311A12;#}
|
||||
{# border-radius: 5px;#}
|
||||
{# font-size: 20px;#}
|
||||
{# display: inline-block;#}
|
||||
{# font-weight: 700;#}
|
||||
{# text-transform: uppercase;">О#}
|
||||
{# </div>#}
|
||||
{# </a>#}
|
||||
{# </div>#}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user