mirror of
https://github.com/alexellis/seeds2.git
synced 2022-05-09 04:08:56 +03:00
Initial
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
config.py
|
||||||
|
*.pyc
|
||||||
|
*.jpg
|
||||||
|
*.ttf
|
||||||
|
|
||||||
1
README.md
Normal file
1
README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://material.io/guidelines/resources/roboto-noto-fonts.html
|
||||||
6
cputemp.py
Normal file
6
cputemp.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class CpuTemp:
|
||||||
|
def read(self):
|
||||||
|
f = open("/sys/class/thermal/thermal_zone0/temp", "r")
|
||||||
|
val = float(f.read())
|
||||||
|
val = val / 1000.0
|
||||||
|
return "{0:.2f}".format(val)
|
||||||
44
main.py
Normal file
44
main.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import picamera
|
||||||
|
import io
|
||||||
|
import time
|
||||||
|
import tweepy
|
||||||
|
|
||||||
|
from config import config
|
||||||
|
from cputemp import CpuTemp
|
||||||
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
|
from tweeter import Tweeter
|
||||||
|
|
||||||
|
def read_image(preview_time):
|
||||||
|
stream = io.BytesIO()
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.start_preview()
|
||||||
|
camera.vflip = True
|
||||||
|
camera.hflip = True
|
||||||
|
camera.resolution = (1920, 1080)
|
||||||
|
# Camera warm-up time
|
||||||
|
time.sleep(preview_time)
|
||||||
|
camera.capture(stream, 'jpeg')
|
||||||
|
return stream
|
||||||
|
|
||||||
|
def watermark(filename, msg):
|
||||||
|
img = Image.open(filename)
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
font = ImageFont.truetype('roboto/Roboto-Regular.ttf', 36)
|
||||||
|
draw.text((10, 10), msg, (0, 0, 0), font=font)
|
||||||
|
img.save(filename)
|
||||||
|
|
||||||
|
if(__name__=="__main__"):
|
||||||
|
preview_time = 1
|
||||||
|
stream = read_image(preview_time)
|
||||||
|
|
||||||
|
filename = "image.jpg"
|
||||||
|
with open(filename, 'wb') as file:
|
||||||
|
file.write(stream.getvalue())
|
||||||
|
cpu = CpuTemp()
|
||||||
|
msg = "CPU temp: " + cpu.read() + "C"
|
||||||
|
watermark(filename, msg)
|
||||||
|
|
||||||
|
if config["tweet"] == True:
|
||||||
|
tweeter = Tweeter(config, tweepy)
|
||||||
|
tweeter.send(filename, "Internet of Seeds Mark II")
|
||||||
|
|
||||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
tweepy
|
||||||
|
picamera
|
||||||
|
pillow
|
||||||
5
seed-it.sh
Executable file
5
seed-it.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd /home/pi/seeds2/
|
||||||
|
python main.py
|
||||||
|
rm image.jpg
|
||||||
17
tweeter.py
Normal file
17
tweeter.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class Tweeter:
|
||||||
|
def __init__(self, config, tweepy):
|
||||||
|
self.tweepy = tweepy
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
def send(self, filename, status_text):
|
||||||
|
|
||||||
|
ckey = self.config["ckey"]
|
||||||
|
csecret = self.config["csecret"]
|
||||||
|
akey = self.config["akey"]
|
||||||
|
asecret = self.config["asecret"]
|
||||||
|
|
||||||
|
auth = self.tweepy.OAuthHandler(ckey, csecret)
|
||||||
|
auth.set_access_token(akey, asecret)
|
||||||
|
api = self.tweepy.API(auth)
|
||||||
|
api.update_with_media(filename, status=status_text)
|
||||||
|
|
||||||
Reference in New Issue
Block a user