├── README.md ├── iot_print_server.py ├── print_tweets.py └── test_print.py /README.md: -------------------------------------------------------------------------------- 1 | # alexa-pi-printer 2 | A printer for Amazon Alexa using a Raspberry Pi and a thermal receipt printer 3 | -------------------------------------------------------------------------------- /iot_print_server.py: -------------------------------------------------------------------------------- 1 | #!flask/bin/python 2 | 3 | from flask import Flask, request 4 | from escpos.printer import Usb 5 | 6 | p = Usb(0x0416, 0x5011) 7 | app = Flask(__name__) 8 | 9 | #CREATE 'INDEX' PAGE 10 | @app.route('/') 11 | def index(): 12 | return 'Your Flask server is working!' 13 | 14 | #CREATE 'LIST' PAGE FOR PRINTING SHOPPING LIST 15 | @app.route('/list') 16 | def list(): 17 | 18 | #REQUEST DATA FROM WEBHOOKS 19 | content = request.get_data() 20 | 21 | #CONVERT RAW DATA TO STRING 22 | str_content = str(content) 23 | 24 | #DIVIDE DATA INTO SEPERATE LINES 25 | str_split = str_content.splitlines() 26 | 27 | #SEPERATE WORDS BY COMMA AND ADD TO A NEW LIST 28 | newlist = [] 29 | for word in str_split: 30 | word = word.split(',') 31 | newlist.extend(word) 32 | 33 | #REMOVE FORMATTING MARKS 34 | rmv_marks = [s.strip("b'") for s in newlist] 35 | 36 | #PRINT HEADER 37 | #print("Shopping List\n") 38 | p.text("Shopping List:\n") 39 | 40 | #ENUMERATE AND PRINT EACH ITEM IN LIST 41 | r = 1 42 | for x in rmv_marks: 43 | #print(str(r) + ". " + x + "\n") 44 | p.text(str(r) + ". " + x + "\n") 45 | r += 1 46 | 47 | return 'x' 48 | 49 | #CREATE 'TO DO' PAGE FOR PRINTING TO DO LIST 50 | @app.route('/todo') 51 | def list(): 52 | content = request.get_data() 53 | str_content = str(content) 54 | str_split = str_content.splitlines() 55 | newlist = [] 56 | for word in str_split: 57 | word = word.split(',') 58 | newlist.extend(word) 59 | rmv_marks = [s.strip("b'") for s in newlist] 60 | p.text("To Do List:\n") 61 | r = 1 62 | for x in rmv_marks: 63 | p.text(str(r) + ". " + x + "\n") 64 | r += 1 65 | return 'x' 66 | 67 | if __name__ == '__main__': 68 | app.run(debug=True, host='0.0.0.0') 69 | -------------------------------------------------------------------------------- /print_tweets.py: -------------------------------------------------------------------------------- 1 | #!flask/bin/python 2 | 3 | from flask import Flask, request 4 | from escpos.printer import Usb 5 | 6 | p = Usb(0x0416, 0x5011) 7 | app = Flask(__name__) 8 | 9 | #CREATE 'INDEX' PAGE 10 | @app.route('/') 11 | def index(): 12 | return 'Your Flask server is working!' 13 | 14 | #CREATE A "PAGE" CALLED "TWEETS" FOR PRINTING NEW TWEETS 15 | @app.route('/tweet') 16 | def tweet(): 17 | #CAPTURE "GET" DATA FROM IFTTT WEBOOKS 18 | tweet_raw = request.get_data() 19 | 20 | #CONVERT RAW DATA TO STRING 21 | tweet_content = str(tweet_raw) 22 | 23 | #DIVIDE DATA INTO SEPERATE LINES 24 | tweet_split = tweet_content.splitlines() 25 | 26 | #SEPERATE ITEMS BY SEMICOLON AND ADD TO A NEW LIST 27 | new_tweetlist = [] 28 | for word in tweet_split: 29 | word = word.split(';') 30 | new_tweetlist.extend(word) 31 | 32 | #REMOVE FORMATTING MARTKS 33 | rmv_marks = [s.strip("b'") for s in new_tweetlist] 34 | 35 | #LOOP THROUGH NEW LIST AND PRINT RESULTS 36 | print("New Tweet From:\n") 37 | p.text("New Tweet From:\n") 38 | 39 | #LOOP THROUGH NEW LIST AND PRINT RESULTS 40 | for x in rmv_marks: 41 | print (x + "\n") 42 | p.text(x + "\n") 43 | 44 | #RETURN RESULTS 45 | return(x) 46 | 47 | #RUN THE PROGRAM 48 | if __name__ == '__main__': 49 | app.run(debug=True, host='0.0.0.0') 50 | -------------------------------------------------------------------------------- /test_print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | from escpos.printer import Usb 3 | p = Usb(0x0416, 0x5011) 4 | p.text("Mini Alexa Pi Printer\n") 5 | p.close() 6 | --------------------------------------------------------------------------------