From 3e05188aeaaeaf14252c1596b0b4df94f40f2d91 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Sun, 16 Jun 2024 22:07:20 -0400 Subject: [PATCH] fixed socialpost function to work for everything --- social.py | 121 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 40 deletions(-) diff --git a/social.py b/social.py index c6f07f3..7c49802 100644 --- a/social.py +++ b/social.py @@ -1671,7 +1671,7 @@ def process_reviews2(outputs): except AttributeError as error : print ('Could not check to see post already exists',error) if len(outputs['postssession'].query(Posts).filter(Posts.name == processrow.name\ - ,Posts.web is True).all()) == 0: + ,Posts.web ==1).all()) == 0: if webcount < env.postsperrun: try: new_web_post=post_to_wordpress(processrow.name,processrow.comment\ @@ -1769,45 +1769,47 @@ def process_reviews2(outputs): else: print (' Facebook: Skipping posting for ',processrow.name,' previously written') if env.xtwitter: - #if writtento["xtwitter"] == 0: - # # if Posts.query.filter(Posts.name.xtwitter.op('!=')(1)).first() - tempval = len(outputs['postssession'].query(Posts).filter(Posts.name == processrow.name,Posts.xtwitter is True).all()) - print ('tempval: ',tempval) - if len(outputs['postssession'].query(Posts).filter(Posts.name == processrow.name,Posts.xtwitter is True).all())==0: - if xtwittercount < env.postsperrun: - try: - print(' Starting to generate xtwitter post') - NewxtwitterPost = post_to_x2(processrow.name, processrow.comment, processrow.date, processrow.rating, processrow.address, processrow.picsLocalpath,outputs['posts'],outputs ) - try: - print (' Start generating content to post to xtwitter') - writtento["xtwitter"] = 1 - processrow.dictPostComplete = str(writtento) - except AttributeError as error: - print(" An error occurred setting value to go into Excel file:", type(error).__name__) # An error occurred: - print (' Success Posting to xtwitter: '+processrow.name)# ',processrow.name, processrow.comment, headers,processrow.address, processrow.rating,processrow.dictPostComplete, processrow.picsLocalpath, temp3["web"] ) - if NewxtwitterPost: - xtwittercount +=1 - try: - print(' write to xls for xtwitter') - outputs['datawb'].save(env.xls) - print(' Successfully wrote to xls for xtwitter') - # outputs['postssession'].update('dictPostComplete = '+str(writtento)+' where name == '+processrow.name) - # outputs['postssession'].commit() - except AttributeError as error: - print(" An error occurred writing Excel file:", type(error).__name__) # An error occurred: - try: - print(' write to DB for xtwitter') - outputs['postssession'].query(Posts).filter(Posts.name == processrow.name).update({"xtwitter" : True}) - outputs['postssession'].commit() - print(' Successfully wrote to database') - except AttributeError as error: - print(" An error occurred writing database", type(error).__name__) - except AttributeError as error: - print (' Error writing xtwitter post : ',error,processrow.name, processrow.comment, outputs,processrow.date, processrow.rating,processrow.address, processrow.picsLocalpath, writtento["xtwitter"], type(error).__name__ ) - else: - print (' Exceeded the number of xtwitter posts per run, skipping', processrow.name) - else: - print (' Xtwitter: Skipping posting for ',processrow.name,' previously written') + xtwittercount = process_socials("xtwitter",processrow,"post_to_x2",xtwittercount, outputs) + # #if writtento["xtwitter"] == 0: + # # # if Posts.query.filter(Posts.name.xtwitter.op('!=')(1)).first() + # tempval = len(outputs['postssession'].query(Posts).filter(Posts.name == processrow.name,Posts.xtwitter is True).all()) + # print ('tempval: ',tempval) + # if len(outputs['postssession'].query(Posts).filter(Posts.name == processrow.name,Posts.xtwitter is True).all())==0: + # if xtwittercount < env.postsperrun: + # try: + # print(' Starting to generate xtwitter post') + # NewxtwitterPost = post_to_x2(processrow.name, processrow.comment, processrow.date, processrow.rating, processrow.address, processrow.picsLocalpath,outputs['posts'],outputs ) + # try: + # print (' Start generating content to post to xtwitter') + # writtento["xtwitter"] = 1 + # processrow.dictPostComplete = str(writtento) + # except AttributeError as error: + # print(" An error occurred setting value to go into Excel file:", type(error).__name__) # An error occurred: + # print (' Success Posting to xtwitter: '+processrow.name)# ',processrow.name, processrow.comment, headers,processrow.address, processrow.rating,processrow.dictPostComplete, processrow.picsLocalpath, temp3["web"] ) + # if NewxtwitterPost: + # xtwittercount +=1 + # try: + # print(' write to xls for xtwitter') + # outputs['datawb'].save(env.xls) + # print(' Successfully wrote to xls for xtwitter') + # # outputs['postssession'].update('dictPostComplete = '+str(writtento)+' where name == '+processrow.name) + # # outputs['postssession'].commit() + # except AttributeError as error: + # print(" An error occurred writing Excel file:", type(error).__name__) # An error occurred: + # try: + # print(' write to DB for xtwitter') + # outputs['postssession'].query(Posts).filter(Posts.name == processrow.name).update({"xtwitter" : True}) + # outputs['postssession'].commit() + # print(' Successfully wrote to database') + # except AttributeError as error: + # print(" An error occurred writing database", type(error).__name__) + # except AttributeError as error: + # print (' Error writing xtwitter post : ',error,processrow.name, processrow.comment, outputs,processrow.date, processrow.rating,processrow.address, processrow.picsLocalpath, writtento["xtwitter"], type(error).__name__ ) + # else: + # print (' Exceeded the number of xtwitter posts per run, skipping', processrow.name) + # else: + # print (' Xtwitter: Skipping posting for ',processrow.name,' previously written') + #post_to_x_example(title, content, date, rating, address, picslist, instasession) # else: # print ('Exceeded the number of posts per run, exiting') @@ -1817,6 +1819,45 @@ def process_reviews2(outputs): # socials('xtwitter',namedict,outputs,writtento, processrow,post_to_x_example) return #(outputs['web']) +def process_socials(social_name,social_post,sub_process,social_count, outputs): + writtento = (ast.literal_eval(social_post.dictPostComplete)) + if len(outputs['postssession'].query(Posts).filter(Posts.name == social_post.name,getattr(Posts, social_name) is True).all())==0: + if social_count < env.postsperrun: + try: + print(' Starting to generate ',social_name,' post') + new_social_post = eval(sub_process)(social_post.name, social_post.comment, social_post.date, social_post.rating, social_post.address, social_post.picsLocalpath,outputs['posts'],outputs ) + try: + print (' Start generating content to post to xtwitter') + writtento[social_name] = 1 + social_post.dictPostComplete = str(writtento) + except AttributeError as error: + print(" An error occurred setting value to go into Excel file:", type(error).__name__) # An error occurred: + print (' Success Posting to xtwitter: '+social_post.name)# ',social_post.name, social_post.comment, headers,social_post.address, social_post.rating,social_post.dictPostComplete, social_post.picsLocalpath, temp3["web"] ) + if new_social_post: + social_count +=1 + try: + print(' write to xls for :',social_name) + outputs['datawb'].save(env.xls) + print(' Successfully wrote to xls for social - ',social_name) + # outputs['postssession'].update('dictPostComplete = '+str(writtento)+' where name == '+social_post.name) + # outputs['postssession'].commit() + except AttributeError as error: + print(" An error occurred writing Excel file:", type(error).__name__) # An error occurred: + try: + print(' write to DB for Social - ',social_name) + outputs['postssession'].query(Posts).filter(Posts.name == social_post.name).update({social_name : True}) + outputs['postssession'].commit() + print(' Successfully wrote to database') + except AttributeError as error: + print(" An error occurred writing database", type(error).__name__) + except AttributeError as error: + print (' Error writing social - ',social_name,' post : ',error,social_post.name, social_post.comment, outputs,social_post.date, social_post.rating,social_post.address, social_post.picsLocalpath, writtento[social_name], type(error).__name__ ) + else: + print (' Exceeded the number of social - ',social_name,' posts per run, skipping', social_post.name) + else: + print (' ',social_name,': Skipping posting for ',social_post.name,' previously written') + return social_count + ################################################################################################## if __name__ == "__main__":