浏览代码

instant mail to er authority while a bad reviews has been posted

Mohidul Islam 5 年之前
父节点
当前提交
3724c0615f
共有 4 个文件被更改,包括 42 次插入17 次删除
  1. 36 0
      analytics/background_job.py
  2. 2 1
      analytics/utils.py
  3. 2 14
      review/background_job.py
  4. 2 2
      review_automation/settings.py

+ 36 - 0
analytics/background_job.py

@@ -0,0 +1,36 @@
+from django.utils import timezone
+from gauth.models import Location
+from review.models import Review
+from .send_email import send_email
+from review.review_utils import get_bad_reviews
+
+
+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>Links: </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 weekly_report(location_id):
+    now = timezone.now()
+    date = now - timezone.timedelta(days=7)
+    reviews = Review.objects.filter(location_id=location_id, create_time__gte=date)

+ 2 - 1
analytics/utils.py

@@ -27,7 +27,8 @@ def last_data(date, location_id):
 
 def get_review_count_by_month(location_id):
     now = timezone.now()
-    day = 31 - now.day
+    date = now.replace(day=1) - timezone.timedelta(days=1)
+    day = date.day - now.day
     first_day_month = now - timezone.timedelta(days=now.day)
     this_month = last_data(first_day_month, location_id)
     sql = f'''

+ 2 - 14
review/background_job.py

@@ -1,12 +1,11 @@
 import random
 from time import sleep
 from django.utils import timezone
-from gauth.models import Location
 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, get_bad_reviews
-from analytics.send_email import send_email
+from analytics.background_job import send_email_bad_reviews
 
 from nameparser import HumanName
 
@@ -58,19 +57,8 @@ 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 = "A bad review has been post."
-            message = f"hi there is {total_reviews} bad review in {location.care_name} please response to reviewer ASAP"
-            send_email(to_list=to, subject=subject, message=message)
-
-
 def background_task():
     populate_reviews()
+    send_email_bad_reviews()
     sleep(60 * random.randint(2, 5))
     reply_uncommented_reviews()

+ 2 - 2
review_automation/settings.py

@@ -148,9 +148,9 @@ EMAIL_USE_TLS = True
 
 EMAIL_HOST = 'smtp.gmail.com'
 
-EMAIL_HOST_USER = 'username@gmail.com'
+EMAIL_HOST_USER = 'your@mail.com'
 
 # Must generate specific password for your app in [gmail settings][1]
-EMAIL_HOST_PASSWORD = 'mys3cr3tp@ssw0rd'
+EMAIL_HOST_PASSWORD = 'y0ur$3cr3tp@$$'
 
 EMAIL_PORT = 587