Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisAlejandro committed Sep 5, 2023
2 parents 7613311 + b0b84a0 commit ee56668
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 164 deletions.
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Changelog
============


1.1.3 (2023-09-05)
------------

Changed
~~~~~~~~~~~~

* Adding support for link embed in facebook and linkedin. [Luis Alejandro Martínez Faneyth]


1.1.2 (2023-09-03)
------------

Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
.. _GitHub actions: https://github.com/LuisAlejandro/agoras-actions
.. _full documentation: https://agoras.readthedocs.org

Current version: 1.1.2
Current version: 1.1.3

Agoras is a python utility that helps publish and delete posts on the most
popular social networks (twitter, facebook, instagram and linkedin).
Expand Down Expand Up @@ -122,6 +122,8 @@ This command allows you to publish a post in different social network.::
LinkedIn post ID to like, retweet or delete.
-st <text>, --status-text <text>
Text to be published.
-sl <link>, --status-link <link>
Link to be published.
-i1 <image url>, --status-image-url-1 <image url>
First image URL to be published.
-i2 <image url>, --status-image-url-2 <image url>
Expand Down
2 changes: 1 addition & 1 deletion README.short.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
.. _GitHub actions: https://github.com/LuisAlejandro/agoras-actions
.. _full documentation: https://agoras.readthedocs.org

Current version: 1.1.2
Current version: 1.1.3

Agoras is a python utility that helps publish and delete posts on the most
popular social networks (twitter, facebook, instagram and linkedin).
Expand Down
2 changes: 2 additions & 0 deletions USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ This command allows you to publish a post in different social network.::
LinkedIn post ID to like, retweet or delete.
-st <text>, --status-text <text>
Text to be published.
-sl <link>, --status-link <link>
Link to be published.
-i1 <image url>, --status-image-url-1 <image url>
First image URL to be published.
-i2 <image url>, --status-image-url-2 <image url>
Expand Down
2 changes: 1 addition & 1 deletion agoras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

__author__ = 'Luis Alejandro Martínez Faneyth'
__email__ = 'luis@luisalejandro.org'
__version__ = '1.1.2'
__version__ = '1.1.3'
__url__ = 'https://github.com/LuisAlejandro/agoras'
__description__ = ('A command line python utility to manage your social'
' networks (Twitter, Facebook, LinkedIn and Instagram)')
3 changes: 3 additions & 0 deletions agoras/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def commandline(argv=None):
publish_options.add_argument(
'-st', '--status-text', metavar='<text>',
help=('Text to be published.'))
publish_options.add_argument(
'-sl', '--status-link', metavar='<link>',
help=('Link to be published.'))
publish_options.add_argument(
'-i1', '--status-image-url-1', metavar='<image url>',
help=('First image URL to be published.'))
Expand Down
54 changes: 27 additions & 27 deletions agoras/core/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from agoras.core.utils import add_url_timestamp


def post(client, facebook_object_id, status_text,
def post(client, facebook_object_id, status_text, status_link,
status_image_url_1=None, status_image_url_2=None,
status_image_url_3=None, status_image_url_4=None):

Expand All @@ -49,8 +49,8 @@ def post(client, facebook_object_id, status_text,
status_image_url_3, status_image_url_4
]))

if not source_media and not status_text:
raise Exception('No --status-text or --status-image-url-1 provided.')
if not source_media and not status_text and not status_link:
raise Exception('No --status-text or --status-link or --status-image-url-1 provided.')

for imgurl in source_media:

Expand Down Expand Up @@ -81,12 +81,17 @@ def post(client, facebook_object_id, status_text,
})

data = {
'message': status_text,
'published': True,
}

if status_link:
data['link'] = status_link

if status_text:
data['message'] = status_text

if attached_media:
data['attached_media'] = json.dumps(attached_media)
data['attached_media'] = json.dumps(attached_media) # type: ignore

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

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

try:
status_image = item.enclosures[0].url
except Exception:
status_image = ''

