add hackster basic project stats
This commit is contained in:
parent
da19d632dc
commit
874e879488
5 changed files with 16152 additions and 0 deletions
BIN
PyPortal_Hackster/Coin.wav
Normal file
BIN
PyPortal_Hackster/Coin.wav
Normal file
Binary file not shown.
6068
PyPortal_Hackster/fonts/Arial-12.bdf
Normal file
6068
PyPortal_Hackster/fonts/Arial-12.bdf
Normal file
File diff suppressed because it is too large
Load diff
10035
PyPortal_Hackster/fonts/Arial-Bold-24.bdf
Normal file
10035
PyPortal_Hackster/fonts/Arial-Bold-24.bdf
Normal file
File diff suppressed because it is too large
Load diff
49
PyPortal_Hackster/hackster.py
Normal file
49
PyPortal_Hackster/hackster.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import time
|
||||
import random
|
||||
import board
|
||||
from adafruit_pyportal import PyPortal
|
||||
|
||||
# Get wifi details and more from a secrets.py file
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
||||
raise
|
||||
|
||||
PROJECT_NAME = "3c92f0"
|
||||
|
||||
# Set up where we'll be fetching data from
|
||||
DATA_SOURCE = "https://api.hackster.io/v2/projects/"+PROJECT_NAME+"?"
|
||||
DATA_SOURCE += "client_id="+secrets['hackster_clientid']+"&client_secret="+secrets['hackster_secret']
|
||||
VIEWS_LOCATION = ['stats', 'views']
|
||||
LIKES_LOCATION = ['stats', 'respects']
|
||||
CAPTION = "http://www.hackster.com/project/"+PROJECT_NAME
|
||||
|
||||
# the current working directory (where this file is)
|
||||
cwd = ("/"+__file__).rsplit('/', 1)[0]
|
||||
pyportal = PyPortal(url=DATA_SOURCE, json_path=(LIKES_LOCATION, VIEWS_LOCATION),
|
||||
status_neopixel=board.NEOPIXEL,
|
||||
default_bg=cwd+"/hackster_background.bmp",
|
||||
text_font=cwd+"/fonts/Arial-Bold-24.bdf",
|
||||
text_position=((80, 75), (80, 145)),
|
||||
text_color=(0x0000FF, 0x000000),
|
||||
caption_text=CAPTION,
|
||||
caption_font=cwd+"/fonts/Arial-12.bdf",
|
||||
caption_position=(20, 200),
|
||||
caption_color=0x000000)
|
||||
|
||||
# track the last value so we can play a sound when it updates
|
||||
last_likes = 0
|
||||
|
||||
while True:
|
||||
try:
|
||||
likes, views = pyportal.fetch()
|
||||
print("Views", views, "Likes", likes)
|
||||
if last_likes < likes: # ooh it went up!
|
||||
print("New respect!")
|
||||
pyportal.play_file(cwd+"/coin.wav")
|
||||
last_likes = likes
|
||||
except RuntimeError as e:
|
||||
print("Some error occured, retrying! -", e)
|
||||
|
||||
time.sleep(60)
|
||||
BIN
PyPortal_Hackster/hackster_background.bmp
Normal file
BIN
PyPortal_Hackster/hackster_background.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
Loading…
Reference in a new issue