Browse Source

Premier commit

master
Christophe SCAYA 4 years ago
commit
331a24aa5f
  1. 4
      Readme.md
  2. 29
      get_dates.py
  3. 21
      verif_sonnerie.py

4
Readme.md

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
### Projet python3 pour raspberry pi :
* Pour forcer la GPIO4 au démarrage, mettre la ligne suivante dans /boot/config.txt\
`gpio=4=op,dh`

29
get_dates.py

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
from ics import Calendar
import requests, arrow, logging
# VARIABLES
log_file = "logfile"
url = "https://0783636d.index-education.net/pronote/ical/Agenda.ics?icalsecurise=3972E4CB6D2FF1DE199B75C1969DC54C867D1CA9A09B1C797A0342D5A2749FD9695E01FD2EE008B66074C8A9C38FB737&version=2021.0.2.3&param=66683d31266f3d31"
dates_file = "./dates.txt"
logging.basicConfig(level=logging.INFO, filename=log_file, filemode="a+",format="%(asctime)-15s %(levelname)-8s %(message)s")
try:
c = Calendar(requests.get(url,proxies="").text)
e = list(c.timeline)
except Exception:
logging.error("Erreur lors de l'accès au calendrier ! script annulé")
exit()
try:
f = open(dates_file, "w")
for x in e:
if x.name.casefold() == "lire ensemble":
print(x.begin, file=f)
print(x.end, file=f)
f.close()
logging.info("Fichier mis à jour le {}".format(arrow.utcnow().to('Europe/Paris').format('YYYY-MM-DD HH:mm')))
except IOError:
logging.error("Erreur de lecture/ecriture")

21
verif_sonnerie.py

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
import arrow, time, logging
import RPi.GPIO as GPIO
logging.basicConfig(level=logging.INFO, filename="logfile", filemode="a+",format="%(asctime)-15s %(levelname)-8s %(message)s")
try:
file1 = open('/home/pi/dates.txt', 'r')
Lines = file1.readlines()
except IOError:
logging.error("Erreur de lecture")
exit()
for x in Lines:
if arrow.get(x).to('Europe/Paris').format('hh:mm') == arrow.utcnow().to('Europe/Paris').format('hh:mm'):
logging.info("Sonnerie déclenchée à {}".format(arrow.utcnow().to('Europe/Paris').format('HH:mm')))
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.output(7,GPIO.LOW)
time.sleep(1)
GPIO.output(7,GPIO.HIGH)
Loading…
Cancel
Save