示例#1
0
def main():
    p = argparse.ArgumentParser()
    p.add_argument('--posX', '-x', type=int, default=0, help="X position of the start of the text")
    p.add_argument('--posY', '-y', type=int, default=0, help="Y position of the start of the text")
    p.add_argument('--fsize', '-s',type=int , default=12, help="Font size to use for the text")
    p.add_argument('--rotation', '-r',type=int , default=0, help="Rotation one of 0, 90, 180, 270")
    p.add_argument('--invert', '-i', type=bool, default=False, help="Invert the display of the text")
    args = p.parse_args()
    args.content = "at some point I will figure out why this is a required variable but until then I'll just nail it up like this"

    with open('trains.xml') as fd:
         doc = xmltodict.parse(fd.read(), xml_attribs=True)

         iterCount = 0
         numDisplayed = 0

         if args.content:
            for iterCount in range(30):
                dest = doc['ActueleVertrekTijden']['VertrekkendeTrein'][iterCount]['EindBestemming']
                time = doc['ActueleVertrekTijden']['VertrekkendeTrein'][iterCount]['VertrekTijd']
                plat = doc['ActueleVertrekTijden']['VertrekkendeTrein'][iterCount]['VertrekSpoor']['#text']
                spc = "    "
                print(dest + spc + time[11:16] + spc + plat)
                if (dest == "Enkhuizen" and numDisplayed <= 1) or (dest == "Breda" and numDisplayed <= 1):
                    if dest == "Den Helder":
                        dest = "HDR"
                    elif dest == "Schagen":
                        dest = "SGN"
                    if numDisplayed == 0:
#                        Xpos = 0
#                        Ypos = 0
                        disp = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 1:
#                        Xpos = 25
#                        Ypos = 25
                        disp2 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    numDisplayed += 1
                    dest = str(dest)
#                    text = PapirusTextPos(False, rotation=args.rotation)
                    #text = PapirusTextPos(rotation=args.rotation)
#                    text.partial_update()
#                    text.AddText(disp, args.posX, args.posY, args.fsize, invert=args.invert)
                    text = PapirusTextPos(False, rotation=args.rotation)
                    text.AddText("Vertrek van de treinen\n\n", 10, 0, 13, Id="Header")
                    text.AddText(disp, 0, 20, 18, Id="opt1")
                    try:
                        disp2
                    except NameError:
                        disp2_exists = False
                    else:
                        disp2_exists = True
                    if disp2_exists == True:
                        text.AddText(disp2, 0, 40, 18, Id="opt2")
    if numDisplayed == 0:
	text = PapirusTextPos(False, rotation=args.rotation)
        text.AddText("Vertrek van de treinen\n\n", 10, 0, 13, Id="Header")
        text.AddText("Apparently there are no trains.", 0, 35, 18, Id="errtxt")
    text.WriteAll()
示例#2
0
def main():
    p = argparse.ArgumentParser()
    p.add_argument('--posX',
                   '-x',
                   type=int,
                   default=0,
                   help="X position of the start of the text")
    p.add_argument('--posY',
                   '-y',
                   type=int,
                   default=0,
                   help="Y position of the start of the text")
    p.add_argument('--fsize',
                   '-s',
                   type=int,
                   default=20,
                   help="Font size to use for the text")
    p.add_argument('--rotation',
                   '-r',
                   type=int,
                   default=0,
                   help="Rotation one of 0, 90, 180, 270")
    p.add_argument('--invert',
                   '-i',
                   type=bool,
                   default=False,
                   help="Invert the display of the text")
    args = p.parse_args()
    args.content = "at some point I will figure out why this is a required variable but until then I'll just nail it up like this"

    with open('trains.xml') as fd:
        doc = xmltodict.parse(fd.read(), xml_attribs=True)

        iterCount = 0
        numDisplayed = 0

        if args.content:
            for iterCount in range(30):
                dest = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['EindBestemming']
                time = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekTijd']
                plat = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekSpoor']['#text']

                if (dest == u"Den Helder"
                        and numDisplayed <= 1) or (dest == u"Schagen"
                                                   and numDisplayed <= 1):
                    numDisplayed += 1
                    disp = dest + " || " + time[
                        11:16] + " || " + "Platform " + plat
                    dest = str(dest)
                    text = PapirusTextPos(rotation=args.rotation)
                    text.AddText(disp,
                                 args.posX,
                                 args.posY,
                                 args.fsize,
                                 invert=args.invert)
示例#3
0
def main():
    p = argparse.ArgumentParser()
    #    p.add_argument('--posX', '-x', type=int, default=0, help="X position of the start of the text")
    #    p.add_argument('--posY', '-y', type=int, default=0, help="Y position of the start of the text")
    p.add_argument('--fsize',
                   '-s',
                   type=int,
                   default=11,
                   help="Font size to use for the text")
    p.add_argument('--rotation',
                   '-r',
                   type=int,
                   default=0,
                   help="Rotation one of 0, 90, 180, 270")
    p.add_argument('--invert',
                   '-i',
                   type=bool,
                   default=False,
                   help="Invert the display of the text")

    args = p.parse_args()
    args.content = "just f**k off"

    with open('trains.xml') as fd:
        doc = xmltodict.parse(fd.read(), xml_attribs=True)

        iterCount = 0
        numDisplayed = 0

        if args.content:
            for iterCount in range(30):
                dest = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['EindBestemming']
                time = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekTijd']
                plat = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekSpoor']['#text']
                spaces = " || "
                if (dest == u"Den Helder"
                        and numDisplayed <= 1) or (dest == u"Schagen"
                                                   and numDisplayed <= 1):
                    numDisplayed += 1
                    ##                  print dest, " || ", time[11:16], " || ", "Platform ", plat
                    disp = dest + " || " + time[
                        11:16] + " || " + "Platform " + plat
                    text = PapirusTextPos(rotation=args.rotation)
                    text.AddText(disp,
                                 args.posX,
                                 args.posY,
                                 args.fsize,
                                 invert=args.invert)
