Everyone! Do you use "_Oha Yosoro !! __"? This is the first voice that motivates me to get up every morning. Maybe love live! I think I tweeted every morning before the Sunshine !! anime started. (Saturdays, Sundays, and holidays may not be convenient) You Watanabe is an angel. so cute.
Python 2.7.11 Raspberry Pi2 B Some knowledge of electronic circuits
The tact switch also has a proper orientation, so let's check it.
It's messy, Explain after numbering the legs of the tact switch Bottom left: No. 1 Bottom right: No. 2
https://bitbucket.org/nnsnodnb/raspi_morning_steady_tweeter/src
I'm pushing to BitBucket for the time being.
app.py
# coding: utf-8
import RPi.GPIO as GPIO
import tweepy
import time, signal, sys, random
from datetime import datetime
def handler(signum, frame):
print('Signal handler called with signal: ' + str(signum))
GPIO.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, handler)
def tweet():
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
tweet_text = ''
if random.randint(1, 7) == 7:
tweet_text = u'Good morning John! !!'
else:
tweet_text = u'Good morning Yosoro! !!'
api.update_status(tweet_text + '\n{0:%Y/%m/%d %H:%M:%S}'.format(datetime.now()) + u'Niyakashi got up')
GPIO.setmode(GPIO.BCM)
GPIO.setup(9, GPIO.IN)
before = 0
while True:
now = GPIO.input(9)
if before == 0 and now == 1:
tweet()
time.sleep(0.1)
before = now
Get CONSUMER_KEY etc. in advance! Also, this time, in response to the request of enthusiastic followers, "_Oha John __" will appear with a probability of 1/6.
First of all, I don't think that you will press the button continuously, but in consideration of the foolproof of duplicate tweets, I tried to tweet up to seconds.
I don't know which GPIO the infrared transmission LED was connected to at the time of this jumper code arrangement, I was sacrificed. If the shyness turns, it will be cured.
Recommended Posts