Sfoglia il codice sorgente

Add a crontab to send mail in every sunday..

Mohidul Islam 4 anni fa
parent
commit
db7ad16c10

+ 12 - 4
analytics/background_job.py

@@ -2,16 +2,24 @@ import requests
 from django.conf import settings
 from gauth.models import Location
 from analytics.send_email import send_email
+from yelp.store_reviews import populate_reviews
+
+to = getattr(settings, 'ADMIN_MAINTEINER_EMAILS')
+host_url = getattr(settings, 'HOST_URI')
 
 
 def send_email_weekly_summary():
     # locations = Location.objects.all()
-    locations = Location.objects.filter(location_id='3511292162159714121')
+    locations = Location.objects.filter(location_id='14748677429039074158')
     for location in locations:
-        to = getattr(settings, 'ADMIN_MAINTEINER_EMAILS')
         to.append(location.recipient_email) if location.recipient_email else None
         subject = f"Weekly report for {location.care_name}."
-        url = f'http://127.0.0.1:8000/analytics/weekly-report/{location.location_id}'
+        url = f'{host_url}/analytics/weekly-report/{location.location_id}'
         message_body = requests.get(url).text
         message_body += '<br><p>Regards,</p><p>Byte Trek Team</p>'
-        send_email(to_list=to, subject=subject, message=message_body)
+        send_email(to_list=to, subject=subject, message=message_body)
+
+
+def background_task_7_days_interval():
+    populate_reviews()
+    send_email_weekly_summary()

+ 9 - 0
nohup.out

@@ -0,0 +1,9 @@
+Watching for file changes with StatReloader
+[21/Jun/2020 14:28:27] "GET / HTTP/1.1" 200 25623
+[21/Jun/2020 14:28:30] "GET /dashboard/ HTTP/1.1" 200 25623
+[21/Jun/2020 15:19:57] "GET / HTTP/1.1" 200 25623
+[21/Jun/2020 15:20:06] "GET /?page=2 HTTP/1.1" 200 13500
+[21/Jun/2020 15:20:09] "GET /dashboard/ HTTP/1.1" 200 25623
+[21/Jun/2020 16:10:30] "GET / HTTP/1.1" 200 25623
+[21/Jun/2020 16:10:36] "GET /dashboard/ HTTP/1.1" 200 25623
+[21/Jun/2020 16:41:10] "GET / HTTP/1.1" 200 25623

+ 2 - 2
review/background_job.py

@@ -76,13 +76,13 @@ def send_email_bad_reviews():
             if total_reviews > 1:
                 tt = f'are {total_reviews} bad reviews has'
             else:
-                tt = f'is a bad review has'
+                tt = f'is a bad review has '
             message += tt + f'been posted in {location.care_name}.</p>'
             for r in reviews:
                 # link = r.location.review_site_url + '?reviewId='+r.review_id
                 name = f'<p><b>Reviewer Name:</b> {r.reviewer_name}</p>'
                 rating = f'<p><b>Rating:</b> {str(r.star_rating)} star rating.</p>'
-                comment = f'<p><b>Comment: </b>{r.comment}</p><br>'
+                comment = f'<p><b>Comment: </b>{r.comment}</p>'
                 message += name + rating + comment
             message += '<p>Regards,</p><p>Byte Trek Team</p>'
 

+ 1 - 2
review/review_utils.py

@@ -77,7 +77,6 @@ def sync_all_review(loc_id):
     :param: loc_id -> Location id of a particular location
     :return: None -> It just update all reviews of this location and return nothing.
     '''
-    loc = Location.objects.get(pk=loc_id)
     next_page_token = ''
     headers = get_auth_header()
     while True:
@@ -89,7 +88,7 @@ def sync_all_review(loc_id):
         data = res.json()
         reviews = data['reviews']
         if len(reviews) != 0:
-            insert_review_into_database(reviews, loc)
+            insert_review_into_database(reviews, loc_id)
         next_page_token = data.get('nextPageToken')
         if next_page_token is None:
             break

+ 1 - 0
review_automation/settings/config.py

@@ -1,6 +1,7 @@
 # Cron-Jobs of the project
 CRONJOBS = [
     ('0 */6 * * *', 'review.background_job.background_task_6_hours_interval'),
+    ('0 0 * * SUN', 'analytics.background_job.background_task_7_days_interval'),
 ]
 
 

+ 1 - 1
yelp/store_reviews.py

@@ -18,4 +18,4 @@ def store_yelp_reviews(location, n_pages):
 def populate_reviews():
     locations = YelpLocation.objects.all()
     for yl in locations:
-        store_yelp_reviews(yl, 1)
+        store_yelp_reviews(yl, 1)