From e889d524a4141ba6a76f39ab9e8187998adc1f59 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 29 May 2024 15:12:06 -0400 Subject: [PATCH 01/12] fix some wordpress issues with dates --- social.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/social.py b/social.py index a2e1cdb..8f1c5dc 100644 --- a/social.py +++ b/social.py @@ -699,7 +699,7 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): print ('Stuff - > ',tempdate) # date = dt.timedelta(days=tempdate) # newdate = dt.datetime.strptime(date_string, format).date() - newdate = datetime.today() - relativedelta(days=tempdate) + newdate = datetime.today() + relativedelta(days=tempdate) else: if "a week" in date: # date = dt.timedelta(weeks= -1) @@ -711,7 +711,7 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): print ('Stuff - > ',tempdate) # date = dt.timedelta(weeks= tempdate) # newdate = dt.datetime.strptime(date_string, format).date() - newdate = datetime.today() - relativedelta(weeks= tempdate) + newdate = datetime.today() + relativedelta(weeks= tempdate) else: if "a month" in date: # date = dt.timedelta(months= -1) @@ -723,7 +723,7 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): print ('Stuff - > ',tempdate) # date = dt.timedelta(months= tempdate) # newdate = dt.datetime.strptime(date_string, format).date() - newdate = datetime.today() - relativedelta(months = tempdate) + newdate = datetime.today() + relativedelta(months = tempdate) else: if "a year" in date: # date = dt.timedelta(years= -1) @@ -736,7 +736,7 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): print ('Stuff - > ',tempdate) # date = dt.timedelta( years= tempdate) # newdate = dt.datetime.strptime(date_string).date() - newdate = datetime.today() - relativedelta(years= tempdate) + newdate = datetime.today() + relativedelta(years= tempdate) except Exception as error: print(" An error getting date occurred:",error) else: From 8538929d9796e87d1acd7f01cb7f1817640fa00f Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Wed, 29 May 2024 15:13:08 -0400 Subject: [PATCH 02/12] rebase --- social.py | 1 + 1 file changed, 1 insertion(+) diff --git a/social.py b/social.py index 8f1c5dc..42b8ae8 100644 --- a/social.py +++ b/social.py @@ -997,6 +997,7 @@ def process_reviews(outputs): # show browser or not ||| HEAD => 43.03 ||| No Head => 39 seg options.add_argument("--lang=en-US") options.add_argument("--disable-blink-features=AutomationControlled") + options.add_argument("--remote-debugging-pipe") # Exclude the collection of enable-automation switches options.add_experimental_option("excludeSwitches", ["enable-automation"]) # Turn-off userAutomationExtension From 56b9ff10d6a01b005beb7fffbd961ac0a21ae048 Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Wed, 29 May 2024 17:52:51 -0400 Subject: [PATCH 03/12] added docker remote browser support --- social.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/social.py b/social.py index 42b8ae8..3bf546f 100644 --- a/social.py +++ b/social.py @@ -1,5 +1,4 @@ import sqlalchemy -import env #data import time @@ -36,9 +35,12 @@ import instagrapi from moviepy.editor import VideoFileClip, concatenate_videoclips #import moviepy +from pathlib import Path + from sqlalchemy.ext.declarative import declarative_base #import mysqlclient #import mysql-connector-python +import env Base = declarative_base() ################################################################################################## @@ -178,6 +180,12 @@ def counter(driver): ################################################################################################## +def is_docker(): + cgroup = Path('/proc/self/cgroup') + return Path('/.dockerenv').is_file() or cgroup.is_file() and 'docker' in cgroup.read_text() + +################################################################################################## + def post_facebook(title, content, date, rating, address, picslist, instasession): #msg = 'Purple Ombre Bob Lace Wig Natural Human Hair now available on https://lace-wigs.co.za/' pics = ((picslist[1:-1].replace(",","")).replace("'","")).split(" ") @@ -1008,7 +1016,10 @@ def process_reviews(outputs): caps['acceptSslCerts'] = True options.set_capability('cloud:options', caps) #driver = webdriver.Chrome(desired_capabilities=caps) - driver = webdriver.Chrome(options=options) # Firefox(options=options) + if is_docker : + driver = webdriver.Remote("http://192.168.10.6:4444/wd/hub", options=options) + else: + driver = webdriver.Chrome(options=options) # Firefox(options=options) # Changing the property of the navigator value for webdriver to undefined driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") driver.get(env.URL) From 500c8fa945f8f82f9efc67d20b44295975ea57ee Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Wed, 29 May 2024 18:56:09 -0400 Subject: [PATCH 04/12] added some work with containers --- social.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/social.py b/social.py index 3bf546f..31209ae 100644 --- a/social.py +++ b/social.py @@ -207,13 +207,15 @@ def post_facebook(title, content, date, rating, address, picslist, instasession) ################################################################################################## -def postImage(group_id, img,auth_token): +def postImage(group_id, img,auth_token, title): files={} url = f"https://graph.facebook.com/{group_id}/photos?access_token=" + auth_token for eachfile in img: files.update({eachfile: open(eachfile, 'rb')}) data = { - "published" : False + "published" : False, + "alt_text" : title, + "description" : title } try: r = requests.post(url, files=files, data=data).json() @@ -237,7 +239,9 @@ def postVideo(group_id, video_path,auth_token,title, content, date, rating, addr data = { "title":title,"description" : title + "\n"+ address+"\nGoogle map to destination: " r"https://www.google.com/maps/dir/?api=1&destination="+addresshtml +"\n\n"+ content + "\n"+rating+"\n"+date+"\n\n"+ hastags(address, title)+ - "\n\nhttps://www.joeeatswhat.com"+"\n\n","published" : True + "\n\nhttps://www.joeeatswhat.com"+"\n\n","published" : True, + "alt_text" : title, + "description" : title } try: r = requests.post(url, files=files, data=data).json() @@ -273,7 +277,7 @@ def post_facebook2(title, content, date, rating, address, picslist, instasession # print(" An error occurred:", type(error).c) # An error occurred: if imgs_pic: try: - post_id = postImage(group_id ,imgs_pic,auth_token) + post_id = postImage(group_id ,imgs_pic,auth_token,title) imgs_id.append(post_id['id']) except Exception as error: print(" An error occurred:", type(error)) # An error occurred: @@ -338,7 +342,7 @@ def get_data(driver,outputs ): """ print('get data...') # Click on more botton on each text reviews - more_elemets = driver.find_elements(By.CSS_SELECTOR, '.w8nwRe.kyuRq') + # more_elemets = driver.find_elements(By.CSS_SELECTOR, '.w8nwRe.kyuRq') for list_more_element in more_elemets: list_more_element.click() # Find Pictures that have the expansion indicator to see the rest of the pictures under @@ -451,8 +455,9 @@ def scrolling(counter,driver): for _i in range(counter): try: scrolling = driver.execute_script( - 'document.getElementsByClassName("dS8AEf")[0].scrollTop=document.getElementsByClassName("dS8AEf")[0].scrollHeight', - scrollable_div + 'document.getElementsByClassName("dS8AEf")[0].\ + scrollTop=document.getElementsByClassName("dS8AEf")[0].scrollHeight', + scrollable_div ) time.sleep(3) except Exception as e: @@ -545,8 +550,8 @@ def write_to_xlsx2(data, outputs): ################################################################################################## def database_read(data): - from sqlalchemy import create_engine - import pandas as pd + # from sqlalchemy import create_engine + # import pandas as pd db_connection_str = 'mysql+pymysql://mysql_user:mysql_password@mysql_host/mysql_db' db_connection = create_engine(db_connection_str) df = pd.read_sql('SELECT * FROM table_name', con=db_connection) @@ -873,7 +878,7 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): print("An error occurred:", type(error).__name__) # An error occurred: try: print ('featured_media = ',file_id) - response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), data={"content" : title+' = '+content+'\n'+googleadress+'\n'+rating + contentpics, "featured_media" : file_id}, headers=headers) + response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), data={"content" : title+' = '+content+'\n'+googleadress+'\n'+rating + contentpics, "featured_media" : file_id,"rank_math_focus_keyword" : title }, headers=headers) print (response_piclinks) except Exception as error: print(" An error writing images to the post " + post_response.title + ' occurred:', type(error).__name__) # An error occurred') @@ -1017,7 +1022,8 @@ def process_reviews(outputs): options.set_capability('cloud:options', caps) #driver = webdriver.Chrome(desired_capabilities=caps) if is_docker : - driver = webdriver.Remote("http://192.168.10.6:4444/wd/hub", options=options) + driver = webdriver.Remote("http://192.168.10.9:4444/wd/hub", options=options) + print ("IN A DOCKER CONTAINER, USING REMOTE CHROME") else: driver = webdriver.Chrome(options=options) # Firefox(options=options) # Changing the property of the navigator value for webdriver to undefined From 939d35c4745384ab8fb6b4ad313194d00ce70124 Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Wed, 29 May 2024 22:36:01 -0400 Subject: [PATCH 05/12] fixed timeout issue with selenium. Working --- social.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/social.py b/social.py index 31209ae..b0da9bb 100644 --- a/social.py +++ b/social.py @@ -36,7 +36,7 @@ from moviepy.editor import VideoFileClip, concatenate_videoclips #import moviepy from pathlib import Path - +from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base #import mysqlclient #import mysql-connector-python @@ -240,8 +240,7 @@ def postVideo(group_id, video_path,auth_token,title, content, date, rating, addr r"https://www.google.com/maps/dir/?api=1&destination="+addresshtml +"\n\n"+ content + "\n"+rating+"\n"+date+"\n\n"+ hastags(address, title)+ "\n\nhttps://www.joeeatswhat.com"+"\n\n","published" : True, - "alt_text" : title, - "description" : title + "alt_text" : title } try: r = requests.post(url, files=files, data=data).json() @@ -342,7 +341,7 @@ def get_data(driver,outputs ): """ print('get data...') # Click on more botton on each text reviews - # more_elemets = driver.find_elements(By.CSS_SELECTOR, '.w8nwRe.kyuRq') + more_elemets = driver.find_elements(By.CSS_SELECTOR, '.w8nwRe.kyuRq') for list_more_element in more_elemets: list_more_element.click() # Find Pictures that have the expansion indicator to see the rest of the pictures under @@ -550,8 +549,6 @@ def write_to_xlsx2(data, outputs): ################################################################################################## def database_read(data): - # from sqlalchemy import create_engine - # import pandas as pd db_connection_str = 'mysql+pymysql://mysql_user:mysql_password@mysql_host/mysql_db' db_connection = create_engine(db_connection_str) df = pd.read_sql('SELECT * FROM table_name', con=db_connection) From 3f6133db0d6505fd6281b91d4289b4aea8bcdaab Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Thu, 30 May 2024 11:40:43 -0400 Subject: [PATCH 06/12] out of fync --- social.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/social.py b/social.py index b0da9bb..52d6c0d 100644 --- a/social.py +++ b/social.py @@ -1064,7 +1064,7 @@ def process_reviews(outputs): except Exception as error: print(" An error occurred writing Excel file:", type(error).__name__) # An error occurred: except Exception as error: - print (' Error writing web post : ',processrow[1].value, processrow[2].value,processrow[7].value, processrow[3].value,processrow[8].value, processrow[5].value, writtento["web"]+' '+error) + print (' Error writing web post : ',processrow[1].value, processrow[2].value,processrow[7].value, processrow[3].value,processrow[8].value, processrow[5].value, writtento["web"],' ',error) #print (' Error writing web post : ',processrow[1].value, processrow[2].value, outputs['web'],processrow[7].value, processrow[3].value,processrow[8].value, processrow[5].value, writtento["web"] ) else: print (' Exceeded the number of web posts per run, skipping', processrow[1].value) From 9b26c7ccb74044d2350138fed110161657e39b14 Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Thu, 30 May 2024 11:41:56 -0400 Subject: [PATCH 07/12] cv --- social.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/social.py b/social.py index 52d6c0d..9f679e6 100644 --- a/social.py +++ b/social.py @@ -679,7 +679,7 @@ def post_x(title, content, date, rating, address, picslist, instasession): # # Saving the response as JSON # json_response = response.json() # print(json.dumps(json_response, indent=4, sort_keys=True)) - return + return # ################################################################################################ From 68dba21de7b0bbdda02814d36916a20278bb0443 Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Sun, 2 Jun 2024 18:59:22 -0400 Subject: [PATCH 08/12] initial add of X/twitter --- social.py | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 204 insertions(+), 4 deletions(-) diff --git a/social.py b/social.py index 9f679e6..8bf7717 100644 --- a/social.py +++ b/social.py @@ -35,6 +35,9 @@ import instagrapi from moviepy.editor import VideoFileClip, concatenate_videoclips #import moviepy +#twitter +import tweepy + from pathlib import Path from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base @@ -628,6 +631,196 @@ def check_post(postname,postdate,headers2): ################################################################################################## +def threads(): + import asyncio + import aiohttp + + # Replace 'your_access_token' with your actual access token for Meta's Threads + ACCESS_TOKEN = 'your_access_token' + + # The URL for the Meta's Threads API endpoint to post a video + THREADS_API_ENDPOINT = 'https://api.threads.meta.com/v1/videos' + + # The path to the video file you want to upload + VIDEO_FILE_PATH = 'path_to_your_video.mp4' + + # The caption for your video + VIDEO_CAPTION = 'Your video caption' + + async def post_video_to_threads(): + # Open the video file in binary read mode + with open(VIDEO_FILE_PATH, 'rb') as video_file: + video_data = video_file.read() + + # Prepare the headers for the HTTP request + headers = { + 'Authorization': f'Bearer {ACCESS_TOKEN}', + 'Content-Type': 'video/mp4' + } + + # Use aiohttp to make an asynchronous HTTP POST request + async with aiohttp.ClientSession() as session: + async with session.post(THREADS_API_ENDPOINT, data=video_data, headers=headers) as response: + # Check if the request was successful + if response.status == 200: + print('Video successfully posted to Threads.') + else: + print('Failed to post video. Response:', await response.text()) + + # Run the asynchronous function using asyncio + if __name__ == '__main__': + asyncio.run(post_video_to_threads()) + return + +####################################################################################################### + +# from googleapiclient.discovery import build +# from oauth2client.service_account import ServiceAccountCredentials + +# # Replace 'YOUR_SERVICE_ACCOUNT_FILE.json' with the path to your service account JSON file +# SERVICE_ACCOUNT_FILE = 'YOUR_SERVICE_ACCOUNT_FILE.json' + +# # Replace 'your_google_business_id' with your actual Google Business ID +# GOOGLE_BUSINESS_ID = 'your_google_business_id' + +# # Scopes for Google My Business API +# SCOPES = ['https://www.googleapis.com/auth/business.manage'] + +# # Authenticate and build the Google My Business service +# credentials = ServiceAccountCredentials.from_json_keyfile_name(SERVICE_ACCOUNT_FILE, SCOPES) +# service = build('mybusiness', 'v4', credentials=credentials) + +# # Function to get the business website +# def get_business_website(business_id): +# # Make a request to the Google My Business API to get business details +# response = service.accounts().locations().get(name=business_id).execute() + +# # Extract the website from the response +# website = response.get('websiteUri', 'No website found for this business') +# return website + +# # Get the website for the given Google Business ID +# business_website = get_business_website(GOOGLE_BUSINESS_ID) +# print(f'The website for business ID {GOOGLE_BUSINESS_ID} is: {business_website}') + +################################################################################################## + +# The URL to your WordPress website's REST API endpoint for media +WP_API_MEDIA_URL = 'https://yourwebsite.com/wp-json/wp/v2/media' + +# The ID of the post for which you want to retrieve the featured photo ID +POST_ID = 'your_post_id' + +# Function to get the featured photo ID of a WordPress post +def get_featured_photo_id(post_id): + # Make a GET request to the WordPress REST API to retrieve media details + response = requests.get(f"{WP_API_MEDIA_URL}?parent={post_id}") + + # Check if the request was successful + if response.status_code == 200: + # Parse the JSON response + media_items = response.json() + + # Loop through the media items associated with the post + for item in media_items: + # Check if the media item is the featured image + if item.get('post', None) == int(post_id): + # Return the ID of the featured image + return item['id'] + + # If the request failed or the featured image was not found, return None + return None + +# # Example usage +# featured_photo_id = get_featured_photo_id(POST_ID) +# print(f"The featured photo ID for post {POST_ID} is: {featured_photo_id}") + +################################################################################################## + +def post_x2(title, content, date, rating, address, picslist, instasession): + pics = ((picslist[1:-1]).replace("'","")).split(",") + # Replace the following strings with your own keys and secrets + CONSUMER_KEY = env.consumer_key + CONSUMER_SECRET = env.consumer_secret + ACCESS_TOKEN = access_token + ACCESS_TOKEN_SECRET = access_token_secret + # Authenticate to Twitter + auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) + auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) + # Create an API object to use the Twitter API + api = tweepy.API(auth) + img_list = pics + for img in img_list: + if 'montage.mp4' in img: + imgs_vid.append(img.strip()) + else: + imgs_pic.append(img.strip()) + if imgs_vid: + # print ("loop") + try: + post_id = postVideo(group_id, imgs_vid,auth_token,title, content, + date, rating, address) + imgs_id.append(post_id['id']) + video_path = imgs+vid[0] + # Path to the video you want to upload + #video_path = 'path_to_video.mp4' + # Message to post along with the video + status_message = title + '/n/n'+ content + '/n/n'+ rating + '/n/n'+ address '/n/n' + # Upload video + media = api.media_upload(video_path, media_category='tweet_video') + # Post tweet with video + api.update_status(status=status_message, media_ids=[media.media_id_string]) + except Exception as error: + print(" An error occurred:",error) # An error occurred: + time.sleep(env.facebooksleep) + return + +################################################################################################## + +def post_tiktok(): + + # Replace 'your_sessionid_cookie' with your actual TikTok sessionid cookie. + session_id = 'your_sessionid_cookie' + + # Replace 'path_to_video.mp4' with the path to your video file. + file_path = 'path_to_video.mp4' + + # Replace 'Your video title' with the title of your video. + title = 'Your video title' + + # Replace the following list with the hashtags you want to add to your post. + tags = ['hashtag1', 'hashtag2', 'hashtag3'] + + # If you want to schedule your video, replace 'schedule_timestamp' with the Unix timestamp. + # Leave it as None if you want to upload immediately. + schedule_time = None # or Unix timestamp (e.g., 1672592400) + + return + +# def upload_video(session_id, file_path, title, tags, schedule_time=None): +# url = 'https://www.tiktok.com/api/upload/video/' +# headers = { +# 'Cookie': f'sessionid={session_id}' +# } +# data = { +# 'title': title, +# 'tags': ','.join(tags), +# 'schedule_time': schedule_time +# } +# files = { +# 'video': open(file_path, 'rb') +# } + +# response = requests.post(url, headers=headers, data=data, files=files) +# return response.json() + +# # Call the function to upload the video +# response = upload_video(session_id, file_path, title, tags, schedule_time) +# print(response) + +################################################################################################## + + def post_x(title, content, date, rating, address, picslist, instasession): # pics = ((picslist[1:-1]).replace("'","")).split(",") # from requests_oauthlib import OAuth1Session @@ -855,6 +1048,7 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): print(" An error loading the metadata from the post " + post_response.title + ' occurred: '+type(error).__name__) #ratinghtml = post_response.text firstMP4 = True + fmedia = {} for piclink in linkslist: #for loop in linkslist: print (' Adding ', piclink['link'], ' to posting') @@ -869,13 +1063,19 @@ def post_to_wp(title, content, headers,date, rating,address, picslist): #[evp_embed_video url="http://example.com/wp-content/uploads/videos/vid1.mp4" autoplay="true"] else: contentpics += '\n '+r'
' + # fmedia.append = piclink{'file_id' } # contentpics += '\n '+r'' + title +r'' +'\n\n' except Exception as error: print("An error occurred:", type(error).__name__) # An error occurred: try: - print ('featured_media = ',file_id) - response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), data={"content" : title+' = '+content+'\n'+googleadress+'\n'+rating + contentpics, "featured_media" : file_id,"rank_math_focus_keyword" : title }, headers=headers) + print ('featured_media = ',linkslist[0]['file_id']) + if linkslist[0]['file_id']: + print ('featuredmedia2 = ',linkslist[0]['file_id']) + else: + fmedia = file_id + print ('featured_media2 = ',file_id) + response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), data={"content" : title+' = '+content+'\n'+googleadress+'\n'+rating + contentpics, "featured_media" : fmedia,"rank_math_focus_keyword" : title }, headers=headers) print (response_piclinks) except Exception as error: print(" An error writing images to the post " + post_response.title + ' occurred:', type(error).__name__) # An error occurred') @@ -1128,12 +1328,12 @@ def process_reviews(outputs): print (' Exceeded the number of facebook posts per run, skipping', processrow[1].value) else: print (' Facebook: Skipping posting for ',processrow[1].value,' previously written') - if False: + if xtwitter: if writtento["xtwitter"] == 0: if xtwittercount <= env.postsperrun: try: print(' Starting to generate xtwitter post') - NewxtwitterPost = post_x(processrow[1].value, processrow[2].value, processrow[7].value, processrow[3].value, processrow[8].value, processrow[5].value,outputs['xtwitter'] ) + NewxtwitterPost = post_x2(processrow[1].value, processrow[2].value, processrow[7].value, processrow[3].value, processrow[8].value, processrow[5].value,outputs['xtwitter'] ) try: print (' Start generating content to post to xtwitter') writtento["facebook"] = 1 From bd2491c406272e1c4f83c81df647506ec11285f9 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Sun, 2 Jun 2024 21:38:49 -0400 Subject: [PATCH 09/12] fixing xtwitter --- social.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/social.py b/social.py index 8bf7717..6625aed 100644 --- a/social.py +++ b/social.py @@ -185,6 +185,7 @@ def counter(driver): def is_docker(): cgroup = Path('/proc/self/cgroup') + #print (cgroup.read_text()) return Path('/.dockerenv').is_file() or cgroup.is_file() and 'docker' in cgroup.read_text() ################################################################################################## @@ -765,7 +766,7 @@ def post_x2(title, content, date, rating, address, picslist, instasession): # Path to the video you want to upload #video_path = 'path_to_video.mp4' # Message to post along with the video - status_message = title + '/n/n'+ content + '/n/n'+ rating + '/n/n'+ address '/n/n' + status_message = title + '/n/n'+ content + '/n/n'+ rating + '/n/n'+ address +'/n/n' # Upload video media = api.media_upload(video_path, media_category='tweet_video') # Post tweet with video @@ -1218,7 +1219,7 @@ def process_reviews(outputs): caps['acceptSslCerts'] = True options.set_capability('cloud:options', caps) #driver = webdriver.Chrome(desired_capabilities=caps) - if is_docker : + if is_docker() : driver = webdriver.Remote("http://192.168.10.9:4444/wd/hub", options=options) print ("IN A DOCKER CONTAINER, USING REMOTE CHROME") else: @@ -1328,7 +1329,7 @@ def process_reviews(outputs): print (' Exceeded the number of facebook posts per run, skipping', processrow[1].value) else: print (' Facebook: Skipping posting for ',processrow[1].value,' previously written') - if xtwitter: + if env.xtwitter: if writtento["xtwitter"] == 0: if xtwittercount <= env.postsperrun: try: From 53f7ae3c7ec5ed7d942613994ba0966369ccc743 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Mon, 3 Jun 2024 12:51:48 -0400 Subject: [PATCH 10/12] Twitter v2 updates --- social.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/social.py b/social.py index 6625aed..f1bb8a5 100644 --- a/social.py +++ b/social.py @@ -743,14 +743,17 @@ def post_x2(title, content, date, rating, address, picslist, instasession): # Replace the following strings with your own keys and secrets CONSUMER_KEY = env.consumer_key CONSUMER_SECRET = env.consumer_secret - ACCESS_TOKEN = access_token - ACCESS_TOKEN_SECRET = access_token_secret + ACCESS_TOKEN = env.access_token + ACCESS_TOKEN_SECRET = env.access_token_secret # Authenticate to Twitter auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) # Create an API object to use the Twitter API api = tweepy.API(auth) img_list = pics + imgs_vid = [] + imgs_pic = [] + #imgs_id = [] for img in img_list: if 'montage.mp4' in img: imgs_vid.append(img.strip()) @@ -759,10 +762,10 @@ def post_x2(title, content, date, rating, address, picslist, instasession): if imgs_vid: # print ("loop") try: - post_id = postVideo(group_id, imgs_vid,auth_token,title, content, - date, rating, address) - imgs_id.append(post_id['id']) - video_path = imgs+vid[0] + # post_id = postVideo(group_id, imgs_vid,auth_token,title, content, + # date, rating, address) + # imgs_id.append(post_id['id']) + video_path = imgs_vid[0] # Path to the video you want to upload #video_path = 'path_to_video.mp4' # Message to post along with the video @@ -1334,10 +1337,10 @@ def process_reviews(outputs): if xtwittercount <= env.postsperrun: try: print(' Starting to generate xtwitter post') - NewxtwitterPost = post_x2(processrow[1].value, processrow[2].value, processrow[7].value, processrow[3].value, processrow[8].value, processrow[5].value,outputs['xtwitter'] ) + NewxtwitterPost = post_x2(processrow[1].value, processrow[2].value, processrow[7].value, processrow[3].value, processrow[8].value, processrow[5].value,outputs['posts'] ) try: print (' Start generating content to post to xtwitter') - writtento["facebook"] = 1 + writtento["xtwitter"] = 1 processrow[9].value = str(writtento) except Exception as error: print(" An error occurred setting value to go into Excel file:", type(error).__name__) # An error occurred: @@ -1353,7 +1356,7 @@ def process_reviews(outputs): except Exception as error: print(" An error occurred writing Excel file:", type(error).__name__) # An error occurred: except Exception as error: - print (' Error writing xtwitter post : ',processrow[1].value, processrow[2].value, outputs,processrow[7].value, processrow[3].value,processrow[8].value, processrow[5].value, writtento["xtwitter"], type(error).__name__ ) + print (' Error writing xtwitter post : ',error,processrow[1].value, processrow[2].value, outputs,processrow[7].value, processrow[3].value,processrow[8].value, processrow[5].value, writtento["xtwitter"], type(error).__name__ ) else: print (' Exceeded the number of xtwitter posts per run, skipping', processrow[1].value) else: From 467f22c1b657e36a96119bf4617c9ed2ac328d7e Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Mon, 3 Jun 2024 14:41:07 -0400 Subject: [PATCH 11/12] jj --- social.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/social.py b/social.py index f1bb8a5..b64bf5f 100644 --- a/social.py +++ b/social.py @@ -738,6 +738,25 @@ def get_featured_photo_id(post_id): ################################################################################################## +def get_twitter_conn_v1(api_key, api_secret, access_token, access_token_secret) -> tweepy.API: + """Get twitter conn 1.1""" + auth = tweepy.OAuth1UserHandler(api_key, api_secret) + auth.set_access_token( + access_token, + access_token_secret, + ) + return tweepy.API(auth) + +def get_twitter_conn_v2(api_key, api_secret, access_token, access_token_secret) -> tweepy.Client: + """Get twitter conn 2.0""" + client = tweepy.Client( + consumer_key=api_key, + consumer_secret=api_secret, + access_token=access_token, + access_token_secret=access_token_secret, + ) + return client + def post_x2(title, content, date, rating, address, picslist, instasession): pics = ((picslist[1:-1]).replace("'","")).split(",") # Replace the following strings with your own keys and secrets @@ -754,6 +773,9 @@ def post_x2(title, content, date, rating, address, picslist, instasession): imgs_vid = [] imgs_pic = [] #imgs_id = [] + client_v1 = get_twitter_conn_v1(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) + client_v2 = get_twitter_conn_v2(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) + # media_path = "C:\\YourPath" for img in img_list: if 'montage.mp4' in img: imgs_vid.append(img.strip()) @@ -769,11 +791,18 @@ def post_x2(title, content, date, rating, address, picslist, instasession): # Path to the video you want to upload #video_path = 'path_to_video.mp4' # Message to post along with the video - status_message = title + '/n/n'+ content + '/n/n'+ rating + '/n/n'+ address +'/n/n' + status_message = title + '/n/n'+ content + '/n/n'+ address + status_message_short = status_message[:279] + # if len(status_message) > 279: + # print (' Count of twitter message: ',len(status_message)) # Upload video - media = api.media_upload(video_path, media_category='tweet_video') + media = client_v1.media_upload(filename=video_path) + media_id = media.media_id + #media = api.media_upload(video_path, media_category='tweet_video') # Post tweet with video - api.update_status(status=status_message, media_ids=[media.media_id_string]) + client_v2.create_tweet(text=status_message_short, media_ids=[media.media_id_string]) + #client_v2.create_tweet(text=status_message_short, media_ids=[media_id]) + #api.update_status(status=status_message, media_ids=[media.media_id_string]) except Exception as error: print(" An error occurred:",error) # An error occurred: time.sleep(env.facebooksleep) From f434214effc236444dd676fe6aa2741ab3215b5b Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Tue, 4 Jun 2024 08:26:34 -0400 Subject: [PATCH 12/12] UPDATE --- social.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/social.py b/social.py index b64bf5f..c35db46 100644 --- a/social.py +++ b/social.py @@ -242,7 +242,7 @@ def postVideo(group_id, video_path,auth_token,title, content, date, rating, addr files.update({eachfile: open(eachfile, 'rb')}) data = { "title":title,"description" : title + "\n"+ address+"\nGoogle map to destination: " r"https://www.google.com/maps/dir/?api=1&destination="+addresshtml +"\n\n"+ content + - "\n"+rating+"\n"+date+"\n\n"+ hastags(address, title)+ + "\n"+rating+"\n"+date+"\n\n"+ hastags(address, title, 'long')+ "\n\nhttps://www.joeeatswhat.com"+"\n\n","published" : True, "alt_text" : title } @@ -760,10 +760,10 @@ def get_twitter_conn_v2(api_key, api_secret, access_token, access_token_secret) def post_x2(title, content, date, rating, address, picslist, instasession): pics = ((picslist[1:-1]).replace("'","")).split(",") # Replace the following strings with your own keys and secrets - CONSUMER_KEY = env.consumer_key - CONSUMER_SECRET = env.consumer_secret - ACCESS_TOKEN = env.access_token - ACCESS_TOKEN_SECRET = env.access_token_secret + CONSUMER_KEY = env.x_consumer_key + CONSUMER_SECRET = env.x_consumer_secret + ACCESS_TOKEN = env.x_access_token + ACCESS_TOKEN_SECRET = env.x_access_token_secret # Authenticate to Twitter auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) @@ -773,8 +773,8 @@ def post_x2(title, content, date, rating, address, picslist, instasession): imgs_vid = [] imgs_pic = [] #imgs_id = [] - client_v1 = get_twitter_conn_v1(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) - client_v2 = get_twitter_conn_v2(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) + client_v1 = get_twitter_conn_v1(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN,ACCESS_TOKEN_SECRET) + client_v2 = get_twitter_conn_v2(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN,ACCESS_TOKEN_SECRET) # media_path = "C:\\YourPath" for img in img_list: if 'montage.mp4' in img: @@ -791,16 +791,17 @@ def post_x2(title, content, date, rating, address, picslist, instasession): # Path to the video you want to upload #video_path = 'path_to_video.mp4' # Message to post along with the video - status_message = title + '/n/n'+ content + '/n/n'+ address - status_message_short = status_message[:279] + status_message = title + ': Review https://www.joeeatswhat.com' + status_message2 = status_message +' '+hastags(address, title, 'short') + status_message_short = status_message2[:279] # if len(status_message) > 279: # print (' Count of twitter message: ',len(status_message)) # Upload video media = client_v1.media_upload(filename=video_path) - media_id = media.media_id + # media_id = media.media_id #media = api.media_upload(video_path, media_category='tweet_video') # Post tweet with video - client_v2.create_tweet(text=status_message_short, media_ids=[media.media_id_string]) + client_v2.create_tweet(text=status_message_short, media_ids=[media.media_id]) #client_v2.create_tweet(text=status_message_short, media_ids=[media_id]) #api.update_status(status=status_message, media_ids=[media.media_id_string]) except Exception as error: @@ -810,7 +811,7 @@ def post_x2(title, content, date, rating, address, picslist, instasession): ################################################################################################## -def post_tiktok(): +def post_tiktok(title, content, date, rating, address, picslist, instasession): # Replace 'your_sessionid_cookie' with your actual TikTok sessionid cookie. session_id = 'your_sessionid_cookie' @@ -843,7 +844,6 @@ def post_tiktok(): # files = { # 'video': open(file_path, 'rb') # } - # response = requests.post(url, headers=headers, data=data, files=files) # return response.json() @@ -1158,7 +1158,7 @@ def post_to_instagram2 (title, content, date, rating, address, picslist, instase pics = ((picslist[1:-1].replace(",","")).replace("'","")).split(" ") video, outputmontage = make_video(pics) try: - data = title + "\n"+ address+"\nGoogle map to destination: " r"https://www.google.com/maps/dir/?api=1&destination="+addresshtml +"\n\n"+ content + "\n"+rating+"\n"+date+"\n\n"+ hastags(address, title)+"\n\nhttps://www.joeeatswhat.com"+"\n\n" + data = title + "\n"+ address+"\nGoogle map to destination: " r"https://www.google.com/maps/dir/?api=1&destination="+addresshtml +"\n\n"+ content + "\n"+rating+"\n"+date+"\n\n"+ hastags(address, title,'long')+"\n\nhttps://www.joeeatswhat.com"+"\n\n" instasession.video_upload(outputmontage, data) # video2 = instasession.video_upload(outputmontage, data) except Exception as error: @@ -1205,13 +1205,16 @@ def clearlist (list): ################################################################################################## -def hastags (address, name): +def hastags (address, name, type): nameNoSpaces = re.sub( r'[^a-zA-Z]','',name) addressdict = address.rsplit(r' ',3) zip = addressdict[3] state = addressdict[2] city = re.sub( r'[^a-zA-Z]','',addressdict[1]) - defaulttags = "\n\n\n#"+nameNoSpaces+" #foodie #music #food #travel #drinks #instagood #feedme #joeeatswhat @timberjoe" + if 'short' in type: + defaulttags = '#'+nameNoSpaces+' #foodie #food #joeeatswhat @timberjoe' + else: + defaulttags = "\n\n\n#"+nameNoSpaces+" #foodie #music #food #travel #drinks #instagood #feedme #joeeatswhat @timberjoe" citytag = "#"+city statetag = "#"+state ziptag = "#"+zip