示例#4
0
class Item_List():

    items = []
    text = PapirusTextPos(False)
    items_per_screen = 0
    selected = 0
    bottom_window = 2

    def __init__(self, items, items_per_screen=3):
        self.items = items
        self.items_per_screen = items_per_screen
        self.draw_text()

    def draw_text(self):
        if self.selected > bottom_window:
            self.bottom_window += 1
        elif self.selected < bottom_window - 2:
            self.bottom_window -= 1

    def redraw_text(self, oldID, newID):
        self.text.UpdateText(oldID, self.items[oldID])
        self.text.UpdateText(newID, u"\u003E"+self.items[newID])
        self.text.WriteAll()

    def select_up(self):
        old = self.selected
        if self.selected > 0:
            self.selected = self.selected - 1
        self.redraw_text(old, self.selected)

    def select_down(self):
        old = self.selected
        if self.selected < len(self.items):
            self.selected = self.selected + 1
        self.redraw_text(old, self.selected)
示例#5
0
 def __init__(self, rotation=0):
     self.text = PapirusTextPos(False, rotation=rotation)
     self.text.AddText("",
                       x=0,
                       y=5,
                       size=36,
                       Id="title",
                       font_path=sans_font)
     self.text.AddText("",
                       x=7,
                       y=55,
                       size=16,
                       Id="body",
                       font_path=sans_font)
     self.text.AddText("",
                       x=7,
                       y=75,
                       size=16,
                       Id="footer",
                       font_path=sans_font)
示例#6
0
    def __init__(self):

        self.papi = PapirusTextPos(False)
        self.papi.Clear()

        self.papi.AddText("DATE:", 0, 0, Id="datetext")
        self.papi.AddText("00-00 00:00", 60, 0, Id="date-time")

        self.papi.AddText("TEMP:", 0, 20, Id="temptext")
        self.papi.AddText("00.000", 60, 20, Id="temp")

        self.papi.AddText("HUME:", 0, 40, Id="humtext")
        self.papi.AddText("00.000", 60, 40, Id="hum")

        self.papi.AddText("PRES:", 0, 60, Id="presstxt")
        self.papi.AddText("0000", 60, 60, Id="press")

        self.papi.AddText("Initializing", 0, 80, Id="ip")

        self.papi.WriteAll()
    def handle(self):
        page = PapirusTextPos(False)

        line = self.rfile.readline()
        while line != b'':
            log("line: " + repr(line))
            op = json.loads(line.decode('utf-8'))
            #import pdb; pdb.set_trace()
            self.invokeop(page, op)
            line = self.rfile.readline()

        log("finished with connection")
示例#8
0
class Screen:
    def __init__(self, rotation=0):
        self.text = PapirusTextPos(False, rotation=rotation)
        self.text.AddText("",
                          x=0,
                          y=5,
                          size=36,
                          Id="title",
                          font_path=sans_font)
        self.text.AddText("",
                          x=7,
                          y=55,
                          size=16,
                          Id="body",
                          font_path=sans_font)
        self.text.AddText("",
                          x=7,
                          y=75,
                          size=16,
                          Id="footer",
                          font_path=sans_font)

    def update_header(self, text):
        self.text.UpdateText("title", text, font_path=sans_font)

    def update_body(self, text):
        self.text.UpdateText("body", text, font_path=bold_sans_font)

    def update_footer(self, text):
        self.text.UpdateText("footer", text, font_path=bold_sans_font)

    def write(self):
        self.text.WriteAll()

    def clear(self):
        self.text.Clear()
示例#9
0
文件: aqi.py 项目: 00b/PaPriusAQI
#!/usr/bin/python

from __future__ import print_function
from datetime import date
from datetime import datetime
from papirus import PapirusTextPos
import calendar
import urllib, json

text = PapirusTextPos(False)
fontsize = 15

#info for AIRNow
AIRNOWAPIKEY = ""
LAT = "37.7749"
LONG = "-122.4194"

#set starting text position
YPOS = 0
XPOS = 0
#get the current AQI data
aqiurl = "http://www.airnowapi.org/aq/observation/latLong/current/?format=application/json&latitude=" + LAT + "&longitude=" + LONG + "&distance=25&API_KEY=" + AIRNOWAPIKEY
#uncomment to print URL to stdout (troubleshooting/debugging)
#print (aqiurl)

response = urllib.urlopen(aqiurl)
data = json.loads(response.read())

#Add text "AQI"  at top of display
#text.AddText('AQI',30,0,10,Id='title')
from twython import Twython, TwythonError
import time
import random
from random import randint
from random import choice
from time import sleep
from papirus import Papirus
from papirus import PapirusText
from papirus import PapirusTextPos

#configure papirus
text = PapirusTextPos(rotation=0)
screen = Papirus(rotation=0)

#Authorise
APP_KEY = 'hwtNGXTnCAjeUOgRveksZdESX'
APP_SECRET = '1YrUz3JLLD86AtwPorc4PVh1MZBUptrOnLEIeL4SWjjh1zMtma'
OAUTH_TOKEN = '20427648-Xx2mqMa0ANvyVheg8xagsrgh6sm3LtEuKUxuSylfR'
OAUTH_TOKEN_SECRET = 'KYoMPhcvq7iMOf0i9Y8p2TwDnyLbcCrPB78SNd9jRf51v'

