|
@@ -1,10 +1,11 @@
|
|
|
import requests
|
|
|
+import json
|
|
|
from .models import FacebookPage, FacebookReview, FacebookReviewReply
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
# browser instance
|
|
|
-browser = getattr(settings, 'BROWSER', None)
|
|
|
+browser_uri = getattr(settings, 'BROWSER_URI', None)
|
|
|
|
|
|
BASE_URL = 'https://graph.facebook.com'
|
|
|
|
|
@@ -97,37 +98,12 @@ def populate_facebook_reviews():
|
|
|
store_reviews_into_db(page_id=page_id.get('id'), n_reviews=15)
|
|
|
|
|
|
|
|
|
-def reply2facebook_review(review_id, reply, like=False, love=False):
|
|
|
- # switch to mobile view which not support any JavaScript
|
|
|
- base_url = 'https://mbasic.facebook.com/'
|
|
|
- url = base_url + str(review_id)
|
|
|
- browser.get(url)
|
|
|
-
|
|
|
- # like the review if needed
|
|
|
- if like:
|
|
|
- like_btn = browser.find_element_by_xpath(
|
|
|
- '/html/body/div/div/div[2]/div/div[1]/div[2]/div/div[1]/table/tbody/tr/td[1]/a')
|
|
|
- assert like_btn.text == 'Like'
|
|
|
- like_btn.click()
|
|
|
-
|
|
|
- # love the review if needed
|
|
|
- if love:
|
|
|
- react_btn = browser.find_element_by_xpath(
|
|
|
- '/html/body/div/div/div[2]/div/div[1]/div[2]/div/div[1]/table/tbody/tr/td[2]/a')
|
|
|
- assert react_btn.text == 'React'
|
|
|
- react_btn.click()
|
|
|
- love_btn = browser.find_element_by_xpath(
|
|
|
- '/html/body/div/div/div[2]/div/table/tbody/tr/td/ul/li[2]/table/tbody/tr/td/a/div/table/tbody/tr/td[2]')
|
|
|
- assert love_btn.text == 'Love'
|
|
|
- love_btn.click()
|
|
|
-
|
|
|
- # reply the review
|
|
|
- reply_field = browser.find_element_by_id('composerInput')
|
|
|
- assert reply_field.get_attribute('name') == 'comment_text'
|
|
|
- reply_field.send_keys(reply)
|
|
|
- ins = browser.find_elements_by_tag_name('input')
|
|
|
- for x in ins:
|
|
|
- if 'omment' in x.get_attribute('value'):
|
|
|
- x.click()
|
|
|
- break
|
|
|
-
|
|
|
+def reply2facebook_review(review_id, reply):
|
|
|
+ url = browser_uri + f'/facebook/reply'
|
|
|
+ payload = {
|
|
|
+ 'id': review_id,
|
|
|
+ 'reply': reply
|
|
|
+ }
|
|
|
+ headers = {'content-type': 'application/json'}
|
|
|
+ response = requests.post(url, data=json.dumps(payload), headers=headers)
|
|
|
+ return response.status_code
|