Skip to content

Commit ee56668

Browse files
committed
Merge branch 'release/1.1.3'
2 parents 7613311 + b0b84a0 commit ee56668

19 files changed

+308
-164
lines changed

HISTORY.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ Changelog
22
============
33

44

5+
1.1.3 (2023-09-05)
6+
------------
7+
8+
Changed
9+
~~~~~~~~~~~~
10+
11+
* Adding support for link embed in facebook and linkedin. [Luis Alejandro Martínez Faneyth]
12+
13+
514
1.1.2 (2023-09-03)
615
------------
716

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
.. _GitHub actions: https://github.com/LuisAlejandro/agoras-actions
4343
.. _full documentation: https://agoras.readthedocs.org
4444

45-
Current version: 1.1.2
45+
Current version: 1.1.3
4646

4747
Agoras is a python utility that helps publish and delete posts on the most
4848
popular social networks (twitter, facebook, instagram and linkedin).
@@ -122,6 +122,8 @@ This command allows you to publish a post in different social network.::
122122
LinkedIn post ID to like, retweet or delete.
123123
-st <text>, --status-text <text>
124124
Text to be published.
125+
-sl <link>, --status-link <link>
126+
Link to be published.
125127
-i1 <image url>, --status-image-url-1 <image url>
126128
First image URL to be published.
127129
-i2 <image url>, --status-image-url-2 <image url>

README.short.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
.. _GitHub actions: https://github.com/LuisAlejandro/agoras-actions
4343
.. _full documentation: https://agoras.readthedocs.org
4444

45-
Current version: 1.1.2
45+
Current version: 1.1.3
4646

4747
Agoras is a python utility that helps publish and delete posts on the most
4848
popular social networks (twitter, facebook, instagram and linkedin).

USAGE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ This command allows you to publish a post in different social network.::
5050
LinkedIn post ID to like, retweet or delete.
5151
-st <text>, --status-text <text>
5252
Text to be published.
53+
-sl <link>, --status-link <link>
54+
Link to be published.
5355
-i1 <image url>, --status-image-url-1 <image url>
5456
First image URL to be published.
5557
-i2 <image url>, --status-image-url-2 <image url>

agoras/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
__author__ = 'Luis Alejandro Martínez Faneyth'
2323
__email__ = '[email protected]'
24-
__version__ = '1.1.2'
24+
__version__ = '1.1.3'
2525
__url__ = 'https://github.com/LuisAlejandro/agoras'
2626
__description__ = ('A command line python utility to manage your social'
2727
' networks (Twitter, Facebook, LinkedIn and Instagram)')

agoras/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def commandline(argv=None):
137137
publish_options.add_argument(
138138
'-st', '--status-text', metavar='<text>',
139139
help=('Text to be published.'))
140+
publish_options.add_argument(
141+
'-sl', '--status-link', metavar='<link>',
142+
help=('Link to be published.'))
140143
publish_options.add_argument(
141144
'-i1', '--status-image-url-1', metavar='<image url>',
142145
help=('First image URL to be published.'))

agoras/core/facebook.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from agoras.core.utils import add_url_timestamp
3737

3838

39-
def post(client, facebook_object_id, status_text,
39+
def post(client, facebook_object_id, status_text, status_link,
4040
status_image_url_1=None, status_image_url_2=None,
4141
status_image_url_3=None, status_image_url_4=None):
4242

@@ -49,8 +49,8 @@ def post(client, facebook_object_id, status_text,
4949
status_image_url_3, status_image_url_4
5050
]))
5151

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.')
5454

5555
for imgurl in source_media:
5656

@@ -81,12 +81,17 @@ def post(client, facebook_object_id, status_text,
8181
})
8282

8383
data = {
84-
'message': status_text,
8584
'published': True,
8685
}
8786

87+
if status_link:
88+
data['link'] = status_link
89+
90+
if status_text:
91+
data['message'] = status_text
92+
8893
if attached_media:
89-
data['attached_media'] = json.dumps(attached_media)
94+
data['attached_media'] = json.dumps(attached_media) # type: ignore
9095

