Skip to content

An automated task to inform my LinkedIn network what GitHub projects I'm working on each month

Notifications You must be signed in to change notification settings

Nkosinathi-Bonga-James-Mncube/Linkedin_post_automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Please note: The script is for learning purposes and not for any malicious intent

Please star project if you find it useful :)

LinkedIn_automation

  • 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.

Packages

Actions used


Table of contents

How it works

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)

On failure (i.e No new repositories have been created for the month)

 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 and fail_msg() function is called.
def fail_msg(df,x):
  • fail_msg() sends all infomation(personal message,current year repos etc.) to be written into fail.txt to be used by send_email() to send an email to myself.

On Success (i.e At least one repository has been created for the month)

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 by send_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 my linkedin_access_token and id_urn.

Installation

Create a Github Personal access token

Create a Linkedin token (Click on 'Create a app')

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.

Enter secrets

NB : If you plan to use your gmail account please use a app password instead of default password. To create app password :

  • 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)

Github action yaml

  • 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

Troubleshoot

Gmail

You experience any issue with sending a email try:

LinkedIn

If you are having trouble creating a Linkedin company page to get a access token please read

About

An automated task to inform my LinkedIn network what GitHub projects I'm working on each month

Topics

Resources

Stars

Watchers

Forks

Languages