Prechádzať zdrojové kódy

Remove some unnecessay codes

Mohidul Islam 5 rokov pred
rodič
commit
445737fbbf
2 zmenil súbory, kde vykonal 2 pridanie a 87 odobranie
  1. 1 86
      review/review_utils.py
  2. 1 1
      review_automation/settings.py

+ 1 - 86
review/review_utils.py

@@ -2,7 +2,6 @@ import json
 from requests import get, put
 from gauth.auth_utils import get_gmb_id, get_auth_header
 from gauth.location_utils import get_all_location_ids
-# from django.db.models import Max
 from .models import Review, Reply
 from gauth.models import Location
 
@@ -37,71 +36,6 @@ def reply_review(review, replied_text):
     return response
 
 
-# def get_max_date(loc_id):
-#     '''
-#     find the maximum date of any particular location. the latest date
-#     :param loc_id: Integer -> Globally unique ID for google my business locations.
-#     :return: DateTime Obj -> The latest reviews date of that location.
-#     '''
-#     # Function that takes a location id and return the latest updated review.
-#     largest = Review.objects.filter(location_id=loc_id).aggregate(Max('create_time'))['create_time__max']
-#     max_date = largest if largest else '1970-01-11 17:41:17.532740'
-#     return max_date
-
-
-# def filter_unrecorded_review_by_date(reviews, max_date):
-#     # A function that return only those reviews whose has larger value than
-#     # the max create_time value in review database.
-#     filtered_reviews = []
-#     for rev in reviews:
-#         if rev['createTime'] >= str(max_date):
-#             filtered_reviews.append(rev)
-#     return filtered_reviews
-
-
-# def insert_review_into_database(reviews, loc):
-#     '''
-#     Insert reviews to database.
-#     :param unrecorded_reviews: all reviews for location.
-#     :param loc: location that unrecorded_reviews belongs to.
-#     :return: It insert all reviews if it is not exits in database and return nothing.
-#     '''
-#     for review in reviews:
-#         review_id = review.get('reviewId')
-#         # Check the review already exists in database then We don't need to store again.
-#         rev = Review.objects.filter(pk=review_id).first()
-#         if rev:
-#             continue
-#         comment = review.get('comment')
-#         create_time = review.get('createTime')
-#         update_time = review.get('updateTime')
-#         star_rating = STAR_REVIEW_NUM[review.get('starRating')]
-#         reviewer = review.get('reviewer')
-#         reviewer_name = reviewer.get('displayName')
-#         reviewer_photo = reviewer.get('profilePhotoUrl')
-#         review_reply = review.get('reviewReply')
-#         # Check if it is already  replied.
-#         if review_reply:
-#             replied_text = review_reply.get('comment')
-#             create_time = review_reply.get('updateTime')
-#             reply = Reply.objects.create(replied_text=replied_text, create_time=create_time)
-#         else:
-#             reply = None
-
-#         review = Review(
-#             review_id=review_id,
-#             comment=comment,
-#             create_time=create_time,
-#             update_time=update_time,
-#             star_rating=star_rating,
-#             reviewer_name=reviewer_name,
-#             reviewer_photo=reviewer_photo,
-#             location=loc,
-#             reply=reply
-#         )
-#         review.save()
-
-
 def insert_review_into_database(reviews, loc_id):
     '''
     Insert reviews to database.
@@ -174,28 +108,9 @@ def update_location_data(loc_id, average_rating, total_reviews, total_reviews_db
     loc.save()
 
 
-# def fetch_all_review(loc_id):
-#     loc = Location.objects.get(pk=loc_id)
-#     max_date = get_max_date(loc_id)
-#     headers = get_auth_header()
-#     url = get_review_list_url(loc_id)
-#     res = get(url, headers=headers)
-#     if res.status_code == 401:
-#         return
-#     data = res.json()
-#     reviews = data['reviews']
-#     average_rating = data.get('averageRating')
-#     total_reviews = data.get('totalReviewCount')
-#     unrecorded_reviews = filter_unrecorded_review_by_date(reviews, max_date)
-#     if len(unrecorded_reviews) != 0:
-#         insert_review_into_database(unrecorded_reviews, loc)
-#     total_reviews_db = Review.objects.filter(location_id=loc_id).count()
-#     update_location_data(loc, average_rating, total_reviews, total_reviews_db)
-
-
 def fetch_last_20_reviews(loc_id):
     headers = get_auth_header()
-    url = get_review_list_url(loc_id)+'&pageSize=100'
+    url = get_review_list_url(loc_id)+'&pageSize=20'
     res = get(url, headers=headers)
     data = res.json()
     reviews = data['reviews']

+ 1 - 1
review_automation/settings.py

@@ -71,7 +71,7 @@ DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'review_automation',
-        'USER': 'root',
+        'USER': 'bytetrek',
         'PASSWORD': 'sad2002S1',
         'HOST': 'localhost',
         'PORT': '3306',