#Prepare your twitter, you will need it for everything
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
#The above should just be a single line, without the break

#keywords for search query q
naughty_words = [
    " -RT", "MAGA", "Brexit", "Trump", "xxx", "p**n", "gay", "tory", "labour",
    "conservative", "brexit", "russia"
]
good_words = ["solarpv", "arduino", "ceramics", "raspberrypi"]
filter = " OR ".join(good_words)
示例#11
0
import time
import board
import busio
import adafruit_gps
import serial
import qrcode
from papirus import PapirusTextPos
import mariadb
import sys
import json

# setup for gps
uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=10)

# setup eInk display
text = PapirusTextPos(False)

# auth json file
auth = json.load(open('credentials.json'))
# keys
user = auth["user"]
passwd = auth["pass"]

# Connect to MariaDB Platform
try:
    conn = mariadb.connect(
        user=user,
        password=passwd,
        host="localhost",
        port=3306,
        database="munz"
示例#12
0
import datetime
from datetime import date, timedelta

from darksky import forecast
import textwrap

# set lat/long for location
LOCATION = 37.5396,127.0097 #put your longitude and latittude here in decimal degrees
UNITS = 'auto' #specify the units you want your results in here, see the Dark Sky API docs page for details

# set Darksky API Key
APIKEY= 'xxxxx' # put your Dark Sky API key here. Get one at https://darksky.net/dev

# For PaPiRus
screen = Papirus()
text = PapirusTextPos(True)

# tempFont = ImageFont.truetype('fonts/Aller_Bd.ttf', 22)
# dayFont = ImageFont.truetype('fonts/Roboto-Black.ttf', 18)
# dateFont = ImageFont.truetype('fonts/Roboto-Bold.ttf', 14)
# font = ImageFont.truetype('fonts/ElecSign.ttf', 10)
# smallFont = ImageFont.truetype('fonts/ElecSign.ttf', 8)
# smallestFont = ImageFont.truetype('fonts/ElecSign.ttf', 7)

def display():
    with forecast (APIKEY, *LOCATION, units=UNITS) as location:
        # today
        currentTemp = location['currently']['temperature']
        upcoming_conditions = location['currently']['summary']
        relativeHumidity = location['currently']['humidity']
        daily_conditions = location['daily']['data'][0]['summary']
示例#13
0
#!/usr/bin/python
# Weather forecast for Raspberry Pi W with PaPiRus hat.
# Retrieves data from DarkSky.net's API, prints current conditions and
# Adapted from Adafruit Industries Python-Thermal-Printer forecast.py
# https://github.com/adafruit/Python-Thermal-Printer/blob/master/forecast.py
# MIT license.
#

from __future__ import print_function
from datetime import date
from datetime import datetime
from papirus import PapirusTextPos
import calendar
import urllib, json

text = PapirusTextPos(False)
fontsize = 10

#Dark Sky API Key goes here
API_KEY = "XXX"

#Put your location here
LAT = "37.5396"
LONG = "127.0097"


def forecast(idx):

    date = datetime.fromtimestamp(int(data['daily']['data'][idx]['time']))

    day = calendar.day_name[date.weekday()]
示例#14
0
def main():
    p = argparse.ArgumentParser()
    p.add_argument('--posX',
                   '-x',
                   type=int,
                   default=0,
                   help="X position of the start of the text")
    p.add_argument('--posY',
                   '-y',
                   type=int,
                   default=0,
                   help="Y position of the start of the text")
    p.add_argument('--fsize',
                   '-s',
                   type=int,
                   default=12,
                   help="Font size to use for the text")
    p.add_argument('--rotation',
                   '-r',
                   type=int,
                   default=0,
                   help="Rotation one of 0, 90, 180, 270")
    p.add_argument('--invert',
                   '-i',
                   type=bool,
                   default=False,
                   help="Invert the display of the text")
    args = p.parse_args()
    args.content = " "

    with open('/tmp/trains.xml') as fd:
        doc = xmltodict.parse(fd.read(), xml_attribs=True)

        iterCount = 0
        numDisplayed = 0

        ## CONFIGURABLE ITEM
        ## Depending on the time of day, and the size of your station, there will
        ## be a varying number of results returned in the 'trains.xml' file. If
        ## range(VALUE) exceeds the number of results contained in the file, the
        ## script will die. I realize that this sucks, and I will work on fixing
        ## it. For now, set the range(VALUE) to something that works for you.
        ## 30 seems to be safe for Amsterdam Centraal most of the time.
        #for iterCount in range(0, len(doc), not_fucked_up=True, dont_always_return_1=True):
        if args.content:
            for iterCount in range(30):
                ## I'm only grabbing the end station, departure time, and
                ## departure platform at start station to display.
                ## There are more things you can retrieve-- paw through trains.xml
                ## +read xmltodict docs to understand how to retrieve them.
                ## I found this page useful:
                ## http://omz-software.com/pythonista/docs/ios/xmltodict.html
                dest = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['EindBestemming']
                time = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekTijd']
                plat = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekSpoor']['#text']
                spc = "    "

                print(dest + spc + time[11:16] + spc +
                      plat)  ## print each row on CLI

                ## CONFIGURABLE ITEM
                ## Currently the script outputs the next four trains matching your
                ## destination. Reduce the max value on both below checks of
                ## numDisplayed to get fewer results.
                if (dest == destStation1
                        and numDisplayed <= 3) or (dest == destStation2
                                                   and numDisplayed <= 3):
                    ## Shortening names to 3-letter codes to fit screen.
                    ## I *may* automate and elegantize this later.
                    if dest == "Schagen":
                        dest = "SGN"
                        print("!! HIT")  ## flagging matches on CLI for debug
                    elif dest == "Den Helder":
                        dest = "HLD"
                        print("!! HIT")  ## flagging matches on CLI for debug
                    ## save each extracted row to its own variable because
                    ## I can't quite grasp how to do this better.
                    if numDisplayed == 0:
                        ## chars [11:16] is where the time lives.
                        ## the raw var contains e.g.
                        ## 2017-07-01T21:07:00+0200
                        disp = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 1:
                        disp2 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 2:
                        disp3 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 3:
                        disp4 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    numDisplayed += 1
                    #                    dest = str(dest)
                    #initialize screen buffer var "text" without displaying anything
                    text = PapirusTextPos(False, rotation=args.rotation)
                    #Append the first bit of text to the screen buffer, top centered.
                    #X position 12, Y position 0, font size 13, Id="Header"
                    #text.AddText("Text", Xpos, Xpos, fontSize, Id="freeformElementID")
                    text.AddText("Vertrek van de treinen",
                                 12,
                                 0,
                                 13,
                                 Id="Header")
                    text.AddText(disp, 0, 19, 18, Id="opt1")

                    ## The next three stanzas are merely an attempt to gracefully
                    ## handle fewer than the maximum allowed number of results.
                    ## The results, if they exist, are presented roughly centered
                    ## in a stack starting from the top, as you can see from the
                    ## increasing Y values in text.AddText.
                    try:
                        disp2
                    except NameError:
                        disp2_exists = False
                    else:
                        disp2_exists = True
                    if disp2_exists == True:
                        text.AddText(disp2, 0, 39, 18, Id="opt2")

                    try:
                        disp3
                    except NameError:
                        disp3_exists = False
                    else:
                        disp3_exists = True
                    if disp3_exists == True:
                        text.AddText(disp3, 0, 59, 18, Id="opt3")

                    try:
                        disp4
                    except NameError:
                        disp4_exists = False
                    else:
                        disp4_exists = True
                    if disp4_exists == True:
                        text.AddText(disp3, 0, 79, 18, Id="opt4")

    ## Exception handling. If we got all the way here and there was
    ## nothing to display, print something on the screen and the CLI
    ## to alert the user.
    if numDisplayed == 0:
        print(
            "\nNo hits for configured stations. Assuming disruption. Exception handler goes here."
        )
        text = PapirusTextPos(False, rotation=args.rotation)
        text.AddText("Vertrek van de treinen\n\n", 10, 0, 13, Id="Header")
        ## this is the small Choo-Choo #404 from above, appearing
        ## shortly on your PaPiRus :)
        text.AddText(train6, 87, 15, 13, Id="train6")
        text.AddText(train7, 28, 27, 13, Id="train7")
        text.AddText(train8, 20, 40, 13, Id="train8")
        text.AddText(train9, 15, 53, 13, Id="train9")
        #        text.AddText("Apparently there", 15, 35, 18, Id="errtxt1")
        #        text.AddText("are no trains.", 25, 55, 18, Id="errtxt2")
        text.AddText("Apparently there are no trains", 8, 80, 10, Id="errtxt")
        ## And here's another Choo-Choo #404 to keep your terminal company
        print(train1)
        print(train2)
        print(train3)
        print(train4)
        print(train5 + "\n")

    ## Finally, the grand finale! Up until now, every text.AddText()
    ## operation was merely adding data to the buffer for the screen,
    ## not actually displaying it. text.WriteAll() dumps everything
    ## to the screen all at once, as befits an ePaper display. We
    ## only have to call this once per run of the entire script,
    # which is why it's at the end. d3rp.
    text.WriteAll()
示例#15
0
#!/usr/bin/env python3
from netifaces import interfaces, ifaddresses, AF_INET
from papirus import PapirusTextPos
from datetime import datetime
import subprocess
import socket
import re
import time
console_display = False
inv = False
text = PapirusTextPos(False, 0)
text.Clear()
text.autoUpdate = False
text.partialUpdates = True
font_size = 15
vert_spacing = font_size + 1
cur_time = datetime.now()
text_time = cur_time.strftime('%Y/%m/%d %I:%M:%S')
disp_text = "web - http://secure.pi"
if console_display: print(disp_text)
text.AddText(disp_text, 0, vert_spacing * 0, font_size, Id="web")
disp_text = "wifi- "
if console_display: print(disp_text)
text.AddText(disp_text, 0, vert_spacing * 1, font_size, Id="wifi")
disp_text = "wlan- "
if console_display: print(disp_text)
text.AddText(disp_text, 0, vert_spacing * 2, font_size, Id="wlan0")
disp_text = "wan - "
if console_display: print(disp_text)
text.AddText(disp_text, 0, vert_spacing * 3, font_size, Id="Pub")
disp_text = "VPN is "
示例#16
0
    def handle_data(self, data):
        # Take the contents of the first <pre> section.
        if not self.is_pre:
            return

        if self.pre_data is None:
            self.pre_data = data
        elif data.rstrip():
            print("Warn: found multiple non-empty <pre> sections")

    def error(self, message):
        print("Parsing error: {}".format(message))
        exit(1)


if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        # Display abnormal errors, but not SystemExit or KeyboardInterrupt.
        # TODO: how to get config from here?
        text = PapirusTextPos(autoUpdate=False, rotation=180)
        text.AddText("Error {} {}: {}".format(
            datetime.datetime.now().strftime("%Y-%m-%d %I:%M %p"),
            type(e).__name__,
            e,
        ))
        text.WriteAll(partialUpdate=True)
        raise
示例#17
0
import socket
import urllib.request
import json
import os
from papirus import PapirusTextPos
from datetime import datetime

url = os.environ['URL']
user = os.environ['AUTH_USER']
passwd = os.environ['AUTH_PASSWD']
realm = os.environ['AUTH_REALM']

authHandler = urllib.request.HTTPBasicAuthHandler()
authHandler.add_password(realm=realm, uri=url, user=user, passwd=passwd)

text = PapirusTextPos(False, rotation=180)
warn = 0
critical = 0
unknown = 0


def writeStatus(txt, x_offset, y_offset, size):
    text.AddText(txt, x_offset, y_offset, size=size)

    # add the current time, means I can check at a glance if it's working
    text.AddText(str(datetime.now().time()), 0, 0, size=20)

    # I keep forgetting the IP get it and display it
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(('192.168.1.1', 80))
    text.AddText(str(s.getsockname()[0]), 0, 20, size=20)
def main(argv):
    global SIZE

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    if SW5 != -1:
        GPIO.setup(SW5, GPIO.IN)

    papirus = PapirusTextPos(False,
                             rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

    cdrom = ''
    i = 0
    files = []

    papirus.AddText('USB Gadget ISO Loader\n\nREDRAW CDROM UP DOWN SELECT',
                    0,
                    0,
                    Id='browser',
                    size=12)
    papirus.AddText('Status Unknown', 0, 55, Id='status', size=20)
    papirus.AddText('', 160, 55, Id='cdrom', size=12)
    papirus.AddText('Please select a disk.', 0, 80, Id='selected', size=12)
    papirus.WriteAll()
    while True:
        press = False

        if GPIO.input(SW5) == False:
            papirus.WriteAll()

        if GPIO.input(SW4) == False:
            if not cdrom:
                cdrom = ' cdrom=y'
                papirus.UpdateText('cdrom', 'cdrom')
            else:
                cdrom = ''
                papirus.UpdateText('cdrom', '')
            press = True

        if GPIO.input(UP) == False:
            press = True
            i = i - 1

        if GPIO.input(DOWN) == False:
            press = True
            i = i + 1

        if GPIO.input(SELECT) == False:
            os.system('rmmod g_mass_storage')
            status = os.system('modprobe g_mass_storage file="%s" stall=0 %s' %
                               ('/'.join((iso_dir, file)), cdrom))
            papirus.UpdateText('selected', file)
            if cdrom:
                type = 'CDROM '
            else:
                type = 'DISK '
            cdrom = ''
            papirus.UpdateText('cdrom', '')

            if (status == 0):
                papirus.UpdateText('status', type + 'OK')
            else:
                papirus.UpdateText('status', type + 'Fail!')
            papirus.WriteAll(True)

        if press is False:
            sleep(0.1)
            continue

        try:
            file = files[i]
        except IndexError:
            files = natural_sort(os.listdir(iso_dir))
            if (i > 0):
                i = 0
            else:
                i = -1
            if not files:
                papirus.UpdateText('browser', 'No files found')
            file = files[i]

        papirus.UpdateText(
            'browser', '%s\n%s\n%s\n%s' %
            (safe_index(files, i), safe_index(files, i + 1),
             safe_index(files, i + 2), safe_index(files, i + 3)))
        papirus.WriteAll(True)

        sleep(0.1)
示例#19
0
                # Commit your changes in the database
                db.commit()
                print
                print 'Upload to database successful'
            except:
                # Rollback in case there is any error
                db.rollback()

            # disconnect from server
            db.close()

            ##########################################################################################
            # eINC DISPLAY

            # Calling PapirusTextPos this way will mean nothing is written to the screen be default
            text = PapirusTextPos(False)

            # Clear all text from the screen
            # This does a full update so is a little slower than just removing the text.
            text.clear()

            # Write text to the screen at selected point, with an Id
            # Nothing will show on the screen
            text.AddText("Order id: ", 10, 10, Id="OrderId")
            text.AddText("Owner: ", 10, 30, Id="Owner")
            text.AddText("Type: ", 10, 50, Id="Type")
            text.AddText("Ammount: ", 10, 70, Id="Ammount")

            # Now display lines on the scrren
            text.WriteAll()
示例#20
0
from twython import Twython, TwythonError
import time
import random
from random import randint
from random import choice
from time import sleep
from papirus import Papirus
from papirus import PapirusText
from papirus import PapirusTextPos

#configure papirus screen
text = PapirusTextPos(rotation = 0)


text.AddText("hello world", 0, 25, Id="Start" )

#Authorise
APP_KEY = 'hwtNGXTnCAjeUOgRveksZdESX'
APP_SECRET = '1YrUz3JLLD86AtwPorc4PVh1MZBUptrOnLEIeL4SWjjh1zMtma'
OAUTH_TOKEN = '20427648-Xx2mqMa0ANvyVheg8xagsrgh6sm3LtEuKUxuSylfR'
OAUTH_TOKEN_SECRET = 'KYoMPhcvq7iMOf0i9Y8p2TwDnyLbcCrPB78SNd9jRf51v'

#Prepare your twitter, you will need it for everything
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
#The above should just be a single line, without the break

#keywords for search query q
naughty_words = [" -RT", "MAGA", "Brexit", "Trump", "xxx", "p**n", "gay", "tory", "labour", "conservative", "brexit", "russia"]
good_words = ["mountaineering", "solarpv", "biomass", "windpower", "climatechange" "#antarctica", "#fission", "#tate"]
filter = " OR ".join(good_words)
blacklist = " -".join(naughty_words)
示例#21
0
#!/usr/bin/env python

from papirus import PapirusTextPos
import mock

kSymbol = '01. symbol'
kPrice = '05. price'
kChangePercent = '10. change percent'

quote, ignore = mock.get_global_quote_mock()

symbol = quote[kSymbol]
price = quote[kPrice]
changePercent = quote[kChangePercent]

line = "{:4.4s} {:^4.4s} {:4.4s}".format(symbol, str(price),
                                         str(changePercent))

print(line)

# Same as calling "PapirusTextPos(True [,rotation = rot])"
text = PapirusTextPos(False, 0)
text.Clear()

text.AddText(line, 0, 0, 24, Id="Start1")
text.AddText("ATRS 3.03 +2.4", 0, 24, 24, Id="Start2")
text.AddText("NVDA _145 +.27", 0, 48, 24, Id="Start3")
text.AddText("__MU 32.5 -0.7", 0, 72, 24, Id="Start4")

text.WriteAll()
示例#22
0
                    elif dest == "Schagen":
                        dest = "SGN"
                        print("!! HIT")
                    if numDisplayed == 0:
                        disp = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 1:
                        disp2 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    numDisplayed += 1
#                    dest = str(dest)
                    text = PapirusTextPos(False, rotation=args.rotation)
                    text.AddText("Vertrek van de treinen\n\n", 10, 0, 13, Id="Header")
                    text.AddText(disp, 0, 20, 18, Id="opt1")
                    try:
                        disp2
                    except NameError:
                        disp2_exists = False
                    else:
                        disp2_exists = True
                    if disp2_exists == True:
                        text.AddText(disp2, 0, 40, 18, Id="opt2")
    if numDisplayed == 0:
        print("\nNo hits for configured stations. Assuming storing. Exception handler goes here.")
	text = PapirusTextPos(False, rotation=args.rotation)
        text.AddText("Vertrek van de treinen\n\n", 10, 0, 13, Id="Header")
        text.AddText("Apparently there are no trains.", 0, 35, 18, Id="errtxt")
    text.WriteAll()

if __name__ == '__main__':
    main()

示例#23
0
from papirus import Papirus
from papirus import PapirusImage
from papirus import PapirusText
from papirus import PapirusTextPos
import time
from twython import TwythonStreamer

screen = Papirus()
image = PapirusImage()
text = PapirusTextPos()

TERMS = '#alembic'

#login codes

APP_KEY = 'xCR6gEUjadgEAuYH5Oh2ehvhT'
APP_SECRET = 'PyhW6JM0EfqUS1l6sER8O8pSmoJxM2vmfJ2pQgOblHO2fx0Bjr'
OAUTH_TOKEN = '20427648-xL2sPwZRpi2V7jxuLFYHxqsOw8FytIgi9KA0e1K9v'
OAUTH_TOKEN_SECRET = 'Xho6kqVa38S4kJ742mNi9pDALM4jqXEvZTeE5lUziWnrT'

#setup callback from twython streamer

class BlinkyStreamer(TwythonStreamer):
        def on_success(self, data):
                if 'text' in data:
                        print data['text'].encode('utf-8')
                        print
                        text.AddText("#alembic", 60, 20, Id="Start", invert=True)
                        time.sleep(5.0)
                        image.write('/home/pi/papirus/epapertrump.bmp')
#screen.update()
示例#24
0
# Note: As of today, the hat needed for the PaPirus is not compatible with
# the GrovePi+ hat. Both work independently. You may choose to use either
# one depending on your project. Further compatibility may come...

#!/usr/bin/env python
from papirus import PapirusTextPos
import sys
text = PapirusTextPos()
text.AddText(
    sys.argv[1],
    Id="Top",
    font_path='/home/pi/processing/sketchbook/fonts/NeueHaasUnicaPro-Bold.ttf')
#print sys.argv[1]

# instantiate writer
text = PapirusTextPos()

#Write text (see README.MD of repo for more examples)
#AddText(*text, x, y, id, font_path, size)#
#text.AddText("your text", Id="Top", font_path='/home/pi/processing/sketchbook/fonts/NeueHaasUnicaPro-Light.ttf')
#text.AddText(sys.argv[1], Id="Top", font_path='/home/pi/processing/sketchbook/fonts/NeueHaasUnicaPro-Bold.ttf')
#text.AddText("your text", 15, 15, Id="Start", font_path='/home/pi/processing/sketchbook/fonts/NeueHaasUnicaPro-Bold.ttf', size=36)
示例#25
0
#Python LED Web Handler
import socket

from flask import Flask, render_template
from flask_jsonpify import jsonify
from flask_restful import Api, Resource

from papirus import PapirusTextPos

rot = 90
papirus_text = PapirusTextPos(False, rotation=rot)
ipAddr = socket.gethostname()
lines = [ipAddr, "", "", "", "", "", "", "", ""]
ids = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
app = Flask(__name__)
api = Api(app)


class set_text(Resource):
    def get(self, index, text):
        print("Index: " + index)
        print("Text: " + text)
        offset = int(index) - 1
        print("offset: {}".format(offset))
        print("Testing: " + lines[0])
        lines[offset] = text
        print("Text: " + lines[offset])
        return jsonify({'data': lines})


class clear_text(Resource):
示例#26
0
GPIO.setup(SW3, GPIO.IN)
GPIO.setup(SW4, GPIO.IN)

# Populate your twitter API details below, replacing
# CONSUMER_KEY_HERE etc with your details from Twitter
consumer_key = '*******************'
consumer_secret = '*******************'
access_token_key = '********************'
access_token_secret = '*******************'

api = twitter.Api(consumer_key=consumer_key,
                  consumer_secret=consumer_secret,
                  access_token_key=access_token_key,
                  access_token_secret=access_token_secret)
tweet_index = 0
text = PapirusTextPos(False, rotation=0)
statuses = api.GetHomeTimeline(count=20)


def home_timeline(Home):
    name = statuses[tweet_index].user.screen_name
    status = statuses[tweet_index].text
    return status, name


def next_tweet():
    status, name = home_timeline(sys.argv[1] if len(sys.argv) > 1 else 0)
    twitter_name = "@" + name

    text.UpdateText("start", twitter_name)
    text.UpdateText("tweet", status)
示例#27
0
文件: nope.py 项目: theodric/nsclock
def main():
    p = argparse.ArgumentParser()
    p.add_argument('--posX',
                   '-x',
                   type=int,
                   default=0,
                   help="X position of the start of the text")
    p.add_argument('--posY',
                   '-y',
                   type=int,
                   default=0,
                   help="Y position of the start of the text")
    p.add_argument('--fsize',
                   '-s',
                   type=int,
                   default=12,
                   help="Font size to use for the text")
    p.add_argument('--rotation',
                   '-r',
                   type=int,
                   default=0,
                   help="Rotation one of 0, 90, 180, 270")
    p.add_argument('--invert',
                   '-i',
                   type=bool,
                   default=False,
                   help="Invert the display of the text")
    args = p.parse_args()
    args.content = "at some point I will figure out why this is a required variable but until then I'll just nail it up like this"

    with open('/tmp/trains.xml') as fd:
        doc = xmltodict.parse(fd.read(), xml_attribs=True)

        iterCount = 0
        numDisplayed = 0

        if args.content:
            for iterCount in range(30):
                dest = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['EindBestemming']
                time = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekTijd']
                plat = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekSpoor']['#text']
                spc = "    "
                print(dest + spc + time[11:16] + spc + plat)
                if (dest == "qeq"
                        and numDisplayed <= 3) or (dest == "wew   "
                                                   and numDisplayed <= 3):
                    if dest == "Wormerveer":
                        dest = "WRM"
                        print("!! HIT")
                    elif dest == "Rotterdam Centraal":
                        dest = "RDC"
                        print("!! HIT")
                    if numDisplayed == 0:
                        disp = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 1:
                        disp2 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 2:
                        disp3 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 3:
                        disp4 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    numDisplayed += 1
                    #                    dest = str(dest)
                    text = PapirusTextPos(False, rotation=args.rotation)
                    text.AddText("Vertrek van de treinen\n\n",
                                 12,
                                 0,
                                 13,
                                 Id="Header")
                    text.AddText(disp, 0, 19, 18, Id="opt1")
                    try:
                        disp2
                    except NameError:
                        disp2_exists = False
                    else:
                        disp2_exists = True
                    if disp2_exists == True:
                        text.AddText(disp2, 0, 39, 18, Id="opt2")
                    try:
                        disp3
                    except NameError:
                        disp3_exists = False
                    else:
                        disp3_exists = True
                    if disp3_exists == True:
                        text.AddText(disp3, 0, 59, 18, Id="opt3")

                    try:
                        disp4
                    except NameError:
                        disp4_exists = False
                    else:
                        disp4_exists = True
                    if disp4_exists == True:
                        text.AddText(disp3, 0, 79, 18, Id="opt4")

    if numDisplayed == 0:
        print(
            "\nNo hits for configured stations. Assuming storing. Exception handler goes here."
        )
        text = PapirusTextPos(False, rotation=args.rotation)
        text.AddText("Vertrek van de treinen\n\n", 10, 0, 13, Id="Header")
        text.AddText(train6, 11, 10, 13, Id="train6")
        text.AddText(train7, 1, 25, 13, Id="train7")
        text.AddText(train8, 0, 40, 13, Id="train8")
        text.AddText(train9, 0, 55, 13, Id="train9")
        #        text.AddText("Apparently there", 15, 35, 18, Id="errtxt1")
        #        text.AddText("are no trains.", 25, 55, 18, Id="errtxt2")
        text.AddText("Apparently there are no trains", 15, 80, 9, Id="errtxt")


#assbag git
    text.WriteAll()
示例#28
0
            fonaLock.release()
            lasttxt = result
            papi.UpdateText("result", result)
            #papi.WriteAll()
            #papi.write(result)
            papi.papirus.display(papi.image)
            papi.papirus.partial_update()


fonaLock = threading.Lock()
#start serial connection to fona
fona = Serial('/dev/ttyUSB0', timeout=1)
lasttxt = ""
#papi = PapirusTextPos(False)
#connect to papirus screen
papi = PapirusTextPos(False)
papi.AddText("", 0, 25, Id="result")
papi.AddText("", 0, 75, Id="bat")
papi.AddText("", 125, 75, Id="weather")
papi.AddText("", 50, 75, Id="time")
#menu options
papi.AddText("Last", 20, 0, Id="SW5", size=12)
papi.AddText("Wthr", 60, 0, Id="SW4", size=12)
papi.AddText("SW3", 90, 0, Id="SW3", size=12)
papi.AddText("Away", 120, 0, Id="SW2", size=12)
papi.AddText("Here", 160, 0, Id="SW1", size=12)
#setup switches on pins
GPIO.setmode(GPIO.BCM)

for switch in SW:
    GPIO.setup(switch, GPIO.IN)
示例#29
0
def main():
    # TODO: load config from somewhere - config.py? Path from environment variable?
    # TODO: concept of ... pages? tabs? that are loaded in and registered.
    # TODO: instead of trying to use the tiny buttons on the papirus, is there
    #       like a row of 5 keyboard keys? maybe nice cherry switches.

    # TODO: Parameterize lat/long in config; this is Ann Arbor, MI.
    latitude = 42.22
    longitude = -83.74

    timezone = tzlocal()

    rotation = 180
    text = PapirusTextPos(autoUpdate=False, rotation=rotation)

    # TODO: Bitmap support requires using PapirusComposite instead of
    #       PapirusTextPos.
    text.AddText("Today is", 0, 0, size=17, Id="date")
    text.AddText("Startup...", 93, 20, size=19, Id="startup")
    text.AddText("\u2600rise:", 0, 35, size=23, Id="sunrise_label")
    text.AddText("\u2600set:", 0, 57, size=23, Id="sunset_label")
    text.AddText("", 87, 35, size=23, Id="sunrise")
    text.AddText("", 87, 57, size=23, Id="sunset")
    text.AddText("Temp", 0, 80, size=14, Id="temp")
    text.WriteAll()

    text.RemoveText("startup")

    first_display = True
    while True:
        today = datetime.date.today()

        # TODO: Accommodate lack of sunrise/sunset like as far north as
        #       Utqiaġvik - the city formerly known as Barrow, Alaska.
        #       get_sunrise_sunset() returns those as None.
        sunrise_time, sunset_time = get_sunrise_sunset(latitude, longitude,
                                                       today, timezone)

        text.UpdateText("date",
                        "Today is {}".format(today.strftime("%A, %Y-%m-%d")))
        text.UpdateText("sunrise", sunrise_time.strftime("%I:%M %p"))
        text.UpdateText("sunset", sunset_time.strftime("%I:%M %p"))
        # For testing the longest English day name.
        #text.UpdateText("date", "Today is {}".format(today.strftime("Wednesday, %Y-%m-%d")))

        text.UpdateText(
            "temp",
            "Temp {}".format(get_temperature_forecast(latitude, longitude)))

        # Do a partial update on startup, and a full update each following hour.
        text.WriteAll(first_display)
        first_display = False

        # Wait until the next hour.
        now = datetime.datetime.now()
        next_hour = (now + datetime.timedelta(hours=1)).replace(microsecond=0,
                                                                second=0,
                                                                minute=0)
        wait_seconds = (next_hour - now).total_seconds()
        print("waiting {} seconds until next hour".format(wait_seconds))
        time.sleep(wait_seconds)
示例#30
0
def main():
    p = argparse.ArgumentParser()
    p.add_argument('--posX',
                   '-x',
                   type=int,
                   default=0,
                   help="X position of the start of the text")
    p.add_argument('--posY',
                   '-y',
                   type=int,
                   default=0,
                   help="Y position of the start of the text")
    p.add_argument('--fsize',
                   '-s',
                   type=int,
                   default=12,
                   help="Font size to use for the text")
    p.add_argument('--rotation',
                   '-r',
                   type=int,
                   default=0,
                   help="Rotation one of 0, 90, 180, 270")
    p.add_argument('--invert',
                   '-i',
                   type=bool,
                   default=False,
                   help="Invert the display of the text")
    args = p.parse_args()
    args.content = "at some point I will figure out why this is a required variable but until then I'll just nail it up like this"

    with open('oldtrains.xml') as fd:
        doc = xmltodict.parse(fd.read(), xml_attribs=True)

        iterCount = 0
        numDisplayed = 0

        if args.content:
            for iterCount in range(30):
                text = PapirusTextPos(False, rotation=args.rotation)
                text.AddText("Vertrek van de treinen\n\n",
                             10,
                             0,
                             13,
                             Id="Header")
                dest = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['EindBestemming']
                time = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekTijd']
                plat = doc['ActueleVertrekTijden']['VertrekkendeTrein'][
                    iterCount]['VertrekSpoor']['#text']
                spc = "    "
                print(dest + spc + time[11:16] + spc + plat)
                if (dest == "Den Helder"
                        and numDisplayed <= 1) or (dest == "Schagen"
                                                   and numDisplayed <= 1):
                    if dest == "Den Helder":
                        dest = "HLD"
                        print("YUP, " + dest + "!")
                    elif dest == "Schagen":
                        dest = "SGN"
                        print(dest + ", YEEHA!")

                    if numDisplayed == 0:
                        print("numDisplayed == 0")
                        disp = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 1:
                        print("numDisplayed == 1")
                        disp2 = dest + spc + time[11:16] + spc + "Spoor " + plat
                    elif numDisplayed == 2:
                        disp3 = dest + spc + time[11:16] + spc + "Spoor " + plat

                    print("incrementing numDisplayed from ")
                    print(numDisplayed)
                    print(" to ")
                    numDisplayed += 1
                    print(numDisplayed)

                    print("adding 1st dest to screen buffer")
                    text.AddText(disp, 0, 25, 18, Id="opt1")
                    try:
                        disp2
                    except NameError:
                        disp2_exists = False
                    else:
                        disp2_exists = True
                    if disp2_exists == True:
                        print("adding 2nd dest to screen buffer")
                        text.AddText(disp2, 0, 50, 18, Id="opt2")

                    try:
                        disp3
                    except NameError:
                        disp3_exists = False
                    else:
                        disp3_exists = True
                    if disp3_exists == True:
                        text.AddText(disp3, 0, 75, 18, Id="opt3")
    if numDisplayed == 0:
        text.AddText("Apparently there are no trains.", 0, 35, 18, Id="errtxt")
    print("writing buffer to screen")
    text.WriteAll()