![Page 1: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/1.jpg)
Raspberry PiCreative Technologists
SheffieldJuly 2015
![Page 2: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/2.jpg)
Self-directed workshop
● Use the Terminal (command line interface)● Install software (apt and pip)● Use the web browser (that's where the good stuff is)● Use GitHub (download projects, upload your own)● Use APIs (Application Programming Interfaces)● Ask questions!● Take notes!● Expand your understanding!● Ask for help!
![Page 3: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/3.jpg)
Connect the camera
![Page 4: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/4.jpg)
Boot the Pi and log in
![Page 5: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/5.jpg)
Test the camera
● raspistill -k
● If it doesn't work, is your camera connected correctly?● Is your camera enabled?
– sudo raspi-config– Enable camera
● Press Ctrl + C to exit the preview
![Page 6: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/6.jpg)
Browse my project on GitHub
● Open the web browser● Go to https://github.com/bennuttall/bett-bot● Read the instructions● Do the instructions:
– Install pip– Install flask– Download the repo– Install twython
![Page 7: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/7.jpg)
Run the app
● Enter the bett-bott folder– cd bett-bott
● Run the app– python app.py
● Open 127.0.0.1:5000 in the web browser● Click Capture to take a photo● See the photo in the gallery● Click the photo● Take more photos● Find your IP address (e.g. 192.168.1.8)
– hostname -I● Browse to http://192.168.1.8:5000 on your phone/tablet/laptop
![Page 8: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/8.jpg)
Connect to Twitter
● Log in to www.twitter.com in the web browser (or sign up)● Go to apps.twitter.com
– Create new app– Set permissions to read and write– Generate access tokens
(see Tweeting Babbage resource on raspberrypi.org for detailed instructions)– raspberrypi.org/learning/tweeting-babbage/worksheet/
![Page 9: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/9.jpg)
Add your API keys
● Open auth.py with Python/IDLE● Add your keys
– consumer_key– consumer_secret– access_token– access_token_secret
● Run the app again– Open Terminal– cd bett-bot-master– python app.py
● Now you can tweet the pictures
![Page 10: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/10.jpg)
Look at the code
● Open app.py with Python/IDLE● What's it doing?
– Imports– Try/except– Connect to Twitter– Define routes
● /● /capture/● /view/● /tweet/
– Routes refer to HTML templates– Run Flask app
![Page 11: Picamera, Flask and the Twitter API Raspberry Pi workshop](https://reader030.vdocuments.us/reader030/viewer/2022020218/55c9a0b7bb61ebb0678b4765/html5/thumbnails/11.jpg)
Hack it
● Change the appearance● Add a feature● Think about more to do later – ideas?● Is a web app suitable?● What's possible? What's not?● Think about hardware installation● Think about touch screens