From a26b334571927ed47f278fd808cb8cc52c2047ec Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 26 Jun 2024 12:24:21 -0400 Subject: [PATCH 1/3] cleanup --- social.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/social.py b/social.py index 0778fc8..3ef55e1 100644 --- a/social.py +++ b/social.py @@ -449,6 +449,7 @@ def get_google_data(driver, local_outputs): except NoSuchElementException : visitdate = "Unknown" print(' Visited: ',visitdate) + newdate,newdate2,visitdate = get_wordpress_post_date_string(visitdate, datetime.now()) try: text = data.find_element(By.CSS_SELECTOR, 'div.MyEned').text except NoSuchElementException : @@ -677,14 +678,14 @@ def write_to_database(data, local_outputs): for x in inspect.getmembers(Posts): if not (x[0].startswith('_') or 'metadata' in x[0] or 'registry' in x[0]): column_list.append(x[0]) - cols = ["name", "comment", 'rating','picsURL','picsLocalpath','source','date','address', - 'dictPostComplete','visitdate'] - cols2 = ["num","name", "comment", 'rating','picsURL','picsLocalpath','source','date', - 'address','dictPostComplete','visitdate'] + #cols = ["name", "comment", 'rating','picsURL','picsLocalpath','source','date','address', + # 'dictPostComplete','visitdate'] + #cols2 = ["num","name", "comment", 'rating','picsURL','picsLocalpath','source','date', + # 'address','dictPostComplete','visitdate'] #df = pd.DataFrame(local_outputs["xls"], columns=cols) # df = pd.DataFrame(local_outputs['xlsdf']) df = pd.DataFrame(local_outputs['xlsdf'].values, columns=column_list) - df2 = pd.DataFrame(local_outputs['posts']) + #df2 = pd.DataFrame(local_outputs['posts']) # print ('Dropped items not included in sync to database: ',df2.dropna(inplace=True)) # rows = list(data) # if env.needreversed: @@ -804,7 +805,7 @@ def check_wordpress_media(filename, headers): ################################################################################################## -def check_is_port_open(host, port): +def check_is_port_open(host): """ Checks if a port on a host is open. @@ -1341,6 +1342,7 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,local_o # .date() # except AttributeError as error: # print(" An error getting date occurred:", error) + visitdate = newdate.strftime("%b%Y") newdate = str(newdate) #formatting = '%b/%Y/%d' #specifify the formatting of the date_string. #newdate2 = dt.datetime.strptime(str(newdate), formatting).date() @@ -1974,7 +1976,7 @@ def process_reviews2(outputs): # if it has not... then process if (writtento["web"] == 0 or writtento["instagram"]==0 or writtento["facebook"]==0 or\ writtento["xtwitter"]==0 or writtento["yelp"]==0 or writtento["tiktok"]==0 or \ - writtento["threads"]==0 ) and (check_is_port_open(env.wpAPI, 443)) and (env.web \ + writtento["threads"]==0 ) and (check_is_port_open(env.wpAPI)) and (env.web \ or env.instagram or env.yelp or env.xtwitter or env.tiktok or env.facebook or \ env.threads or env.google)and (processrow.comment is not None) : if env.web and processrow.web is False or env.force_web_create is True: From 8a9c3e0b760e8c5bfe53e5c01fda43f3ba22e79c Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 26 Jun 2024 15:35:36 -0400 Subject: [PATCH 2/3] added test for visited date starting with string --- social.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/social.py b/social.py index 3ef55e1..e6cd77a 100644 --- a/social.py +++ b/social.py @@ -448,8 +448,11 @@ def get_google_data(driver, local_outputs): visitdate = data.find_element(By.CSS_SELECTOR, 'span.rsqaWe').text except NoSuchElementException : visitdate = "Unknown" - print(' Visited: ',visitdate) - newdate,newdate2,visitdate = get_wordpress_post_date_string(visitdate, datetime.now()) + print(' Visited: ',visitdate, visitdate[:1]) + if re.match('^[a-zA-Z]+', visitdate) is None: + #if visitdate[:1].isalpha: + newdate,newdate2,visitdate = get_wordpress_post_date_string(str(visitdate), str(datetime.now())) + print(' Visited altered to : ',visitdate) try: text = data.find_element(By.CSS_SELECTOR, 'div.MyEned').text except NoSuchElementException : From 2b33ff35c8be324101d33729259a035990314951 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 26 Jun 2024 16:02:27 -0400 Subject: [PATCH 3/3] fix visit date (seems to work) --- social.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/social.py b/social.py index e6cd77a..5ddb5bb 100644 --- a/social.py +++ b/social.py @@ -1597,37 +1597,37 @@ def get_wordpress_post_date_string(date_string, date): newdate = datetime.today() - date visitdate = newdate.strftime("%b%Y") else: - if "day" in date: + if "day" in date_string: tempdate = -(int(re.sub( r'[^0-9]','',date_string))) print ('Stuff - > ',tempdate) newdate = datetime.today() + relativedelta(days=tempdate) visitdate = newdate.strftime("%b%Y") else: - if "a week" in date: + if "a week" in date_string: newdate = datetime.today() - relativedelta(weeks= 1) visitdate = newdate.strftime("%b%Y") else: - if "week" in date: + if "week" in date_string: tempdate = -(int(re.sub( r'[^0-9]','',date_string))) print ('Stuff - > ',tempdate) newdate = datetime.today() + relativedelta(weeks= tempdate) visitdate = newdate.strftime("%b%Y") else: - if "a month" in date: + if "a month" in date_string: newdate = datetime.today() - relativedelta(months = 1) visitdate = newdate.strftime("%b%Y") else: - if "month" in date: + if "month" in date_string: tempdate = -int(re.sub( r'[^0-9]','',date_string)) print ('Stuff - > ',tempdate) newdate = datetime.today() + relativedelta(months = tempdate) visitdate = newdate.strftime("%b%Y") else: - if "a year" in date: + if "a year" in date_string: newdate = datetime.today() - relativedelta(years= 1) visitdate = newdate.strftime("%b%Y") else: - if "year" in date: + if "year" in date_string: try: tempdate = -int(re.sub( r'[^0-9]','',date_string)) print ('Stuff - > ',tempdate)