Please note: The script is for learning purposes and not for any malicious intent
Please star project if you find it useful :)
- Posts a automated report each 1st of the month to my LinkedIn Profile using Github Actions (e.g If todays the 1 JAN 2021 it will post all public repos created in DEC 2020).
- The report contains the following:
- Name of project
- Description of project
- Link to project repository
- Additional functionality:
- Sends me a email report when I successfully create at least one public repository in the previous month.
- Emails me if I haven't at least created one project for the previous month with a current list of public repos for the year.
- Pandas: https://pypi.org/project/pandas/
- Request: https://pypi.org/project/requests/
- GitHub Script: https://github.com/marketplace/actions/github-script
def github_request():
github_request()
function makes a GET request from Github API for the details of my repository and returns its response object.
def create_dataframe(response):
create_dataframe()
then convert the response object into json object. To use the data effectively I converted the data into lists from json values( excluding any repos that are forked) to created a dataframe.
def display_repos(df):
def display_repos()
function is tasked to:- Sorting the dataframe in ascending order according using json key "Created_at"(i.e list newest public repository at the top of dataframe)
- Retrieves the current date then return the previous offset month value(e.g If todays the 1 JAN 2021 it will return 1 DEC 2020)
- Find any repo that was created from the previous months(e.g Find all repos in DEC)
each_repo = df.loc[df['Created_at'].dt.month==x.month].values
- If
each_repo.size
is 0 that means no public repository have been created for that specific month andfail_msg()
function is called.
def fail_msg(df,x):
fail_msg()
sends all infomation(personal message,current year repos etc.) to be written intofail.txt
to be used bysend_email()
to send an email to myself.
each_repo = df.loc[df['Created_at'].dt.month==x.month].values
-
If
each_repo.size
is greater than 0 then: -
All infomation(personal message,current months repos etc.) is written into
report.txt
to be used bysend_email()
to send an email to myself.
def linkedin_request(send_textfile):
- Lastely ,
linkedin_request()
function sends a request to share a post on my LinkedIn profile using mylinkedin_access_token
andid_urn
.
Please note: It's advise to use your own personal Linkedin profile as there are restrictions on newly created accounts.Please refer to the Troubleshoot section.
NB : If you plan to use your gmail account please use a app password instead of default password. To create app password :
-
To enter secrets details for email click on settings
- In the left sidebar, click Secrets.Add the following secrets :
SEND_TO
(enter email address)SEND_FROM
(enter email address i.e sending it to myself)MAIL_PASSWORD
(enter password)API
(Github personal access token)LINKEDIN_ACCESS_TOKEN
(Linkedin access token)LINKEDIN_ID_URN
(Linkedin URN id)
- Script should automatically run on the 1st of each month set by
cron
.Checkout
action was used for testing purposes (testing on push event).
name: LinkedIn post automation
on:
schedule:
- cron: "0 0 1 * *"
jobs:
LinkedInActions:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name : Run LinkedIn script
env:
SEND_TO: ${{secrets.SEND_TO}}
SEND_FROM: ${{secrets.SEND_FROM}}
MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
API: ${{secrets.API}}
LINKEDIN_ACCESS_TOKEN: ${{secrets.LINKEDIN_ACCESS_TOKEN}}
LINKEDIN_ID_URN: ${{secrets.LINKEDIN_ID_URN}}
run: |
pip install -r requirements.txt
python src/main.py $SEND_TO $SEND_FROM $MAIL_PASSWORD $API $LINKEDIN_ACCESS_TOKEN $LINKEDIN_ID_URN
You experience any issue with sending a email try:
If you are having trouble creating a Linkedin company page to get a access token please read