diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 26b06d4..a763ace 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -8,8 +8,11 @@ on: workflow_dispatch: jobs: - facebook_group: + test_post: runs-on: ubuntu-latest + strategy: + matrix: + target: [group, page] steps: - name: Checkout uses: actions/checkout@v4 @@ -17,28 +20,11 @@ jobs: - name: facebook-post-action uses: ./ with: - page_id: ${{ secrets.FACEBOOK_GROUP_ID }} + page_id: ${{ matrix.target == 'group' && secrets.FACEBOOK_GROUP_ID || secrets.FACEBOOK_PAGE_ID }} access_token: ${{ secrets.FACEBOOK_ACCESS_TOKEN }} message: | ${{ github.event.repository.name }} - ${{ github.ref_name }} - Group test successful - url: https://github.com/ReenigneArcher/facebook-post-action - fail_on_error: false - - facebook_page: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: facebook-post-action - uses: ./ - with: - page_id: ${{ secrets.FACEBOOK_PAGE_ID }} - access_token: ${{ secrets.FACEBOOK_ACCESS_TOKEN }} - message: | - ${{ github.event.repository.name }} - ${{ github.ref_name }} - - Page test successful + ${{ matrix.target == 'group' && 'Group' || 'Page' }} test successful url: https://github.com/ReenigneArcher/facebook-post-action + fail_on_error: ${{ matrix.target == 'group' && 'false' || 'true' }} diff --git a/HISTORY.md b/HISTORY.md deleted file mode 100644 index 59d0409..0000000 --- a/HISTORY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog - -## [1.0.0] - 2022-01-10 -### Other -- Initial Version diff --git a/facebook_post_action.py b/facebook_post_action.py index f80507d..27afdff 100644 --- a/facebook_post_action.py +++ b/facebook_post_action.py @@ -1,11 +1,11 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - +# standard imports import os -import requests import sys +# lib imports from dotenv import load_dotenv +import requests + load_dotenv() # inputs @@ -15,15 +15,19 @@ URL = os.getenv('INPUT_URL', None) FAIL_ON_ERROR = os.getenv('INPUT_FAIL_ON_ERROR', 'true') -FACEBOOK_API_END = 'https://graph.facebook.com/{0}/feed'.format(PAGE_ID) +FACEBOOK_API_END = f'https://graph.facebook.com/{PAGE_ID}/feed' if URL: - FACEBOOK_API_DATA = {'message': MESSAGE, - 'link': URL, - 'access_token': ACCESS_TOKEN} + FACEBOOK_API_DATA = { + 'message': MESSAGE, + 'link': URL, + 'access_token': ACCESS_TOKEN, + } else: - FACEBOOK_API_DATA = {'message': MESSAGE, - 'access_token': ACCESS_TOKEN} + FACEBOOK_API_DATA = { + 'message': MESSAGE, + 'access_token': ACCESS_TOKEN, + } r = requests.post(url=FACEBOOK_API_END, json=FACEBOOK_API_DATA) diff --git a/utils.py b/utils.py deleted file mode 100644 index caff181..0000000 --- a/utils.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import sys -from datetime import datetime -from urllib.parse import quote -from html.parser import HTMLParser - -if not sys.version_info < (3,): - unicode = str - basestring = str - - -def u(u_string): - """ - Convert a string to unicode working on both python 2 and 3. - - :param u_string: a string to convert to unicode. - - .. versionadded:: 0.1.5 - """ - if isinstance(u_string, unicode): - return u_string - return u_string.decode('utf-8') - - -def s(s_string): - """ - Convert a byte stream to string working on both python 2 and 3. - - :param s_string: a byte stream to convert to string. - - .. versionadded:: 0.1.5 - """ - if isinstance(s_string, bytes): - return s_string - return s_string.encode('utf-8') - - -def html_unescape(_string): - return HTMLParser().unescape(_string) - - -def escape(_string): - return quote(u(_string).encode(), safe='~') - - -def filter_json_index_by_year(json_index_content): - json_index_filtered = {} - current_year = int(datetime.now().strftime('%Y')) - for pid, data in json_index_content.items(): - post_date = datetime.strptime(data['date'][:-6], '%Y-%m-%dT%H:%M:%S') - post_year = int(post_date.strftime('%Y')) - if post_year >= (current_year - 2): - json_index_filtered[pid] = data - return json_index_filtered