Closed sakarimov closed 3 years ago
i suggest an edit in file instagram.py and xpath.py
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from time import sleep
from .xpath import xpath from .browser import explicit_wait_visibility_of_element_located
MODE_INSTAGRAM = "mode=instagram"
def go_to_instagram_Tab(browser): """Go to instragram mode"""
if MODE_INSTAGRAM in browser.current_url:
print("Already in Instragram Mode")
return
try:
instagram_button = browser.find_element_by_xpath(xpath[go_to_instagram_Tab.__name__]["instagram_button"])
except:
print("Unable to find Instagram Button")
ActionChains(browser).move_to_element(instagram_button).click().perform()
if MODE_INSTAGRAM in browser.current_url:
print("Switched to Instagram Mode")
return
def create_post(browser, account, message, file, schedule_options=None): """Create a post."""
explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["create_post_button"])
create_post_button = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["create_post_button"])
ActionChains(browser).move_to_element(create_post_button).click().perform()
sleep(2)
explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["instagram_feed_button"])
instagram_feed_button = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["instagram_feed_button"])
ActionChains(browser).move_to_element(instagram_feed_button).click().perform()
sleep(1)
try:
explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["input_account"])
input_account = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["input_account"])
for character in account:
ActionChains(browser).move_to_element(input_account).click().send_keys(character).perform()
sleep(1)
list_account = explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["list_account"].format(account), timeout=1)
if list_account is not None:
ActionChains(browser).move_to_element(list_account).click().perform()
sleep(1)
break
sleep(2)
except:
pass
# First we load the content
explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["add_content_button"])
add_content_button = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["add_content_button"])
browser.execute_script("arguments[0].scrollIntoView();", add_content_button)
ActionChains(browser).move_to_element(add_content_button).click().perform()
sleep(2)
input_file = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["input_file"])
input_file.send_keys(file)
sleep(1)
input_message = explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["input_message"])
browser.execute_script("arguments[0].scrollIntoView();", input_message)
ActionChains(browser).move_to_element(input_message).click().send_keys(message).perform()
sleep(1)
if schedule_options is not None:
schedule_options_hour, schedule_options_minutes, = schedule_options["time"].replace(":", " ").split()
options_publish_button = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["options_publish_button"])
ActionChains(browser).move_to_element(options_publish_button).click().perform()
sleep(1)
schedule_option = explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["schedule_option"])
ActionChains(browser).move_to_element(schedule_option).click().perform()
sleep(1)
input_date = browser.find_element_by_xpath(xpath["instagram"][create_post.__name__]["input_date"])
ActionChains(browser).move_to_element(input_date).click().send_keys(schedule_options["date"]).perform()
sleep(1)
hour, minutes = browser.find_elements_by_xpath(xpath["instagram"][create_post.__name__]["input_time"])
hour.send_keys(schedule_options_hour)
sleep(1)
minutes.send_keys(schedule_options_minutes)
sleep(1)
print("Watting for load finish.")
load_finished = explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["load_complete"])
if load_finished is None:
print("Load not finish. Aborting...")
return
send_post_button = explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["send_post_button"])
browser.execute_script("arguments[0].scrollIntoView();", send_post_button)
ActionChains(browser).move_to_element(send_post_button).click().perform()
sleep(1)
success_message = explicit_wait_visibility_of_element_located(browser, xpath["instagram"][create_post.__name__]["success_message"])
if success_message is None:
print("Error Creating Post")
return False
print("Post Created.")
return True
xpath = {}
xpath["is_user_loged"] = { "login_button": "//div[text()='Facebook Login']", }
xpath["login_user"] = { "input_email": "//input[@name='email']", "input_password": "//input[@name='pass']", "login_button": "//button[@name='login']", }
xpath["go_to_instagram_Tab"] = { "instagram_button": "//div[@id='media_manager_chrome_bar_instagram_icon']", }
xpath["instagram"] = { }
xpath["instagram"]["create_post"] = { "create_post_button": "//div[text()='Create Post']", "instagram_feed_button": "//strong[text()='Instagram feed']", "input_account": "//input[@class='_4b7k _4b7k_media-manager-instagram-composer _53rs']", "list_account": "//div[text()='{}']", "input_message": "//div[@aria-autocomplete='list']", "add_content_button": "//span[@class='l61y9joe j8otv06s a1itoznt fvlrrmdj svz86pwt jrvjs1jy a53abz89 jvnjaidj']", "input_file": "//input[@class='_n _5f0v']", "send_post_button": "//button[@class='_271k _271m _1qjd']", "options_publish_button": "//button[@class='_271k _271l _1o4e _271m _1qjd']", "schedule_option": "//span[text()='Schedule']", "publish_now_option": "//span[text()='Publish Now']", "draft_option": "//span[text()='Draft']", "input_date": "//input[@placeholder='dd/mm/yyyy']", "input_time": "//input[@role='spinbutton']", "load_complete": "//div[text()='100%']", "success_message": "//span[text()='Your post has been successfully scheduled.']", }
xpath["go_to_facebook_Tab"] = { "facebook_button": "//div[@id='media_manager_chrome_bar_facebook_icon']", }
xpath["facebook"] = { }
xpath["facebook"]["create_post"] = { "create_post_button": "//div[text()='Create Post']", "create_post_button_2": "//span[text()='Create Post']", "input_page": "//input[@class='_4b7k _4b7k_media-manager-composer-search _53rs']", "list_page": "//span[@class='_4lq7']/div[text()='{}']", "input_message": "//div[@role='textbox']", "input_file": "//input[@accept='image/*, image/heic, image/heif']", "publish_button": "//button[@class='_1mf7 _8bma _4jy0 _4jy3 _4jy1 _51sy selected _42ft']", "options_publish_button": "//div[@class='_43rm' and text()='Share Now']", "schedule_option": "//span[text()='Schedule']", "publish_now_option": "//span[text()='Now']", "Backdate_option": "//span[text()='Backdate']", "draft_option": "//span[text()='Save Draft']", "input_date": "//input[@placeholder='dd/mm/yyyy']", "input_time": "//input[@role='spinbutton']", "schedule_button": "//button[@class='layerConfirm _4jy0 _4jy3 _4jy1 _51sy selected _42ft' and text()='Schedule']", "success_message": "//span[text()='Success! You can view your post in the content library.']", }
Hi @sakarimov there isn't any time mode change in Creator Studio, at least no for me(In general changes are not deployed to all user at the same time.). I think you change something in your configs.
Sorry @asperduti my bad, i forgot that my account is set indonesian, maybe the time insertion is still indonesian style, After realizing that, I was looking for a way to change it to English, but the creator studio doesn't have a language setting, is there any suggestion?
Hi @sakarimov sorry for the delay.
The creator studio doesn't have a language setting itself, but yes it has it your Facebook account(under Settings/Language and Region).
I'm not sure if the Creator Studio takes the Facebook setting or the setting on your system.
The Creator Studio takes the Facebook language of your account. You have to change it to English(US)
User is logged Traceback (most recent call last): File "niaga.py", line 15, in <module> cs_cli.create_post(account=post[0], File "/home/cikapc/creator-studio-cli/creator_studio/creator_studio.py", line 31, in create_post instagram.create_post(self.browser, account, message, file, schedule_options=schedule_options) File "/home/cikapc/creator-studio-cli/creator_studio/instagram.py", line 77, in create_post schedule_options_hour, schedule_options_minutes, schedule_options_am_pm, = schedule_options["time"].replace(":", " ").split() ValueError: not enough values to unpack (expected 3, got 2)
i guess it's because of time mode change in Creator Studio it self, now it's 24 hour without AM / PM