そこで、物理的な Gmail 通知機能を作ろうとしました。330 オームの抵抗器と LED を使用して、未読メールがあるときに点滅させます。これは私が思っていたよりも厳しいことが証明されています。Pythonコードを実行しようとすると、この出力が引き続き表示されます。
raspi_gmail.py:34: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(PIN_mail, GPIO.OUT)
Traceback (most recent call last):
File "raspi_gmail.py", line 45, in <module>
newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
File "/usr/local/lib/python2.7/dist-packages/feedparser.py", line 356, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'fullcount'
これは私が使用しているコードで、資格情報はもちろん切り取られています。
from os.path import exists
import RPi.GPIO as GPIO, feedparser
GPIO.setmode(GPIO.BCM)
file=".unreadmail.txt"
# insert your username and password
USERNAME="[USERNAME]@gmail.com"
PASSWORD="[PASSWORD]"
# if .unreadmail.txt doesn't exists the script wont work
# the following lines check if the file exists and create it if needed
if exists(file) == False:
data = open(file, 'w')
data.write("0")
data.close()
# edit these two value depending on your pin wiring
PIN_mail=6
PIN_check=18
data = open(file, 'r')
status=int(data.read())
data.close()
GPIO.setup(PIN_mail, GPIO.OUT)
GPIO.setup(PIN_check, GPIO.OUT)
GPIO.output(PIN_check, False)
if status == 0:
GPIO.output(PIN_mail, True)
else:
GPIO.output(PIN_mail, False)
newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
# output on .unreadmail.txt and GPIO
data = open(file, 'w')
if newmails > 0:
GPIO.output(PIN_mail, False)
data.write("1")
else:
GPIO.output(PIN_mail, True)
data.write("0")
GPIO.output(PIN_check, True)
data.close()
何か助けていただければ幸いです。私はこの全体の初心者のようなものです。