36
36
from agoras .core .utils import add_url_timestamp
37
37
38
38
39
- def post (client , facebook_object_id , status_text ,
39
+ def post (client , facebook_object_id , status_text , status_link ,
40
40
status_image_url_1 = None , status_image_url_2 = None ,
41
41
status_image_url_3 = None , status_image_url_4 = None ):
42
42
@@ -49,8 +49,8 @@ def post(client, facebook_object_id, status_text,
49
49
status_image_url_3 , status_image_url_4
50
50
]))
51
51
52
- if not source_media and not status_text :
53
- raise Exception ('No --status-text or --status-image-url-1 provided.' )
52
+ if not source_media and not status_text and not status_link :
53
+ raise Exception ('No --status-text or --status-link or --status- image-url-1 provided.' )
54
54
55
55
for imgurl in source_media :
56
56
@@ -81,12 +81,17 @@ def post(client, facebook_object_id, status_text,
81
81
})
82
82
83
83
data = {
84
- 'message' : status_text ,
85
84
'published' : True ,
86
85
}
87
86
87
+ if status_link :
88
+ data ['link' ] = status_link
89
+
90
+ if status_text :
91
+ data ['message' ] = status_text
92
+
88
93
if attached_media :
89
- data ['attached_media' ] = json .dumps (attached_media )
94
+ data ['attached_media' ] = json .dumps (attached_media ) # type: ignore
90
95
91
96
time .sleep (random .randrange (5 ))
92
97
request = client .post_object (object_id = facebook_object_id ,
@@ -169,15 +174,14 @@ def last_from_feed(client, facebook_object_id, feed_url,
169
174
170
175
status_link = add_url_timestamp (link , today .strftime ('%Y%m%d%H%M%S' )) if link else ''
171
176
status_title = unescape (title ) if title else ''
172
- status_text = '{0} {1}' .format (status_title , status_link )
173
177
174
178
try :
175
179
status_image = item .enclosures [0 ].url
176
180
except Exception :
177
181
status_image = ''
178
182
179
183
count += 1
180
- post (client , facebook_object_id , status_text , status_image )
184
+ post (client , facebook_object_id , status_title , status_link , status_image )
181
185
182
186
183
187
def random_from_feed (client , facebook_object_id , feed_url , max_post_age ):
@@ -224,9 +228,8 @@ def random_from_feed(client, facebook_object_id, feed_url, max_post_age):
224
228
225
229
status_link = add_url_timestamp (random_status_link , today .strftime ('%Y%m%d%H%M%S' )) if random_status_link else ''
226
230
status_title = unescape (random_status_title ) if random_status_title else ''
227
- status_text = '{0} {1}' .format (status_title , status_link )
228
231
229
- post (client , facebook_object_id , status_text , random_status_image )
232
+ post (client , facebook_object_id , status_title , status_link , random_status_image )
230
233
231
234
232
235
def schedule (client , facebook_object_id , google_sheets_id ,
@@ -235,9 +238,7 @@ def schedule(client, facebook_object_id, google_sheets_id,
235
238
236
239
count = 0
237
240
newcontent = []
238
- gspread_scope = [
239
- 'https://spreadsheets.google.com/feeds'
240
- ]
241
+ gspread_scope = ['https://spreadsheets.google.com/feeds' ]
241
242
account_info = {
242
243
'private_key' : google_sheets_private_key ,
243
244
'client_email' : google_sheets_client_email ,
@@ -255,12 +256,12 @@ def schedule(client, facebook_object_id, google_sheets_id,
255
256
256
257
for row in content :
257
258
258
- status_text , status_image_url_1 , status_image_url_2 , \
259
+ status_text , status_link , status_image_url_1 , status_image_url_2 , \
259
260
status_image_url_3 , status_image_url_4 , \
260
261
date , hour , state = row
261
262
262
263
newcontent .append ([
263
- status_text , status_image_url_1 , status_image_url_2 ,
264
+ status_text , status_link , status_image_url_1 , status_image_url_2 ,
264
265
status_image_url_3 , status_image_url_4 ,
265
266
date , hour , state
266
267
])
@@ -284,7 +285,7 @@ def schedule(client, facebook_object_id, google_sheets_id,
284
285
285
286
count += 1
286
287
newcontent [- 1 ][- 1 ] = 'published'
287
- post (client , facebook_object_id , status_text ,
288
+ post (client , facebook_object_id , status_text , status_link ,
288
289
status_image_url_1 , status_image_url_2 ,
289
290
status_image_url_3 , status_image_url_4 )
290
291
@@ -297,19 +298,18 @@ def schedule(client, facebook_object_id, google_sheets_id,
297
298
def main (kwargs ):
298
299
299
300
action = kwargs .get ('action' )
300
- facebook_access_token = kwargs .get (
301
- 'facebook_access_token' ,
302
- os .environ .get ('FACEBOOK_ACCESS_TOKEN' , None ))
303
- facebook_object_id = kwargs .get (
304
- 'facebook_object_id' ,
305
- os .environ .get ('FACEBOOK_OBJECT_ID' , None ))
301
+ facebook_access_token = kwargs .get ('facebook_access_token' , None ) or \
302
+ os .environ .get ('FACEBOOK_ACCESS_TOKEN' , None )
303
+ facebook_object_id = kwargs .get ('facebook_object_id' , None ) or \
304
+ os .environ .get ('FACEBOOK_OBJECT_ID' , None )
306
305
facebook_post_id = kwargs .get ('facebook_post_id' , None ) or \
307
306
os .environ .get ('FACEBOOK_POST_ID' , None )
308
- facebook_profile_id = kwargs .get (
309
- 'facebook_profile_id' ,
310
- os .environ .get ('FACEBOOK_PROFILE_ID' , None ))
311
- status_text = kwargs .get ('status_text' , None ) or \
312
- os .environ .get ('STATUS_TEXT' , None )
307
+ facebook_profile_id = kwargs .get ('facebook_profile_id' , None ) or \
308
+ os .environ .get ('FACEBOOK_PROFILE_ID' , None )
309
+ status_text = kwargs .get ('status_text' , '' ) or \
310
+ os .environ .get ('STATUS_TEXT' , '' )
311
+ status_link = kwargs .get ('status_link' , '' ) or \
312
+ os .environ .get ('STATUS_LINK' , '' )
313
313
status_image_url_1 = kwargs .get ('status_image_url_1' , None ) or \
314
314
os .environ .get ('STATUS_IMAGE_URL_1' , None )
315
315
status_image_url_2 = kwargs .get ('status_image_url_2' , None ) or \
@@ -347,7 +347,7 @@ def main(kwargs):
347
347
client = GraphAPI (access_token = facebook_access_token , version = "14.0" )
348
348
349
349
if action == 'post' :
350
- post (client , facebook_object_id , status_text ,
350
+ post (client , facebook_object_id , status_text , status_link ,
351
351
status_image_url_1 , status_image_url_2 ,
352
352
status_image_url_3 , status_image_url_4 )
353
353
elif action == 'like' :
0 commit comments