9196
time.sleep(random.randrange(5))
9297
request = client.post_object(object_id=facebook_object_id,
@@ -169,15 +174,14 @@ def last_from_feed(client, facebook_object_id, feed_url,
169174

170175
status_link = add_url_timestamp(link, today.strftime('%Y%m%d%H%M%S')) if link else ''
171176
status_title = unescape(title) if title else ''
172-
status_text = '{0} {1}'.format(status_title, status_link)
173177

174178
try:
175179
status_image = item.enclosures[0].url
176180
except Exception:
177181
status_image = ''
178182

179183
count += 1
180-
post(client, facebook_object_id, status_text, status_image)
184+
post(client, facebook_object_id, status_title, status_link, status_image)
181185

182186

183187
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):
224228

225229
status_link = add_url_timestamp(random_status_link, today.strftime('%Y%m%d%H%M%S')) if random_status_link else ''
226230
status_title = unescape(random_status_title) if random_status_title else ''
227-
status_text = '{0} {1}'.format(status_title, status_link)
228231

229-
post(client, facebook_object_id, status_text, random_status_image)
232+
post(client, facebook_object_id, status_title, status_link, random_status_image)
230233

231234

232235
def schedule(client, facebook_object_id, google_sheets_id,
@@ -235,9 +238,7 @@ def schedule(client, facebook_object_id, google_sheets_id,
235238

236239
count = 0
237240
newcontent = []
238-
gspread_scope = [
239-
'https://spreadsheets.google.com/feeds'
240-
]
241+
gspread_scope = ['https://spreadsheets.google.com/feeds']
241242
account_info = {
242243
'private_key': google_sheets_private_key,
243244
'client_email': google_sheets_client_email,
@@ -255,12 +256,12 @@ def schedule(client, facebook_object_id, google_sheets_id,
255256

256257
for row in content:
257258

258-
status_text, status_image_url_1, status_image_url_2, \
259+
status_text, status_link, status_image_url_1, status_image_url_2, \
259260
status_image_url_3, status_image_url_4, \
260261
date, hour, state = row
261262

262263
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,
264265
status_image_url_3, status_image_url_4,
265266
date, hour, state
266267
])
@@ -284,7 +285,7 @@ def schedule(client, facebook_object_id, google_sheets_id,
284285

285286
count += 1
286287
newcontent[-1][-1] = 'published'
287-
post(client, facebook_object_id, status_text,
288+
post(client, facebook_object_id, status_text, status_link,
288289
status_image_url_1, status_image_url_2,
289290
status_image_url_3, status_image_url_4)
290291

@@ -297,19 +298,18 @@ def schedule(client, facebook_object_id, google_sheets_id,
297298
def main(kwargs):
298299

299300
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)
306305
facebook_post_id = kwargs.get('facebook_post_id', None) or \
307306
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', '')
313313
status_image_url_1 = kwargs.get('status_image_url_1', None) or \
314314
os.environ.get('STATUS_IMAGE_URL_1', None)
315315
status_image_url_2 = kwargs.get('status_image_url_2', None) or \
@@ -347,7 +347,7 @@ def main(kwargs):
347347
client = GraphAPI(access_token=facebook_access_token, version="14.0")
348348

349349
if action == 'post':
350-
post(client, facebook_object_id, status_text,
350+
post(client, facebook_object_id, status_text, status_link,
351351
status_image_url_1, status_image_url_2,
352352
status_image_url_3, status_image_url_4)
353353
elif action == 'like':

agoras/core/instagram.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from agoras.core.utils import add_url_timestamp
3737

3838

39-
def post(client, instagram_object_id, status_text,
39+
def post(client, instagram_object_id, status_text, status_link,
4040
status_image_url_1=None, status_image_url_2=None,
4141
status_image_url_3=None, status_image_url_4=None):
4242

@@ -77,7 +77,7 @@ def post(client, instagram_object_id, status_text,
7777
}
7878

7979
if not is_carousel_item:
80-
image_data['caption'] = status_text
80+
image_data['caption'] = f'{status_text} {status_link}'
8181

8282
time.sleep(random.randrange(5))
8383
media = client.post_object(object_id=instagram_object_id,
@@ -89,7 +89,7 @@ def post(client, instagram_object_id, status_text,
8989
carousel_data = {
9090
'media_type': 'CAROUSEL',
9191
'children': ','.join(attached_media),
92-
'caption': status_text
92+
'caption': f'{status_text} {status_link}'
9393
}
9494
time.sleep(random.randrange(5))
9595
carousel = client.post_object(object_id=instagram_object_id,
@@ -161,15 +161,14 @@ def last_from_feed(client, instagram_object_id, feed_url,
161161

162162
status_link = add_url_timestamp(link, today.strftime('%Y%m%d%H%M%S')) if link else ''
163163
status_title = unescape(title) if title else ''
164-
status_text = '{0} {1}'.format(status_title, status_link)
165164

166165
try:
167166
status_image = item.enclosures[0].url
168167
except Exception:
169168
status_image = ''
170169

171170
count += 1
172-
post(client, instagram_object_id, status_text, status_image)
171+
post(client, instagram_object_id, status_title, status_link, status_image)
173172

174173

175174
def random_from_feed(client, instagram_object_id, feed_url, max_post_age):
@@ -216,9 +215,8 @@ def random_from_feed(client, instagram_object_id, feed_url, max_post_age):
216215

217216
status_link = add_url_timestamp(random_status_link, today.strftime('%Y%m%d%H%M%S')) if random_status_link else ''
218217
status_title = unescape(random_status_title) if random_status_title else ''
219-
status_text = '{0} {1}'.format(status_title, status_link)
220218

221-
post(client, instagram_object_id, status_text, random_status_image)
219+
post(client, instagram_object_id, status_title, status_link, random_status_image)
222220

223221

224222
def schedule(client, instagram_object_id, google_sheets_id,
@@ -245,12 +243,12 @@ def schedule(client, instagram_object_id, google_sheets_id,
245243

246244
for row in content:
247245

248-
status_text, status_image_url_1, status_image_url_2, \
246+
status_text, status_link, status_image_url_1, status_image_url_2, \
249247
status_image_url_3, status_image_url_4, \
250248
date, hour, state = row
251249

252250
newcontent.append([
253-
status_text, status_image_url_1, status_image_url_2,
251+
status_text, status_link, status_image_url_1, status_image_url_2,
254252
status_image_url_3, status_image_url_4,
255253
date, hour, state
256254
])
@@ -274,7 +272,7 @@ def schedule(client, instagram_object_id, google_sheets_id,
274272

275273
count += 1
276274
newcontent[-1][-1] = 'published'
277-
post(client, instagram_object_id, status_text,
275+
post(client, instagram_object_id, status_text, status_link,
278276
status_image_url_1, status_image_url_2,
279277
status_image_url_3, status_image_url_4)
280278

@@ -287,16 +285,16 @@ def schedule(client, instagram_object_id, google_sheets_id,
287285
def main(kwargs):
288286

289287
action = kwargs.get('action')
290-
instagram_access_token = kwargs.get(
291-
'instagram_access_token',
292-
os.environ.get('INSTAGRAM_ACCESS_TOKEN', None))
293-
instagram_object_id = kwargs.get(
294-
'instagram_object_id',
295-
os.environ.get('INSTAGRAM_OBJECT_ID', None))
288+
instagram_access_token = kwargs.get('instagram_access_token', None) or \
289+
os.environ.get('INSTAGRAM_ACCESS_TOKEN', None)
290+
instagram_object_id = kwargs.get('instagram_object_id', None) or \
291+
os.environ.get('INSTAGRAM_OBJECT_ID', None)
296292
instagram_post_id = kwargs.get('instagram_post_id', None) or \
297293
os.environ.get('INSTAGRAM_POST_ID', None)
298-
status_text = kwargs.get('status_text', None) or \
299-
os.environ.get('STATUS_TEXT', None)
294+
status_text = kwargs.get('status_text', '') or \
295+
os.environ.get('STATUS_TEXT', '')
296+
status_link = kwargs.get('status_link', '') or \
297+
os.environ.get('STATUS_LINK', '')
300298
status_image_url_1 = kwargs.get('status_image_url_1', None) or \
301299
os.environ.get('STATUS_IMAGE_URL_1', None)
302300
status_image_url_2 = kwargs.get('status_image_url_2', None) or \
@@ -334,7 +332,7 @@ def main(kwargs):
334332
client = GraphAPI(access_token=instagram_access_token, version="14.0")
335333

336334
if action == 'post':
337-
post(client, instagram_object_id, status_text,
335+
post(client, instagram_object_id, status_text, status_link,
338336
status_image_url_1, status_image_url_2,
339337
status_image_url_3, status_image_url_4)
340338
elif action == 'like':

0 commit comments

Comments
 (0)