1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
from mastodon import Mastodon
import time
import requests #pour URL Home assistant
import json
import picamera
'''
### A décommenter pour obtenir les tokens à la première utilisation
Mastodon.create_app(
'pytooterapp',
api_base_url = 'https://toot.fr',
to_file = 'pytooter_clientcred.secret'
)
'''
### Infos de connexion
mastodon.log_in(
'user@user.org',
'Motdepasse',
to_file = 'pytooter_usercred.secret'
)
t = time.strftime('%H:%M', time.localtime())
T = time.strftime('%d-%m', time.localtime())
### Parse Home assistant
##Etat du soleil (valeur true ou false)
soleil = requests.get('http://192.168.168...')
soleiljson = json.loads(soleil.text)
##Température abri (nombre à virgule)
temp = requests.get('http://192.168.168...')
tempjson = json.loads(temp.text)
### Prise photo
camera = picamera.PiCamera()
camera.resolution = (960, 1280)
camera.rotation = 270
camera.start_preview()
time.sleep(2)
camera.capture ('/home/pi/mastobot/' + str(t) + '.jpg')
camera.stop_preview()
### Evoi du toot
text = (u"Hello, I'm Koopa ! \nIt\'s " + str(t) + "\nTemp= " + str(tempjson["state"]))
image = '/home/pi/mastobot/' + str(t) + '.jpg'
video = '/home/pi/bot/last.mp4'
mimetype = "'mp4'"
media1 = mastodon.media_post('/home/pi/mastobot/' + str(t) + '.jpg')
media2 = mastodon.media_post(video, mime_type=mimetype)
mastodon.status_post( text, media_ids=media2 ) |
Partager