-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
118 lines (92 loc) · 3.61 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import configparser
import epsimplelib
import time
import datetime
import textwrap
import telepot
from telepot.loop import MessageLoop
from pathlib import Path
# Look for your absolute directory path
script_path = (Path(__file__)).parent
config_file = script_path / 'config.ini'
print(config_file)
config = configparser.RawConfigParser()
config.read(config_file.as_posix())
telegram_bot_api_key = config.get('telegram', 'bot_api_key')
# eInk
EPD_WIDTH = epsimplelib.DEVICE_WIDTH
EPD_HEIGHT = epsimplelib.DEVICE_HEIGHT
def toPercentHeight(num):
return num * .01 * EPD_HEIGHT
def toPercentWidth(num):
return num * .01 * EPD_WIDTH
def display(title, msgs):
eps = epsimplelib.EPScreen('landscape') # eps = e-Ink Paper Screen
# print(len(msgs))
if title:
eps.set_title('From ' + title + ':')
# eps.add_text_middle(toPercentWidth(25), "<3 <3 <3")
if len(msgs) == 1:
width = 20
# print(len(msgs[0]))
if len(msgs[0]) > width:
positionX = 25
myNewText = textwrap.wrap(msgs[0], width=width)
for i in range(len(myNewText)):
eps.add_text_middle(toPercentWidth(positionX), myNewText[i])
positionX = positionX + 20
else:
eps.add_text_middle(toPercentWidth(45), msgs[0])
elif len(msgs) == 2:
eps.add_text_middle(toPercentWidth(30), msgs[0])
eps.add_text_middle(toPercentWidth(50), msgs[1])
# eps.add_text_middle(toPercentWidth(60), "girls very much!!!")
# eps.add_text_middle(toPercentWidth(80), "<3 <3 <3")
# TODO: Figure out how the hell to make a heart from lines
# eps.add_line((40, 40, 41, 40))
# eps.add_line((100, 100, 165, 100))
eps.update_screen()
# hello()
# hello() # Physical screen not refreshed
# Telegram Bot
def action(msg):
chat_id = msg['chat']['id']
command = msg['text']
# print(msg['from']['username'])
# print('Received: %s' % command)
if command.startswith('/hi'):
telegram_bot.sendMessage(chat_id, str(
"Hi, " + msg['from']['first_name'] + '!'))
print('msg: "' + msg['text'] + '"\
from: ' + msg['from']['username'])
elif command == '/time':
now = datetime.datetime.now()
telegram_bot.sendMessage(chat_id, str(
now.hour)+str(":")+str(now.minute))
# elif command == '/logo':
# telegram_bot.sendPhoto (chat_id, photo = "https://i.pinimg.com/avatars/circuitdigest_1464122100_280.jpg")
# elif command == '/file':
# telegram_bot.sendDocument(chat_id, document=open('/home/pi/Aisha.py'))
# elif command == '/audio':
# telegram_bot.sendAudio(chat_id, audio=open('/home/pi/test.mp3'))
elif command.startswith('/display '):
display(msg['from']['first_name'],
[msg['text'].replace("/display ", "")])
telegram_bot.sendMessage(chat_id, str(
'Your message has been displayed.'))
print('display: "' + msg['text'].replace("/display ", "") + '"\
from: ' + msg['from']['username'])
elif command == '/headinghome':
now = datetime.datetime.now()
display("", [msg['from']['first_name'] + ' is heading home',
'at ' + now.strftime("%m/%d/%Y, %H:%M:%S")])
telegram_bot.sendMessage(chat_id, str(
'Your message has been displayed.'))
print('display: "' + msg['text'].replace("/display ", "") + '"\
from: ' + msg['from']['username'])
telegram_bot = telepot.Bot(telegram_bot_api_key)
print(telegram_bot.getMe())
MessageLoop(telegram_bot, action).run_as_thread()
print('Up and Running....')
while 1:
time.sleep(10)