more updates

This commit is contained in:
Joe Steele
2024-06-17 09:27:06 -04:00
parent 2c16c348c7
commit b35e9e093d
+48 -40
View File
@@ -224,9 +224,11 @@ def get_auth_connect():
token = base64.b64encode(data_string.encode()).decode("utf-8") token = base64.b64encode(data_string.encode()).decode("utf-8")
headers = {"Authorization": f"Basic {token}"} headers = {"Authorization": f"Basic {token}"}
connections.update({'web' : headers}) connections.update({'web' : headers})
else:
headers = ""
if env.tiktok : if env.tiktok :
print(' Connecting to Instagram ...') print(' Connecting to Instagram ...')
return connections return connections,headers
################################################################################################## ##################################################################################################
@@ -311,7 +313,7 @@ def make_montage_video_from_google(inphotos):
inphotos (list): List of paths to input photo files. inphotos (list): List of paths to input photo files.
Returns: Returns:
tuple: A tuple containing the path to the output video file and a boolean indicating success. tuple: A tuple containing the path to the output video file and a boolean indicating succes
""" """
# Load the photos from the folder # Load the photos from the folder
@@ -415,7 +417,6 @@ def get_google_data(driver,outputs ):
print(' Found extra pics') print(' Found extra pics')
list_more_pics.click() list_more_pics.click()
elements = driver.find_elements(By.CLASS_NAME, 'jftiEf') elements = driver.find_elements(By.CLASS_NAME, 'jftiEf')
lst_data = [] lst_data = []
for data in elements: for data in elements:
name = data.find_element(By.CSS_SELECTOR, 'div.d4r55.YJxk2d').text name = data.find_element(By.CSS_SELECTOR, 'div.d4r55.YJxk2d').text
@@ -809,7 +810,7 @@ def get_wordpress_featured_photo_id(post_id):
################################################################################################## ##################################################################################################
def post_to_x2(title, content, date, rating, address, picslist, instasession,outputs): def post_to_x2(title, content, headers,date, rating, address, picslist,outputs):
""" """
Post to x2. Post to x2.
@@ -878,7 +879,7 @@ def post_to_x2(title, content, date, rating, address, picslist, instasession,out
################################################################################################## ##################################################################################################
def post_facebook3(title, content, date, rating, address, picslist, outputs): def post_facebook3(title, content,headers, date, rating, address, picslist, outputs):
""" """
Post to Facebook3. Post to Facebook3.
@@ -906,28 +907,32 @@ def post_facebook3(title, content, date, rating, address, picslist, outputs):
attrib_list = outputs['postssession'].query(Posts).filter(Posts.name == title).all() attrib_list = outputs['postssession'].query(Posts).filter(Posts.name == title).all()
business_url = attrib_list[0].businessurl business_url = attrib_list[0].businessurl
wpurl = attrib_list[0].wpurl wpurl = attrib_list[0].wpurl
status_message = str(title) + ': My Review - '+ wpurl + '\n Business website: '+ \ if wpurl:
business_url+' \n\n'+ content if business_url:
for img in img_list: status_message = str(title) + ': My Review - '+ wpurl + '\n Business website: '+ \
if 'montage.mp4' in img: business_url+' \n\n'+ content
imgs_vid.append(img.strip())
else: else:
imgs_pic.append(img.strip()) status_message = str(title) + ': My Review - '+ wpurl +' \n\n'+ content
if imgs_vid: for img in img_list:
try: if 'montage.mp4' in img:
post_id = post_facebook_video(group_id, imgs_vid,auth_token,title, status_message, imgs_vid.append(img.strip())
date, rating, address) else:
imgs_id.append(post_id['id']) imgs_pic.append(img.strip())
except AttributeError as error: if imgs_vid:
print(" An error occurred:",error) try:
return False post_id = post_facebook_video(group_id, imgs_vid,auth_token,title, status_message,
time.sleep(env.facebooksleep) date, rating, address)
print(' Facebook response: ',post_id) imgs_id.append(post_id['id'])
except AttributeError as error:
print(" An error occurred:",error)
return False
time.sleep(env.facebooksleep)
print(' Facebook response: ',post_id)
return (True) return (True)
################################################################################################## ##################################################################################################
def post_to_threads (title, content, date, rating, address, picslist, instasession): def post_to_threads (title, content, headers,date, rating, address, picslist,outputs):
if picslist != '[]' and "montage.mp4" in picslist: if picslist != '[]' and "montage.mp4" in picslist:
outputmontage = '' outputmontage = ''
addresshtml = re.sub(" ", ".",address) addresshtml = re.sub(" ", ".",address)
@@ -948,7 +953,7 @@ def post_to_threads (title, content, date, rating, address, picslist, instasessi
else: else:
return False return False
def post_to_threads2 (title, content, date, rating, address, picslist, instasession): def post_to_threads2 (title, content, headers,date, rating, address, picslist,outputs):
if picslist != '[]' and "montage.mp4" in picslist: if picslist != '[]' and "montage.mp4" in picslist:
outputmontage = '' outputmontage = ''
addresshtml = re.sub(" ", ".",address) addresshtml = re.sub(" ", ".",address)
@@ -995,7 +1000,7 @@ def post_to_threads2 (title, content, date, rating, address, picslist, instasess
####################################################################################################### #######################################################################################################
def post_to_tiktok(title, content, date, rating, address, picslist, instasession): def post_to_tiktok(title, content, headers,date, rating, address, picslist,outputs):
# Replace 'your_sessionid_cookie' with your actual TikTok sessionid cookie. # Replace 'your_sessionid_cookie' with your actual TikTok sessionid cookie.
session_id = 'your_sessionid_cookie' session_id = 'your_sessionid_cookie'
@@ -1037,10 +1042,11 @@ def post_to_tiktok(title, content, date, rating, address, picslist, instasession
####################################################################################################### #######################################################################################################
def post_to_instagram2(title, content, date, rating, address, picslist, instasession,outputs): def post_to_instagram2(title, content, headers,date, rating, address, picslist,outputs):
#post_to_instagram2(processrow.name, processrow.comment ,processrow.address,processrow.rating. #post_to_instagram2(processrow.name, processrow.comment ,processrow.address,processrow.rating.
# value, processrow.dictPostComplete, processrow.picsLocalpath,outputs['instagram']) # value, processrow.dictPostComplete, processrow.picsLocalpath,outputs['instagram'])
#montageexists = "montage.mp4" in picslist #montageexists = "montage.mp4" in picslist
instasession = outputs['instagram']
if picslist != '[]' and "montage.mp4" in picslist: if picslist != '[]' and "montage.mp4" in picslist:
outputmontage = '' outputmontage = ''
addresshtml = re.sub(" ", ".",address) addresshtml = re.sub(" ", ".",address)
@@ -1345,7 +1351,7 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,outputs
################################################################################################## ##################################################################################################
def process_reviews(outputs): def process_reviews(outputs,headerss):
# Process # Process
webcount = xtwittercount = instagramcount = facebookcount = 0 webcount = xtwittercount = instagramcount = facebookcount = 0
# webcount=xtwittercount=instagramcount=yelpcount=threadscount=facebookcount=tiktokcount = 0 # webcount=xtwittercount=instagramcount=yelpcount=threadscount=facebookcount=tiktokcount = 0
@@ -1581,7 +1587,7 @@ def process_reviews(outputs):
################################################################################################## ##################################################################################################
def process_reviews2(outputs): def process_reviews2(outputs,headers):
# Process # Process
webcount = xtwittercount = instagramcount = facebookcount = 0 webcount = xtwittercount = instagramcount = facebookcount = 0
# webcount=xtwittercount=instagramcount=yelpcount=threadscount=facebookcount=tiktokcount = 0 # webcount=xtwittercount=instagramcount=yelpcount=threadscount=facebookcount=tiktokcount = 0
@@ -1668,22 +1674,22 @@ def process_reviews2(outputs):
print (' Error getting wordpress links to update databse') print (' Error getting wordpress links to update databse')
except AttributeError as error : except AttributeError as error :
print ('Could not check to see post already exists',error) print ('Could not check to see post already exists',error)
webcount = process_socials("web",processrow,"post_to_wordpress",\ webcount = process_socials("web",processrow,headers,"post_to_wordpress",\
webcount, outputs) webcount, outputs)
if env.instagram: if env.instagram:
instagramcount = process_socials("instagram",processrow,"post_to_instagram2",\ instagramcount = process_socials("instagram",processrow,headers,"post_to_instagram2",\
instagramcount, outputs) instagramcount, outputs)
if env.facebook: if env.facebook:
facebookcount = process_socials("facebook",processrow,"post_facebook3",\ facebookcount = process_socials("facebook",processrow,headers,"post_facebook3",\
facebookcount, outputs) facebookcount, outputs)
if env.xtwitter: if env.xtwitter:
xtwittercount = process_socials("xtwitter",processrow,"post_to_x2",\ xtwittercount = process_socials("xtwitter",processrow,headers,"post_to_x2",\
xtwittercount, outputs) xtwittercount, outputs)
return return
################################################################################################## ##################################################################################################
def process_socials(social_name,social_post,sub_process,social_count, outputs): def process_socials(social_name,social_post,headers,sub_process,social_count, outputs):
"""Summary: """Summary:
Function to process social media posts. Function to process social media posts.
@@ -1701,14 +1707,16 @@ def process_socials(social_name,social_post,sub_process,social_count, outputs):
Count of the social that was selected Count of the social that was selected
""" """
writtento = (ast.literal_eval(social_post.dictPostComplete)) writtento = (ast.literal_eval(social_post.dictPostComplete))
if len(outputs['postssession'].query(Posts).filter(Posts.name == social_post.name,getattr\ # if len(outputs['postssession'].query(Posts).filter(Posts.name == social_post.name,getattr\
(Posts, social_name) is True).all())==0: # (Posts, social_name) is True).all())==0:
if (len(outputs['postssession'].query(Posts).filter(Posts.name == social_post.name,getattr\
(Posts, social_name) is True).all())==0) and ((outputs['postssession'].query(Posts).filter(Posts.name == social_post.name).all()[0].wpurl != None)or social_name == 'web'):
if social_count < env.postsperrun: if social_count < env.postsperrun:
try: try:
print(' Starting to generate ',social_name,' post') print(' Starting to generate ',social_name,' post')
new_social_post = eval(sub_process)(social_post.name, social_post.comment,\ new_social_post = eval(sub_process)(social_post.name, social_post.comment,\
social_post.date, social_post.rating, social_post.address, social_post.\ headers, social_post.date, social_post.rating, social_post.address, social_post.\
picsLocalpath,outputs['posts'],outputs ) picsLocalpath,outputs )
try: try:
print (' Start generating content to post to xtwitter') print (' Start generating content to post to xtwitter')
writtento[social_name] = 1 writtento[social_name] = 1
@@ -1754,11 +1762,11 @@ if __name__ == "__main__":
print('starting ...') print('starting ...')
preload() preload()
print('making connections ...') print('making connections ...')
outputs = get_auth_connect() outputs,headers = get_auth_connect()
if env.datasource == 'db': if env.datasource == 'db':
process_reviews2(outputs) process_reviews2(outputs,headers)
else: else:
process_reviews(outputs) process_reviews(outputs,headers)
print('Done!') print('Done!')
################################################################################################## ##################################################################################################