|
|
@@ -1,41 +1,44 @@
|
|
|
-import os
|
|
|
import collections
|
|
|
|
|
|
import splinter
|
|
|
import selenium.common.exceptions
|
|
|
|
|
|
import util
|
|
|
+import config
|
|
|
|
|
|
-_USER_EMAIL = os.environ['FB_USER']
|
|
|
-_USER_PASS = os.environ['FB_PASS']
|
|
|
+def remove_items(client, initial_values, secondary_values, confirm_button=None):
|
|
|
+
|
|
|
+ if not isinstance(initial_values, list):
|
|
|
+ initial_values = [initial_values]
|
|
|
+ if not isinstance(secondary_values, list):
|
|
|
+ secondary_values = [secondary_values]
|
|
|
|
|
|
-def remove_items(b, value1, value2, confirm_button=None):
|
|
|
removed = 0
|
|
|
|
|
|
while True:
|
|
|
- b.b.reload()
|
|
|
+ client.b.reload()
|
|
|
|
|
|
element_ids = None
|
|
|
for _ in range(60):
|
|
|
util.sleep(2, 0)
|
|
|
- element_ids = util.get_tag_ids(b.b.html, 'data-tooltip-content="%s"' % value1)
|
|
|
+ element_ids = util.get_tag_ids(client.b.html, ['data-tooltip-content="%s"' % v for v in initial_values])
|
|
|
if element_ids:
|
|
|
break
|
|
|
else:
|
|
|
- b.scroll_y(200)
|
|
|
+ client.scroll_y(200)
|
|
|
|
|
|
if not element_ids:
|
|
|
print 'All done.'
|
|
|
return
|
|
|
|
|
|
util.sleep(2, 0)
|
|
|
- element_ids = util.get_tag_ids(b.b.html, 'data-tooltip-content="%s"' % value1)
|
|
|
+ element_ids = util.get_tag_ids(client.b.html, ['data-tooltip-content="%s"' % v for v in initial_values])
|
|
|
|
|
|
done = set()
|
|
|
while element_ids:
|
|
|
eid = element_ids[0]
|
|
|
element_ids = None
|
|
|
- e = b.b.find_by_id(eid)
|
|
|
+ e = client.b.find_by_id(eid)
|
|
|
done.add(eid)
|
|
|
|
|
|
if e:
|
|
|
@@ -43,10 +46,12 @@ def remove_items(b, value1, value2, confirm_button=None):
|
|
|
e.mouse_over()
|
|
|
util.sleep(0, 0.2)
|
|
|
e.click()
|
|
|
+
|
|
|
+ util.sleep(0.1, 0.1)
|
|
|
|
|
|
- unlike_ids = util.filter_by_value(b.b.find_by_tag('a'), value2)
|
|
|
+ unlike_ids = util.filter_by_value(client.b.find_by_tag('a'), secondary_values)
|
|
|
if len(unlike_ids) != 1:
|
|
|
- raise Exception('Could not find a single "%s" button (found %i).' % (value2, len(unlike_ids)))
|
|
|
+ raise Exception('Could not find a single %s button (found %i).' % (secondary_values, len(unlike_ids)))
|
|
|
|
|
|
e = unlike_ids[0]
|
|
|
util.sleep(0, 0.2)
|
|
|
@@ -57,7 +62,7 @@ def remove_items(b, value1, value2, confirm_button=None):
|
|
|
if confirm_button:
|
|
|
util.sleep(1, 1)
|
|
|
|
|
|
- buttons = b.b.find_by_tag('button')
|
|
|
+ buttons = client.b.find_by_tag('button')
|
|
|
buttons = [button for button in buttons if button.has_class('layerConfirm')]
|
|
|
|
|
|
if len(buttons) != 1:
|
|
|
@@ -67,7 +72,7 @@ def remove_items(b, value1, value2, confirm_button=None):
|
|
|
util.sleep(0.1, 0.2)
|
|
|
buttons[0].click()
|
|
|
|
|
|
- while b.b.is_text_present(confirm_button):
|
|
|
+ while client.b.is_text_present(confirm_button):
|
|
|
print 'Waiting for confirm button to disappear...'
|
|
|
|
|
|
util.sleep(0.5, 0)
|
|
|
@@ -77,25 +82,25 @@ def remove_items(b, value1, value2, confirm_button=None):
|
|
|
|
|
|
util.sleep(4, 1)
|
|
|
|
|
|
- element_ids = util.get_tag_ids(b.b.html, 'data-tooltip-content="%s"' % value1)
|
|
|
+ element_ids = util.get_tag_ids(client.b.html, ['data-tooltip-content="%s"' % v for v in initial_values])
|
|
|
element_ids = [x for x in element_ids if x not in done]
|
|
|
|
|
|
except selenium.common.exceptions.StaleElementReferenceException, e:
|
|
|
print 'StaleElementReferenceException; reloading elements.'
|
|
|
- element_ids = util.get_tag_ids(b.b.html, 'data-tooltip-content="%s"' % value1)
|
|
|
+ element_ids = util.get_tag_ids(client.b.html, ['data-tooltip-content="%s"' % v for v in initial_values])
|
|
|
element_ids = [x for x in element_ids if x not in done]
|
|
|
except selenium.common.exceptions.ElementNotVisibleException, e:
|
|
|
print 'ElementNotVisibleException; scrolling, reloading elements.'
|
|
|
- b.scroll_y(500)
|
|
|
- util.sleep(1, 0)
|
|
|
- element_ids = util.get_tag_ids(b.b.html, 'data-tooltip-content="%s"' % value1)
|
|
|
+ client.scroll_y(500)
|
|
|
+ util.sleep(0.3, 0)
|
|
|
+ element_ids = util.get_tag_ids(client.b.html, ['data-tooltip-content="%s"' % v for v in initial_values])
|
|
|
element_ids = [x for x in element_ids if x not in done]
|
|
|
except selenium.common.exceptions.WebDriverException, e:
|
|
|
if 'Element is not clickable' in str(e):
|
|
|
print 'Not clickable: %s' % e
|
|
|
# b.scroll_y(300)
|
|
|
util.sleep(1, 0)
|
|
|
- element_ids = util.get_tag_ids(b.b.html, 'data-tooltip-content="%s"' % value1)
|
|
|
+ element_ids = util.get_tag_ids(client.b.html, ['data-tooltip-content="%s"' % v for v in initial_values])
|
|
|
element_ids = [x for x in element_ids if x not in done]
|
|
|
|
|
|
else:
|
|
|
@@ -106,13 +111,11 @@ def remove_items(b, value1, value2, confirm_button=None):
|
|
|
except Exception, e:
|
|
|
print str(e)
|
|
|
|
|
|
-
|
|
|
class FacebookBrowser(object):
|
|
|
- b = None
|
|
|
stats = collections.Counter()
|
|
|
|
|
|
- def __init__(self, driver='firefox'):
|
|
|
- self.b = splinter.Browser(driver)
|
|
|
+ def __init__(self):
|
|
|
+ self.b = splinter.Browser('chrome', executable_path=config.CHROME_PATH)
|
|
|
self.b.visit('https://facebook.com/login')
|
|
|
|
|
|
def remove_your_posts(self):
|
|
|
@@ -126,10 +129,10 @@ class FacebookBrowser(object):
|
|
|
util.sleep(0, 0.2)
|
|
|
es[0].click()
|
|
|
|
|
|
- self._remove_items(self.b, 'Allowed on Timeline', 'Delete', 'Delete Post')
|
|
|
+ remove_items(self, 'Allowed on Timeline', 'Delete', 'Delete Post')
|
|
|
|
|
|
def remove_likes(self):
|
|
|
- es = util.filter_by_value(self.b.find_by_tag('a'), 'Likes')
|
|
|
+ es = util.filter_by_value(self.b.find_by_tag('a'), 'Likes and Reactions')
|
|
|
|
|
|
if len(es) != 1:
|
|
|
print 'Could not find a single "Likes" button (found %i)' % len(es)
|
|
|
@@ -139,7 +142,7 @@ class FacebookBrowser(object):
|
|
|
util.sleep(0, 0.2)
|
|
|
es[0].click()
|
|
|
|
|
|
- self._remove_items('Edit', 'Unlike')
|
|
|
+ remove_items(self, 'Edit', ['Unlike', 'Remove Reaction'])
|
|
|
|
|
|
def remove_comments(self):
|
|
|
es = util.filter_by_value(self.b.find_by_tag('a'), 'Comments')
|
|
|
@@ -152,10 +155,7 @@ class FacebookBrowser(object):
|
|
|
util.sleep(0, 0.2)
|
|
|
es[0].click()
|
|
|
|
|
|
- self._remove_items('Edit', 'Delete')
|
|
|
-
|
|
|
- def _remove_items(self, value1, value2, confirm_button=None):
|
|
|
- return remove_items(self, value1, value2, confirm_button=None)
|
|
|
+ remove_items(self, 'Edit', 'Delete')
|
|
|
|
|
|
def scroll_y(self, pixels):
|
|
|
self.b.execute_script('window.scrollBy(0,%i);' % pixels)
|
|
|
@@ -187,7 +187,7 @@ class FacebookBrowser(object):
|
|
|
e.click()
|
|
|
|
|
|
util.sleep(1, 1)
|
|
|
- util.type(e, _USER_EMAIL)
|
|
|
+ util.type(e, config.USER_EMAIL)
|
|
|
|
|
|
e = self.b.find_by_id('pass')[0]
|
|
|
|
|
|
@@ -198,7 +198,7 @@ class FacebookBrowser(object):
|
|
|
e.click()
|
|
|
|
|
|
util.sleep(1, 1)
|
|
|
- util.type(e, _USER_PASS, delay=0.2)
|
|
|
+ util.type(e, config.USER_PASS, delay=0.2)
|
|
|
|
|
|
e = self.b.find_by_id('loginbutton')[0]
|
|
|
|