|
@@ -1,11 +1,12 @@
|
|
|
import random
|
|
|
from time import sleep
|
|
|
from django.utils import timezone
|
|
|
+from gauth.models import Location
|
|
|
+from analytics.send_email import send_email
|
|
|
from .models import Review, CustomReply, Reply
|
|
|
from nlu_job.nlu_utils import is_a_name
|
|
|
from review.review_utils import reply_review
|
|
|
-from review.review_utils import populate_reviews
|
|
|
-from analytics.background_job import send_email_bad_reviews
|
|
|
+from review.review_utils import populate_reviews, get_bad_reviews
|
|
|
|
|
|
from nameparser import HumanName
|
|
|
|
|
@@ -57,6 +58,31 @@ def reply_uncommented_reviews():
|
|
|
sleep(60*random.randint(2, 5))
|
|
|
|
|
|
|
|
|
+def send_email_bad_reviews():
|
|
|
+ locations = Location.objects.all()
|
|
|
+ for location in locations:
|
|
|
+ reviews = get_bad_reviews(location.location_id, hours=6)
|
|
|
+ total_reviews = reviews.count()
|
|
|
+ if total_reviews > 0:
|
|
|
+ to = [location.recipient_email if location.recipient_email else 'bt@bytetrek.com.bd']
|
|
|
+ subject = f"A bad review has been post in {location.care_name}."
|
|
|
+ message =f'''
|
|
|
+ <img src="https://ercare24.com/wp-content/uploads/2016/07/signature-care-resized-e1462918690585.png" alt="Avatar" class="image" width=20% >
|
|
|
+ <h1>Bad Review has been posted.</h1>
|
|
|
+ <p>Hi there, </p>
|
|
|
+ <p>There is {total_reviews} bad reviews has been posted in {location.care_name}.
|
|
|
+ Please, response them ASAP.</p>
|
|
|
+ <h4>Follow those Links to respond: </h4>
|
|
|
+ '''
|
|
|
+ for r in reviews:
|
|
|
+ link = r.location.review_site_url + '?reviewId='+r.review_id
|
|
|
+ text = str(r.star_rating) + ' star review'
|
|
|
+ message += f'<a href="{link}">{text}</a><br>'
|
|
|
+ message += '<p>Regards,</p><p>Byte Trek Limited</p>'
|
|
|
+
|
|
|
+ send_email(to_list=to, subject=subject, message=message)
|
|
|
+
|
|
|
+
|
|
|
def background_task_6_hours_interval():
|
|
|
populate_reviews()
|
|
|
send_email_bad_reviews()
|