mirror of
https://github.com/timberjoegithub/GoogleScrape.git
synced 2026-07-22 00:19:48 +00:00
fixing linting problems
This commit is contained in:
@@ -97,6 +97,11 @@ class Posts(Base):
|
|||||||
date = sqlalchemy.Column(sqlalchemy.String(length=64, collation="utf8"))
|
date = sqlalchemy.Column(sqlalchemy.String(length=64, collation="utf8"))
|
||||||
address = sqlalchemy.Column(sqlalchemy.String(length=256, collation="utf8"))
|
address = sqlalchemy.Column(sqlalchemy.String(length=256, collation="utf8"))
|
||||||
dictPostComplete = sqlalchemy.Column(sqlalchemy.String(length=128, collation="utf8"))
|
dictPostComplete = sqlalchemy.Column(sqlalchemy.String(length=128, collation="utf8"))
|
||||||
|
googleurl = sqlalchemy.Column(sqlalchemy.String(length=128, collation="utf8"))
|
||||||
|
weburl = sqlalchemy.Column(sqlalchemy.String(length=128, collation="utf8"))
|
||||||
|
businessurl = sqlalchemy.Column(sqlalchemy.String(length=128, collation="utf8"))
|
||||||
|
longitude = sqlalchemy.Column(sqlalchemy.Float())
|
||||||
|
latitude = sqlalchemy.Column(sqlalchemy.Float())
|
||||||
#active = sqlalchemy.Column(sqlalchemy.Boolean, default=True)
|
#active = sqlalchemy.Column(sqlalchemy.Boolean, default=True)
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
@@ -144,7 +149,7 @@ def authconnect():
|
|||||||
print(' Connecting to facebook ...')
|
print(' Connecting to facebook ...')
|
||||||
# page_id_1 = facebookpageID
|
# page_id_1 = facebookpageID
|
||||||
# facebook_access_token = 'paste-your-page-access-token-here'
|
# facebook_access_token = 'paste-your-page-access-token-here'
|
||||||
# image_url = 'https://graph.facebook.com/{}/photos'.format(page_id_1)
|
# image_url = 'https://graph.facebook.com/{}/photos'.formatting(page_id_1)
|
||||||
# image_location = 'http://image.careers-portal.co.za/f_output.jpg'
|
# image_location = 'http://image.careers-portal.co.za/f_output.jpg'
|
||||||
# img_payload = {
|
# img_payload = {
|
||||||
# 'message': msg,
|
# 'message': msg,
|
||||||
@@ -196,8 +201,8 @@ def post_facebook(title, content, date, rating, address, picslist, instasession)
|
|||||||
page_id_1 = env.facebookpageID
|
page_id_1 = env.facebookpageID
|
||||||
facebook_access_token = env.facebookpass
|
facebook_access_token = env.facebookpass
|
||||||
#facebook_access_token = 'paste-your-page-access-token-here'
|
#facebook_access_token = 'paste-your-page-access-token-here'
|
||||||
# image_url = 'https://graph.facebook.com/{}/feed'.format(page_id_1)
|
# image_url = 'https://graph.facebook.com/{}/feed'.formatting(page_id_1)
|
||||||
image_url = 'https://graph.facebook.com/{}/photos'.format(page_id_1)
|
image_url = 'https://graph.facebook.com/{}/photos'.formatting(page_id_1)
|
||||||
image_location = pics[0]
|
image_location = pics[0]
|
||||||
img_payload = {
|
img_payload = {
|
||||||
'message': content,
|
'message': content,
|
||||||
@@ -338,7 +343,7 @@ def post_facebook3(title, content, date, rating, address, picslist, instasession
|
|||||||
|
|
||||||
def get_data(driver,outputs ):
|
def get_data(driver,outputs ):
|
||||||
# curl -X GET -H 'Content-Type: application/json' -H "X-Goog-Api-Key: API_KEY" -H
|
# curl -X GET -H 'Content-Type: application/json' -H "X-Goog-Api-Key: API_KEY" -H
|
||||||
# "X-Goog-FieldMask: id,displayName,formattedAddress,plusCode"
|
# "X-Goog-FieldMask: id,displayName,formattingtedAddress,plusCode"
|
||||||
# https://places.googleapis.com/v1/places/ChIJj61dQgK6j4AR4GeTYWZsKWw #placeId #websiteUri
|
# https://places.googleapis.com/v1/places/ChIJj61dQgK6j4AR4GeTYWZsKWw #placeId #websiteUri
|
||||||
"""
|
"""
|
||||||
this function get main text, score, name
|
this function get main text, score, name
|
||||||
@@ -911,7 +916,7 @@ def post_x(title, content, date, rating, address, picslist, instasession):
|
|||||||
|
|
||||||
def post_to_wp(title, content, headers,date, rating,address, picslist):
|
def post_to_wp(title, content, headers,date, rating,address, picslist):
|
||||||
# post
|
# post
|
||||||
NewPost = False
|
newPost = False
|
||||||
#countreview = False
|
#countreview = False
|
||||||
addresshtml = re.sub(" ", ".",address)
|
addresshtml = re.sub(" ", ".",address)
|
||||||
googleadress = r"<a href=https://www.google.com/maps/dir/?api=1&destination="+\
|
googleadress = r"<a href=https://www.google.com/maps/dir/?api=1&destination="+\
|
||||||
@@ -923,47 +928,47 @@ def post_to_wp(title, content, headers,date, rating,address, picslist):
|
|||||||
pidchop = pic3.split(" ")
|
pidchop = pic3.split(" ")
|
||||||
linkslist=[]
|
linkslist=[]
|
||||||
print (' Figuring out date of Post : ',title)
|
print (' Figuring out date of Post : ',title)
|
||||||
format = '%b/%Y/%d' #specifify the format of the date_string.
|
formatting = '%b/%Y/%d' #specifify the formatting of the date_string.
|
||||||
date_string = date
|
date_string = date
|
||||||
if "a day" in date_string:
|
if "a day" in date_string:
|
||||||
date = dt.timedelta(days=-1)
|
date = dt.timedelta(days=-1)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() - date
|
newdate = datetime.today() - date
|
||||||
else:
|
else:
|
||||||
if "day" in date:
|
if "day" in date:
|
||||||
tempdate = -(int(re.sub( r'[^0-9]','',date_string)))
|
tempdate = -(int(re.sub( r'[^0-9]','',date_string)))
|
||||||
print ('Stuff - > ',tempdate)
|
print ('Stuff - > ',tempdate)
|
||||||
# date = dt.timedelta(days=tempdate)
|
# date = dt.timedelta(days=tempdate)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() + relativedelta(days=tempdate)
|
newdate = datetime.today() + relativedelta(days=tempdate)
|
||||||
else:
|
else:
|
||||||
if "a week" in date:
|
if "a week" in date:
|
||||||
# date = dt.timedelta(weeks= -1)
|
# date = dt.timedelta(weeks= -1)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() - relativedelta(weeks= -1)
|
newdate = datetime.today() - relativedelta(weeks= -1)
|
||||||
else:
|
else:
|
||||||
if "week" in date:
|
if "week" in date:
|
||||||
tempdate = -(int(re.sub( r'[^0-9]','',date_string)))
|
tempdate = -(int(re.sub( r'[^0-9]','',date_string)))
|
||||||
print ('Stuff - > ',tempdate)
|
print ('Stuff - > ',tempdate)
|
||||||
# date = dt.timedelta(weeks= tempdate)
|
# date = dt.timedelta(weeks= tempdate)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() + relativedelta(weeks= tempdate)
|
newdate = datetime.today() + relativedelta(weeks= tempdate)
|
||||||
else:
|
else:
|
||||||
if "a month" in date:
|
if "a month" in date:
|
||||||
# date = dt.timedelta(months= -1)
|
# date = dt.timedelta(months= -1)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() - relativedelta(months = -1)
|
newdate = datetime.today() - relativedelta(months = -1)
|
||||||
else:
|
else:
|
||||||
if "month" in date:
|
if "month" in date:
|
||||||
tempdate = -int(re.sub( r'[^0-9]','',date_string))
|
tempdate = -int(re.sub( r'[^0-9]','',date_string))
|
||||||
print ('Stuff - > ',tempdate)
|
print ('Stuff - > ',tempdate)
|
||||||
# date = dt.timedelta(months= tempdate)
|
# date = dt.timedelta(months= tempdate)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() + relativedelta(months = tempdate)
|
newdate = datetime.today() + relativedelta(months = tempdate)
|
||||||
else:
|
else:
|
||||||
if "a year" in date:
|
if "a year" in date:
|
||||||
# date = dt.timedelta(years= -1)
|
# date = dt.timedelta(years= -1)
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
newdate = datetime.today() - relativedelta(years= -1)
|
newdate = datetime.today() - relativedelta(years= -1)
|
||||||
else:
|
else:
|
||||||
if "year" in date:
|
if "year" in date:
|
||||||
@@ -976,22 +981,22 @@ def post_to_wp(title, content, headers,date, rating,address, picslist):
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(" An error getting date occurred:",error)
|
print(" An error getting date occurred:",error)
|
||||||
else:
|
else:
|
||||||
format = '%Y-%b-%d' #specifify the format of the date_string.
|
formatting = '%Y-%b-%d' #specifify the formatting of the date_string.
|
||||||
month = date[:3]
|
month = date[:3]
|
||||||
year = date[3:]
|
year = date[3:]
|
||||||
day = '01'
|
day = '01'
|
||||||
date_string = year+'-'+ month+'-'+day
|
date_string = year+'-'+ month+'-'+day
|
||||||
try:
|
try:
|
||||||
newdate = dt.datetime.strptime(date_string, format).date()
|
newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(" An error getting date occurred:",error)
|
print(" An error getting date occurred:",error)
|
||||||
# try:
|
# try:
|
||||||
# newdate = dt.datetime.strptime(date_string, format).date()
|
# newdate = dt.datetime.strptime(date_string, formatting).date()
|
||||||
# except Exception as error:
|
# except Exception as error:
|
||||||
# print(" An error getting date occurred:", type(error).c)
|
# print(" An error getting date occurred:", error)
|
||||||
newdate = str(newdate)
|
newdate = str(newdate)
|
||||||
#format = '%b/%Y/%d' #specifify the format of the date_string.
|
#formatting = '%b/%Y/%d' #specifify the formatting of the date_string.
|
||||||
#newdate2 = dt.datetime.strptime(str(newdate), format).date()
|
#newdate2 = dt.datetime.strptime(str(newdate), formatting).date()
|
||||||
dateparts = (str(newdate)).split("-")
|
dateparts = (str(newdate)).split("-")
|
||||||
dateparts2 = dateparts[2].split(" ")
|
dateparts2 = dateparts[2].split(" ")
|
||||||
#dateparts = dateparts2[0]
|
#dateparts = dateparts2[0]
|
||||||
@@ -1017,11 +1022,11 @@ def post_to_wp(title, content, headers,date, rating,address, picslist):
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
headers2 = headers
|
headers2 = headers
|
||||||
response = requests.post(env.wpAPOurl, json = post_data, headers=headers2)
|
response = requests.post(env.wpAPOurl, json = post_data, headers=headers2,timeout=30)
|
||||||
if response.status_code != 201:
|
if response.status_code != 201:
|
||||||
print ('Error: ',response, response.text)
|
print ('Error: ',response, response.text)
|
||||||
else:
|
else:
|
||||||
NewPost = True
|
newPost = True
|
||||||
post_id_json = response.json()
|
post_id_json = response.json()
|
||||||
post_id = post_id_json.get('id')
|
post_id = post_id_json.get('id')
|
||||||
print (' New post is has post_id = ',post_id)
|
print (' New post is has post_id = ',post_id)
|
||||||
@@ -1049,38 +1054,43 @@ def post_to_wp(title, content, headers,date, rating,address, picslist):
|
|||||||
"description": description
|
"description": description
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
image_response = requests.post(env.wpAPI + "/media", headers=headers, files=image)
|
image_response = requests.post(env.wpAPI + "/media", headers=headers, files=image,timeout=30)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(" An error uploading picture ' + picname+ ' occurred:", type(error).__name__) # An error occurred:
|
print(" An error uploading picture ' + picname+ ' occurred:", type(error).__name__)
|
||||||
if image_response.status_code != 201 :
|
if image_response.status_code != 201 :
|
||||||
print (' Error- Image ',picname,' was not successfully uploaded. response: ',image_response)
|
print (' Error- Image ',picname,' was not successfully uploaded. response: ', \
|
||||||
|
image_response)
|
||||||
else:
|
else:
|
||||||
PicDict=image_response.json()
|
pic_dic=image_response.json()
|
||||||
file_id= PicDict.get('id')
|
file_id= pic_dic.get('id')
|
||||||
link = PicDict.get('guid').get("rendered")
|
link = pic_dic.get('guid').get("rendered")
|
||||||
print (' ',picname,' was successfully uploaded to website with ID: ',file_id, link)
|
print (' ',picname,' was successfully uploaded to website with ID: ',file_id, link)
|
||||||
try:
|
try:
|
||||||
linksDict = {'file_id' : file_id , 'link' : link}
|
linksDict = {'file_id' : file_id , 'link' : link}
|
||||||
linkslist.append(linksDict)
|
linkslist.append(linksDict)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(" An error adding to dictionary " , file_id , link , " occurred:", type(error).__name__) # An error occurred:
|
print(" An error adding to dictionary " , file_id , link , " occurred:", \
|
||||||
|
type(error).__name__) # An error occurred:
|
||||||
else:
|
else:
|
||||||
print (' Photo ',picname,' was already in library and added to post with ID: ',file_id,' : ',link)
|
print (' Photo ',picname,' was already in library and added to post with ID: ', \
|
||||||
|
file_id,' : ',link)
|
||||||
try:
|
try:
|
||||||
image_response = requests.post(env.wpAPI + "/media/" + str(file_id), headers=headers, data={"post" : post_id})
|
image_response = requests.post(env.wpAPI + "/media/" + str(file_id), headers=headers, data={"post" : post_id},timeout=30)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print (' Error- Image ',picname,' was not attached to post. response: ',image_response+' '+error)
|
print (' Error- Image ',picname,' was not attached to post. response: ',image_response+' '+error)
|
||||||
try:
|
try:
|
||||||
post_response = requests.post(env.wpAPI + "/posts/" + str(post_id), headers=headers)
|
post_response = requests.post(env.wpAPI + "/posts/" + str(post_id), headers=headers,timeout=30)
|
||||||
if link in str(post_response.text):
|
if link in str(post_response.text):
|
||||||
print (' Image link for ', picname, 'already in content of post: ',post_id, post_response.text, link)
|
print (' Image link for ', picname, 'already in content of post: ' \
|
||||||
|
,post_id, post_response.text, link)
|
||||||
else:
|
else:
|
||||||
linkslist.append({'file_id' : file_id , 'link' : link})
|
linkslist.append({'file_id' : file_id , 'link' : link})
|
||||||
# countreview = True
|
# countreview = True
|
||||||
except Exception as error:
|
except BaseException as error:
|
||||||
print(" An error loading the metadata from the post " + post_response.title + ' occurred: '+type(error).__name__)
|
print(" An error loading the metadata from the post " + post_response.title + \
|
||||||
|
' occurred: '+type(error).__name__)
|
||||||
#ratinghtml = post_response.text
|
#ratinghtml = post_response.text
|
||||||
firstMP4 = True
|
first_MP4 = True
|
||||||
fmedia = {}
|
fmedia = {}
|
||||||
for piclink in linkslist:
|
for piclink in linkslist:
|
||||||
#for loop in linkslist:
|
#for loop in linkslist:
|
||||||
@@ -1088,14 +1098,16 @@ def post_to_wp(title, content, headers,date, rating,address, picslist):
|
|||||||
try:
|
try:
|
||||||
ext = piclink['link'].split( '.')[-1]
|
ext = piclink['link'].split( '.')[-1]
|
||||||
if ext == 'mp4':
|
if ext == 'mp4':
|
||||||
if firstMP4:
|
if first_MP4:
|
||||||
contentpics += '\n' +r'[evp_embed_video url="' + piclink['link'] + r'" autoplay="true"]'
|
contentpics += '\n' +r'[evp_embed_video url="' + piclink['link'] + \
|
||||||
firstMP4 = False
|
r'" autoplay="true"]'
|
||||||
|
first_MP4 = False
|
||||||
else:
|
else:
|
||||||
contentpics += '\n' +r'[evp_embed_video url="' + piclink['link'] + r'"]'
|
contentpics += '\n' +r'[evp_embed_video url="' + piclink['link'] + r'"]'
|
||||||
#[evp_embed_video url="http://example.com/wp-content/uploads/videos/vid1.mp4" autoplay="true"]
|
#[evp_embed_video url="http://example.com/wp-content/uploads/videos/vid1.mp4" autoplay="true"]
|
||||||
else:
|
else:
|
||||||
contentpics += '\n '+r'<div class="col-xs-4"><img id="'+str(file_id)+r'"' + r'src="' + piclink['link'] + r'"></div>'
|
contentpics += '\n '+r'<div class="col-xs-4"><img id="'+str(file_id)+r'"' + r'src="' + \
|
||||||
|
piclink['link'] + r'"></div>'
|
||||||
# fmedia.append = piclink{'file_id' }
|
# fmedia.append = piclink{'file_id' }
|
||||||
# contentpics += '\n '+r'<img src="'+ piclink['link'] + '> \n'
|
# contentpics += '\n '+r'<img src="'+ piclink['link'] + '> \n'
|
||||||
#contentpics += r'<img src="'+ piclink['link'] + r' alt="' + title +r'">' +'\n\n'
|
#contentpics += r'<img src="'+ piclink['link'] + r' alt="' + title +r'">' +'\n\n'
|
||||||
@@ -1108,11 +1120,12 @@ def post_to_wp(title, content, headers,date, rating,address, picslist):
|
|||||||
else:
|
else:
|
||||||
fmedia = file_id
|
fmedia = file_id
|
||||||
print ('featured_media2 = ',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)
|
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,timeout=30)
|
||||||
print (response_piclinks)
|
print (response_piclinks)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(" An error writing images to the post " + post_response.title + ' occurred:', type(error).__name__) # An error occurred')
|
print(" An error writing images to the post " + post_response.title + ' occurred:', \
|
||||||
return NewPost
|
type(error).__name__) # An error occurred')
|
||||||
|
return newPost
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
@@ -1120,8 +1133,8 @@ def make_video(inphotos):
|
|||||||
# Load the photos from the folder
|
# Load the photos from the folder
|
||||||
# Set the duration of each photo to 2 seconds
|
# Set the duration of each photo to 2 seconds
|
||||||
if inphotos:
|
if inphotos:
|
||||||
dir = inphotos[0].rsplit(r'/', 1)
|
directory = inphotos[0].rsplit(r'/', 1)
|
||||||
folder = dir[0]
|
folder = directory[0]
|
||||||
output = folder+"/montage.mp4"
|
output = folder+"/montage.mp4"
|
||||||
if not os.path.exists(output) and len(inphotos) >1:
|
if not os.path.exists(output) and len(inphotos) >1:
|
||||||
video = VideoFileClip(inphotos[0])
|
video = VideoFileClip(inphotos[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user