Published © GPL3+

3D Printed Reddit Karma Counter

Raspberry Pi Zero fetches karma and displays it on a cute lil OLED.

IntermediateFull instructions provided624
3D Printed Reddit Karma Counter

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
Adafruit - MONOCHROME 0.96" 128X64 OLED GRAPHIC DISPLAY
×1
Adafruit 7 male to female jumper wires
×1
3D printer
white, black, red/orange PLA
×1
Machine Screw, M2
Machine Screw, M2
×4

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

White body

Thingiverse

3d printed parts required

Red Eyes

Black Body

Back

Schematics

Wiring

Star

StarFit

Code

Code

Python
If you have any ideas on how to improve my code please let me know it would be appreciated!
import board
import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
import time
import bs4 as bs
import urllib.request

def fetchKarma():
    req = urllib.request.Request('https://www.reddit.com/user/Squiddles1227', 
    headers={'User-Agent': 'Mozilla/5.0'})
    source = urllib.request.urlopen(req).read()

    soup = bs.BeautifulSoup(source, 'lxml')


    for span in soup.find_all('span', id='profile--id-card--highlight-tooltip--karma'):
        newKarma = span.text

    return newKarma

oled_reset = digitalio.DigitalInOut(board.D4)
WIDTH = 128
HEIGHT = 64
BORDER = 5

# Use for SPI
spi = board.SPI()
oled_cs = digitalio.DigitalInOut(board.D5)
oled_dc = digitalio.DigitalInOut(board.D6)
oled = adafruit_ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, oled_dc, oled_reset, oled_cs)

# Clear display.
oled.fill(0)
oled.show()

image = Image.new('1', (oled.width, oled.height))
im = Image.open("starFit.ppm").convert('1')

draw = ImageDraw.Draw(im)
font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSansBold.ttf', 21)

def loadingBar() :
    topX = 0
    topProgress = 0
    while topProgress < 127 :
        draw.point((topX,0), 255)
        oled.image(im)
        oled.show()
        topX += 1
        topProgress += 1
        time.sleep(.1)

        if topProgress == 127 :
            break

    rightSideProgress = 0
    rightSideY = 0
    while rightSideProgress < 64 :
        draw.point((127,rightSideY), 255)
        oled.image(im)
        oled.show()
        rightSideY += 1
        rightSideProgress += 1
        time.sleep(.1)

        if rightSideProgress == 64 :
            break

    bottomProgress = 0
    bottomX = 127
    while bottomProgress < 127 :
        draw.point((bottomX, 63), 255)
        oled.image(im)
        oled.show()
        bottomX -= 1
        bottomProgress += 1
        time.sleep(.1)

        if bottomProgress == 127 :
            break

    leftSideProgress = 0
    leftSideY = 63
    while leftSideProgress < 63 :
        draw.point((0, leftSideY), 255)
        oled.image(im)
        oled.show()
        leftSideY -= 1
        leftSideProgress += 1
        time.sleep(.1)

        if leftSideProgress == 63 :
            break

    # erase bar 

    topX = 0
    topProgress = 0
    while topProgress < 127 :
        draw.point((topX,0), 0)
        oled.image(im)
        oled.show()
        topX += 1
        topProgress += 1
        time.sleep(.1)

        if topProgress == 127 :
            break

    rightSideProgress = 0
    rightSideY = 0
    while rightSideProgress < 64 :
        draw.point((127,rightSideY), 0)
        oled.image(im)
        oled.show()
        rightSideY += 1
        rightSideProgress += 1
        time.sleep(.1)

        if rightSideProgress == 64 :
            break

    bottomProgress = 0
    bottomX = 127
    while bottomProgress < 127 :
        draw.point((bottomX, 63), 0)
        oled.image(im)
        oled.show()
        bottomX -= 1
        bottomProgress += 1
        time.sleep(.1)

        if bottomProgress == 127 :
            break

    leftSideProgress = 0
    leftSideY = 63
    while leftSideProgress < 63 :
        draw.point((0, leftSideY), 0)
        oled.image(im)
        oled.show()
        leftSideY -= 1
        leftSideProgress += 1
        time.sleep(.1)

        if leftSideProgress == 63 :
            break

i = 1
while i < 2 :
    draw.rectangle((54, 20, 128, 64), outline=0, fill=0)
    oled.show()
    draw.text((54, 20), str(fetchKarma()), font=font, fill=255)
    oled.image(im)
    oled.show()
    loadingBar()

Credits

Comments