Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from time import sleep
|
|
| 6 |
from selenium.webdriver.chrome.options import Options
|
| 7 |
from selenium.webdriver.chrome.service import Service
|
| 8 |
from webdriver_manager.chrome import ChromeDriverManager
|
|
|
|
| 9 |
|
| 10 |
import setuptools
|
| 11 |
|
|
@@ -52,64 +53,55 @@ setuptools.setup(
|
|
| 52 |
)
|
| 53 |
|
| 54 |
def main():
|
| 55 |
-
|
| 56 |
-
st.title("Facebook Group Poster")
|
| 57 |
-
account = st.text_input("Facebook Account Email", "sample@gmail.com")
|
| 58 |
-
password = st.text_input("Facebook Password", "sample", type="password")
|
| 59 |
-
groups_links_list = st.text_area("Facebook Group URLs (one per line)",
|
| 60 |
-
"https://www.facebook.com/groups/sample1\nhttps://www.facebook.com/groups/sample2")
|
| 61 |
-
message = st.text_area("Post Message", "Checkout this amazing script...")
|
| 62 |
-
images_list = st.file_uploader("Upload Images", accept_multiple_files=True)
|
| 63 |
-
|
| 64 |
if st.button('Post to Facebook Groups'):
|
| 65 |
-
# Only execute if the button is clicked
|
| 66 |
if not account or not password or not groups_links_list or not message or not images_list:
|
| 67 |
st.error("Please fill all the fields.")
|
| 68 |
else:
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
|
|
|
|
|
|
|
|
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
# Login Facebook
|
| 74 |
-
chrome_options = Options() # Use the Options class
|
| 75 |
-
prefs = {"profile.default_content_setting_values.notifications" : 2}
|
| 76 |
-
chrome_options.add_experimental_option("prefs", prefs)
|
| 77 |
-
driver = webdriver.Chrome(options=chrome_options) # Pass 'options'
|
| 78 |
-
driver.get('https://www.facebook.com')
|
| 79 |
-
emailelement = driver.find_element(By.XPATH,'//*[@id="email"]')
|
| 80 |
-
emailelement.send_keys(account)
|
| 81 |
-
passelement = driver.find_element(By.XPATH,'//*[@id="pass"]')
|
| 82 |
-
passelement.send_keys(password)
|
| 83 |
-
loginelement = driver.find_element(By.XPATH,'//*[@id="loginbutton"]')
|
| 84 |
-
loginelement.click()
|
| 85 |
-
|
| 86 |
-
# Post on each group
|
| 87 |
-
for group in groups_links_list:
|
| 88 |
-
driver.get(group)
|
| 89 |
-
time.sleep(2)
|
| 90 |
-
try:
|
| 91 |
-
driver.find_element(By.XPATH,'//*[@label="Start Discussion"]').click()
|
| 92 |
-
post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
| 93 |
-
except:
|
| 94 |
-
post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
| 95 |
-
post_box.send_keys(message)
|
| 96 |
-
time.sleep(1)
|
| 97 |
-
for photo in images_list:
|
| 98 |
-
photo_element = driver.find_element(By.XPATH,'//input[@type="file"]')
|
| 99 |
-
photo_element.send_keys(photo)
|
| 100 |
time.sleep(1)
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
if __name__ == '__main__':
|
| 115 |
main()
|
|
|
|
| 6 |
from selenium.webdriver.chrome.options import Options
|
| 7 |
from selenium.webdriver.chrome.service import Service
|
| 8 |
from webdriver_manager.chrome import ChromeDriverManager
|
| 9 |
+
import streamlit as st
|
| 10 |
|
| 11 |
import setuptools
|
| 12 |
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
def main():
|
| 56 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if st.button('Post to Facebook Groups'):
|
|
|
|
| 58 |
if not account or not password or not groups_links_list or not message or not images_list:
|
| 59 |
st.error("Please fill all the fields.")
|
| 60 |
else:
|
| 61 |
+
chrome_options = Options()
|
| 62 |
+
prefs = {"profile.default_content_setting_values.notifications": 2}
|
| 63 |
+
chrome_options.add_experimental_option("prefs", prefs)
|
| 64 |
|
| 65 |
+
with st.spinner("Posting to Facebook..."):
|
| 66 |
+
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
|
| 67 |
+
driver.get('https://www.facebook.com')
|
| 68 |
|
| 69 |
+
emailelement = driver.find_element(By.XPATH,'//*[@id="email"]')
|
| 70 |
+
emailelement.send_keys(account)
|
| 71 |
+
passelement = driver.find_element(By.XPATH,'//*[@id="pass"]')
|
| 72 |
+
passelement.send_keys(password)
|
| 73 |
+
loginelement = driver.find_element(By.XPATH,'//*[@id="loginbutton"]')
|
| 74 |
+
loginelement.click()
|
| 75 |
+
|
| 76 |
+
groups_links = groups_links_list.splitlines() # Split into list of URLs
|
| 77 |
+
|
| 78 |
+
for group in groups_links:
|
| 79 |
+
driver.get(group)
|
| 80 |
+
time.sleep(2)
|
| 81 |
+
|
| 82 |
+
try:
|
| 83 |
+
driver.find_element(By.XPATH,'//*[@label="Start Discussion"]').click()
|
| 84 |
+
post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
| 85 |
+
except:
|
| 86 |
+
post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
| 87 |
+
post_box.send_keys(message)
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
time.sleep(1)
|
| 90 |
+
|
| 91 |
+
# Handle image uploads (assuming one upload field per image)
|
| 92 |
+
for image_file in images_list:
|
| 93 |
+
photo_element = driver.find_element(By.XPATH,'//input[@type="file"]')
|
| 94 |
+
photo_element.send_keys(image_file.name) # Or image_file.path, adjust as needed
|
| 95 |
+
time.sleep(1)
|
| 96 |
+
|
| 97 |
+
time.sleep(6)
|
| 98 |
+
post_button = driver.find_element_by_xpath("//*[@data-testid='react-composer-post-button']")
|
| 99 |
+
# ... (Rest of your logic to click the post button)
|
| 100 |
+
|
| 101 |
+
driver.close()
|
| 102 |
+
|
| 103 |
+
if __name__ == '__main__':
|
| 104 |
+
main()
|
| 105 |
|
| 106 |
if __name__ == '__main__':
|
| 107 |
main()
|