From 8b42fda122c3811041b70136d294012a78f1ca3d Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 12 Jun 2024 14:30:23 -0400 Subject: [PATCH 1/7] more docstrings --- social.py | 61 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/social.py b/social.py index c1d9e5a..afae810 100644 --- a/social.py +++ b/social.py @@ -793,22 +793,22 @@ def get_wordpress_featured_photo_id(post_id): def post_to_x2(title, content, date, rating, address, picslist, instasession): """ -Post to x2. + Post to x2. -This function posts content to a social media platform using the provided data. + This function posts content to a social media platform using the provided data. -Args: - title (str): The title of the post. - content (str): The content of the post. - date (str): The date of the post. - rating (int): The rating of the post. - address (str): The address associated with the post. - picslist (list): A list of pictures for the post. - instasession: The Instagram session for posting. + Args: + title (str): The title of the post. + content (str): The content of the post. + date (str): The date of the post. + rating (int): The rating of the post. + address (str): The address associated with the post. + picslist (list): A list of pictures for the post. + instasession: The Instagram session for posting. -Returns: - str: The media ID of the posted content. -""" + Returns: + str: The media ID of the posted content. + """ pics = ((picslist[1:-1]).replace("'","")).split(",") # Replace the following strings with your own keys and secrets @@ -864,6 +864,23 @@ Returns: ################################################################################################## def post_facebook3(title, content, date, rating, address, picslist, instasession): + """ + Post to Facebook3. + + This function posts content to Facebook using the provided data. + + Args: + title (str): The title of the post. + content (str): The content of the post. + date (str): The date of the post. + rating (int): The rating of the post. + address (str): The address associated with the post. + picslist (list): A list of pictures for the post. + instasession: The Instagram session for posting. + + Returns: + bool: Indicates if the post was successfully made. + """ pics = ((picslist[1:-1]).replace("'","")).split(",") group_id = env.facebookpageID auth_token = env.facebookpass @@ -1051,6 +1068,24 @@ def post_to_instagram2 (title, content, date, rating, address, picslist, instase ################################################################################################## def post_to_wordpress(title,content,headers,date,rating,address,picslist,outputs): + """ + Post to WordPress. + + This function posts content to a WordPress site using the provided data. + + Args: + title (str): The title of the post. + content (str): The content of the post. + headers: Headers for the request. + date (str): The date of the post. + rating (str): The rating of the post. + address (str): The address associated with the post. + picslist (list): A list of pictures for the post. + outputs: Outputs for the post. + + Returns: + None +""" # post newPost = False #countreview = False From dfb0d4b6f6fb4202644f68f22d44ad1388b0c924 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Thu, 13 Jun 2024 08:49:42 -0400 Subject: [PATCH 2/7] added link to wordpress review to Twitter --- requirements.txt | 5 ++++- social.py | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index d551115..84954d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,7 @@ jsonpickle tweepy sqlalchemy googlemaps -moviepy \ No newline at end of file +moviepy +mysqlclient +mysql-connector-python +pymysql \ No newline at end of file diff --git a/social.py b/social.py index afae810..ba94f40 100644 --- a/social.py +++ b/social.py @@ -483,7 +483,7 @@ def get_google_data(driver,outputs ): for lmpics in more_specific_pics: # Grab URL from style definiton (long multivalue string), and remove the -p-k so that # it is full size - urlmedia = re.sub('=\S*-p-k-no', '=-no', (re.findall(r"['\"](.*?)['\"]", + urlmedia = re.sub(r'=\S*-p-k-no', '=-no', (re.findall(r"['\"](.*?)['\"]", lmpics.get_attribute("style")))[0]) print (' Pic URL : ',urlmedia) pics.append(urlmedia) @@ -791,7 +791,7 @@ def get_wordpress_featured_photo_id(post_id): ################################################################################################## -def post_to_x2(title, content, date, rating, address, picslist, instasession): +def post_to_x2(title, content, date, rating, address, picslist, instasession,outputs): """ Post to x2. @@ -843,7 +843,9 @@ def post_to_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 = str(title) + ': Review https://www.joeeatswhat.com' + wpurllist = outputs['postssession'].query(Posts).filter(Posts.name == title).all() + wpurl = wpurllist[0].wpurl + status_message = str(title) + ': My Review - '+ wpurl status_message2 = status_message +' '+str(get_hastags(address, title, 'short'))+' ' status_message_short = status_message2[:279] # if len(status_message) > 279: @@ -1258,7 +1260,7 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,outputs try: post_response = requests.post(env.wpAPI + "/posts/" + str(post_id),\ headers=headers,timeout=30) - if link in str(post_response.text): + if link in post_response.text: print (' Image link for ', picname, 'already in content of post: ' \ ,post_id, post_response.text, link) else: @@ -1481,7 +1483,7 @@ def process_reviews(outputs): if xtwittercount < env.postsperrun: try: print(' Starting to generate xtwitter post') - NewxtwitterPost = post_to_x2(processrow[1].value, processrow[2].value, processrow[7].value, processrow[3].value, processrow[8].value, processrow[5].value,outputs['posts'] ) + NewxtwitterPost = post_to_x2(processrow[1].value, processrow[2].value, processrow[7].value, processrow[3].value, processrow[8].value, processrow[5].value,outputs['posts'],outputs ) try: print (' Start generating content to post to xtwitter') writtento["xtwitter"] = 1 From cbc21642b17b57f87f0c0552de9808bb3a88b4bd Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Thu, 13 Jun 2024 08:54:23 -0400 Subject: [PATCH 3/7] Added business url to Twitter --- social.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/social.py b/social.py index c2b337d..024fd6c 100644 --- a/social.py +++ b/social.py @@ -858,9 +858,11 @@ def post_to_x2(title, content, date, rating, address, picslist, instasession,out # Path to the video you want to upload #video_path = 'path_to_video.mp4' # Message to post along with the video + business_url_list = outputs['postssession'].query(Posts).filter(Posts.name == title).all() + business_url = business_url_list[0].business_url_list wpurllist = outputs['postssession'].query(Posts).filter(Posts.name == title).all() wpurl = wpurllist[0].wpurl - status_message = str(title) + ': My Review - '+ wpurl + status_message = str(title) + ': My Review - '+ wpurl + '\n Business website: '+ business_url status_message2 = status_message +' '+str(get_hastags(address, title, 'short'))+' ' status_message_short = status_message2[:279] # if len(status_message) > 279: From 9dac3356810a4bb1b9f6699b2744757669a227d8 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Thu, 13 Jun 2024 08:57:57 -0400 Subject: [PATCH 4/7] Added link to website to wordpress --- social.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/social.py b/social.py index 024fd6c..1c27ec9 100644 --- a/social.py +++ b/social.py @@ -1317,8 +1317,13 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,outputs else: fmedia = file_id # print ('featured_media2 = ',file_id) + business_url_list = outputs['postssession'].query(Posts).filter(Posts.name == title).all() + business_url = business_url_list[0].business_url_list + wpurllist = outputs['postssession'].query(Posts).filter(Posts.name == title).all() + wpurl = wpurllist[0].wpurl + status_message = str(title) + ': My Review - '+ wpurl + '\n Business website: '+ business_url response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), \ - data={"content" : title+' = '+content+'\n'+googleadress+'\n'+rating + contentpics,\ + data={"content" : title+' = '+status_message+'\n\n'+content+'\n'+googleadress+'\n'+rating + contentpics,\ "featured_media" : fmedia,"rank_math_focus_keyword" : title }, headers=headers,\ timeout=30) print (' ',response_piclinks) From 9dd2920ff2076bfba346814c2a6ddeb090c9113e Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Thu, 13 Jun 2024 08:59:16 -0400 Subject: [PATCH 5/7] removed link to wordpress site from being posted to wordpress site --- social.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/social.py b/social.py index 1c27ec9..ee86f5f 100644 --- a/social.py +++ b/social.py @@ -1319,9 +1319,9 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,outputs # print ('featured_media2 = ',file_id) business_url_list = outputs['postssession'].query(Posts).filter(Posts.name == title).all() business_url = business_url_list[0].business_url_list - wpurllist = outputs['postssession'].query(Posts).filter(Posts.name == title).all() - wpurl = wpurllist[0].wpurl - status_message = str(title) + ': My Review - '+ wpurl + '\n Business website: '+ business_url + # wpurllist = outputs['postssession'].query(Posts).filter(Posts.name == title).all() + # wpurl = wpurllist[0].wpurl + status_message = str(title) + ': Business website: '+ business_url response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), \ data={"content" : title+' = '+status_message+'\n\n'+content+'\n'+googleadress+'\n'+rating + contentpics,\ "featured_media" : fmedia,"rank_math_focus_keyword" : title }, headers=headers,\ From 59cb54c6c3aba63e8b34faed0b1517fca8cab68a Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Thu, 13 Jun 2024 11:58:31 -0400 Subject: [PATCH 6/7] fixed twitter --- social.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/social.py b/social.py index ee86f5f..1836c94 100644 --- a/social.py +++ b/social.py @@ -716,8 +716,7 @@ def check_wordpress_media(filename,headers): link = result[0]['guid']['rendered'] return file_id, link except Exception as error: - print(' No existing media with same name in Wordpress media folder: '+filename+' '\ - ,error) + print(' No existing media with same name in Wordpress media folder: '+filename) return (False, False) ################################################################################################## From 2bc34775c04a6d8d4b4a2fb4e8defbf02b113dd8 Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Thu, 13 Jun 2024 15:36:40 -0400 Subject: [PATCH 7/7] dint know --- social.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/social.py b/social.py index 1836c94..65f2fe8 100644 --- a/social.py +++ b/social.py @@ -1,6 +1,10 @@ #data import time import os +from pathlib import Path +#from selenium.webdriver.chrome.webdriver import WebDriver +#from selenium.webdriver.chrome.service import Service + import re import urllib3 from urllib.request import urlretrieve @@ -39,11 +43,13 @@ import tweepy #import asyncio #import aiohttp -from pathlib import Path -#from sqlalchemy import create_engine -from sqlalchemy.ext.declarative import declarative_base + import sqlalchemy +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import null +from selenium import webdriver +from selenium.webdriver.common.by import By import googlemaps #import mysqlclient #import mysql-connector-python