-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.py
62 lines (49 loc) · 1.52 KB
/
t.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
import re
picdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pic')
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import textwrap
from auth import (
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET
)
from twython import TwythonStreamer
import time
from waveshare_epd import epd2in13_V2
from PIL import Image, ImageDraw, ImageFont
epd = epd2in13_V2.EPD()
epd.init(epd.FULL_UPDATE)
epd.Clear(0xFF)
font13 = ImageFont.truetype(os.path.join(picdir, 'GnuUnifont.ttf'), 13)
def printToDisplay(string):
image = Image.new('1', (epd.height, epd.width), 255)
draw = ImageDraw.Draw(image)
draw.text((0, 10), string, font = font13, fill = 0)
epd.display(epd.getbuffer(image))
class MyStreamer(TwythonStreamer):
def on_success(self, data):
if data['lang'] == 'en':
username = data['user']['screen_name']
tweet = data['text']
tweet = re.sub(r"&", "", tweet)
tweet = textwrap.fill(data['text'], width = 35)
print(f"@{username}: \n{tweet}")
printToDisplay(f"{username}: \n{tweet}")
time.sleep(3)
def on_error(self, status_code, data):
print(status_code)
stream = MyStreamer(
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET
)
filter = ['San Francisco', '🛸']
stream.statuses.filter(track = filter)