Memer Action - GitHub Action for Programmer Memes

📅 April 11, 2020 • 🕣 1 min read

blog13

TTLDR;

I created a small github action to greet contributors with random programmer memes

Bhupesh-V/memer-action - GitHub

View on GitHub Marketplace

Why ?

You can say thanks to contributors by greeting them with some programmer humour & btw almost everyone likes memes so having some fun while contributing to OpenSource would be great :)

Demo

Here is a sample of memer-action in action

How

The action was built using python, here is how the magic happens

import feedparser
import random
import os
import sys

HOST_URL = "https://www.reddit.com/r/ProgrammerHumor"


def getMeme(filter_posts="hot"):
    memelist = []
    memedict = {}
    f = feedparser.parse(f"{HOST_URL}/{filter_posts}.rss")
    for entry in f.entries:
        x = entry['content'][0]['value']
        img = x[x.find("https://i.redd.it"): x.find("link") - 3]
        if img != "":
            memedict["title"] = entry["title"]
            memedict["src"] = str(entry["link"])
            memedict["meme"] = img
            memelist.append(memedict)
        random.shuffle(memelist)
        return memelist[0]


def main():
    filter_by = os.environ["INPUT_FILTER"]
    if filter_by not in ["hot", "top", "new", "rising"]:
        sys.exit(0)
    meme = getMeme(filter_by)
    print(f"::set-output name=meme::{meme['meme']}")
    print(f"::set-output name=title::{meme['title']}")
    print(f"::set-output name=source::{meme['src']}")


if __name__ == "__main__":
    main()

The above script runs inside a docker container. Below are some of the resources that (I used) you can use to build you own actions using Python

have fun !!