count += 1
post(client, facebook_object_id, status_text, status_image)
post(client, facebook_object_id, status_title, status_link, status_image)


def random_from_feed(client, facebook_object_id, feed_url, max_post_age):
Expand Down Expand Up @@ -224,9 +228,8 @@ def random_from_feed(client, facebook_object_id, feed_url, max_post_age):

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

post(client, facebook_object_id, status_text, random_status_image)
post(client, facebook_object_id, status_title, status_link, random_status_image)


def schedule(client, facebook_object_id, google_sheets_id,
Expand All @@ -235,9 +238,7 @@ def schedule(client, facebook_object_id, google_sheets_id,

count = 0
newcontent = []
gspread_scope = [
'https://spreadsheets.google.com/feeds'
]
gspread_scope = ['https://spreadsheets.google.com/feeds']
account_info = {
'private_key': google_sheets_private_key,
'client_email': google_sheets_client_email,
Expand All @@ -255,12 +256,12 @@ def schedule(client, facebook_object_id, google_sheets_id,

for row in content:

status_text, status_image_url_1, status_image_url_2, \
status_text, status_link, status_image_url_1, status_image_url_2, \
status_image_url_3, status_image_url_4, \
date, hour, state = row

newcontent.append([
status_text, status_image_url_1, status_image_url_2,
status_text, status_link, status_image_url_1, status_image_url_2,
status_image_url_3, status_image_url_4,
date, hour, state
])
Expand All @@ -284,7 +285,7 @@ def schedule(client, facebook_object_id, google_sheets_id,

count += 1
newcontent[-1][-1] = 'published'
post(client, facebook_object_id, status_text,
post(client, facebook_object_id, status_text, status_link,
status_image_url_1, status_image_url_2,
status_image_url_3, status_image_url_4)

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

action = kwargs.get('action')
facebook_access_token = kwargs.get(
'facebook_access_token',
os.environ.get('FACEBOOK_ACCESS_TOKEN', None))
facebook_object_id = kwargs.get(
'facebook_object_id',
os.environ.get('FACEBOOK_OBJECT_ID', None))
facebook_access_token = kwargs.get('facebook_access_token', None) or \
os.environ.get('FACEBOOK_ACCESS_TOKEN', None)
facebook_object_id = kwargs.get('facebook_object_id', None) or \
os.environ.get('FACEBOOK_OBJECT_ID', None)
facebook_post_id = kwargs.get('facebook_post_id', None) or \
os.environ.get('FACEBOOK_POST_ID', None)
facebook_profile_id = kwargs.get(
'facebook_profile_id',
os.environ.get('FACEBOOK_PROFILE_ID', None))
status_text = kwargs.get('status_text', None) or \
os.environ.get('STATUS_TEXT', None)
facebook_profile_id = kwargs.get('facebook_profile_id', None) or \
os.environ.get('FACEBOOK_PROFILE_ID', None)
status_text = kwargs.get('status_text', '') or \
os.environ.get('STATUS_TEXT', '')
status_link = kwargs.get('status_link', '') or \
os.environ.get('STATUS_LINK', '')
status_image_url_1 = kwargs.get('status_image_url_1', None) or \
os.environ.get('STATUS_IMAGE_URL_1', None)
status_image_url_2 = kwargs.get('status_image_url_2', None) or \
Expand Down Expand Up @@ -347,7 +347,7 @@ def main(kwargs):
client = GraphAPI(access_token=facebook_access_token, version="14.0")

if action == 'post':
post(client, facebook_object_id, status_text,
post(client, facebook_object_id, status_text, status_link,
status_image_url_1, status_image_url_2,
status_image_url_3, status_image_url_4)
elif action == 'like':
Expand Down
36 changes: 17 additions & 19 deletions agoras/core/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from agoras.core.utils import add_url_timestamp


def post(client, instagram_object_id, status_text,
def post(client, instagram_object_id, status_text, status_link,
status_image_url_1=None, status_image_url_2=None,
status_image_url_3=None, status_image_url_4=None):

Expand Down Expand Up @@ -77,7 +77,7 @@ def post(client, instagram_object_id, status_text,
}

if not is_carousel_item:
image_data['caption'] = status_text
image_data['caption'] = f'{status_text} {status_link}'

time.sleep(random.randrange(5))
media = client.post_object(object_id=instagram_object_id,
Expand All @@ -89,7 +89,7 @@ def post(client, instagram_object_id, status_text,
carousel_data = {
'media_type': 'CAROUSEL',
'children': ','.join(attached_media),
'caption': status_text
'caption': f'{status_text} {status_link}'
}
time.sleep(random.randrange(5))
carousel = client.post_object(object_id=instagram_object_id,
Expand Down Expand Up @@ -161,15 +161,14 @@ def last_from_feed(client, instagram_object_id, feed_url,

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

try:
status_image = item.enclosures[0].url
except Exception:
status_image = ''

count += 1
post(client, instagram_object_id, status_text, status_image)
post(client, instagram_object_id, status_title, status_link, status_image)


def random_from_feed(client, instagram_object_id, feed_url, max_post_age):
Expand Down Expand Up @@ -216,9 +215,8 @@ def random_from_feed(client, instagram_object_id, feed_url, max_post_age):

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

post(client, instagram_object_id, status_text, random_status_image)
post(client, instagram_object_id, status_title, status_link, random_status_image)


def schedule(client, instagram_object_id, google_sheets_id,
Expand All @@ -245,12 +243,12 @@ def schedule(client, instagram_object_id, google_sheets_id,

for row in content:

status_text, status_image_url_1, status_image_url_2, \
status_text, status_link, status_image_url_1, status_image_url_2, \
status_image_url_3, status_image_url_4, \
date, hour, state = row

newcontent.append([
status_text, status_image_url_1, status_image_url_2,
status_text, status_link, status_image_url_1, status_image_url_2,
status_image_url_3, status_image_url_4,
date, hour, state
])
Expand All @@ -274,7 +272,7 @@ def schedule(client, instagram_object_id, google_sheets_id,

count += 1
newcontent[-1][-1] = 'published'
post(client, instagram_object_id, status_text,
post(client, instagram_object_id, status_text, status_link,
status_image_url_1, status_image_url_2,
status_image_url_3, status_image_url_4)

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

action = kwargs.get('action')
instagram_access_token = kwargs.get(
'instagram_access_token',
os.environ.get('INSTAGRAM_ACCESS_TOKEN', None))
instagram_object_id = kwargs.get(
'instagram_object_id',
os.environ.get('INSTAGRAM_OBJECT_ID', None))
instagram_access_token = kwargs.get('instagram_access_token', None) or \
os.environ.get('INSTAGRAM_ACCESS_TOKEN', None)
instagram_object_id = kwargs.get('instagram_object_id', None) or \
os.environ.get('INSTAGRAM_OBJECT_ID', None)
instagram_post_id = kwargs.get('instagram_post_id', None) or \
os.environ.get('INSTAGRAM_POST_ID', None)
status_text = kwargs.get('status_text', None) or \
os.environ.get('STATUS_TEXT', None)
status_text = kwargs.get('status_text', '') or \
os.environ.get('STATUS_TEXT', '')
status_link = kwargs.get('status_link', '') or \
os.environ.get('STATUS_LINK', '')
status_image_url_1 = kwargs.get('status_image_url_1', None) or \
os.environ.get('STATUS_IMAGE_URL_1', None)
status_image_url_2 = kwargs.get('status_image_url_2', None) or \
Expand Down Expand Up @@ -334,7 +332,7 @@ def main(kwargs):
client = GraphAPI(access_token=instagram_access_token, version="14.0")

if action == 'post':
post(client, instagram_object_id, status_text,
post(client, instagram_object_id, status_text, status_link,
status_image_url_1, status_image_url_2,
status_image_url_3, status_image_url_4)
elif action == 'like':
Expand Down
Loading

0 comments on commit ee56668

Please sign in to comment.