-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpistuff.py
More file actions
93 lines (72 loc) · 2.96 KB
/
Copy pathpistuff.py
File metadata and controls
93 lines (72 loc) · 2.96 KB
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
import asyncio
import gpiozero
from gpiozero import Button, LED, Buzzer, RGBLED
from colorzero import Color
from discord.ext import tasks, commands
import discord
import time
from datetime import date
import datetime
from time import sleep
class PiBell(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.x = 4
self.button = Button(self.x, False, None)
self.led = LED(14)
self.led_working = RGBLED(16, 20, 21)
self.bell_channel_id = 758425852001255486
# self.buzzer = Buzzer(15)
self.led_working.color = Color('green')
print(self.button.pull_up)
self.send_onready_message.start()
self.reset_color_led.start()
self.wait = 0
self.fTime = open("SwanData.txt", "a")
@tasks.loop(seconds=5)
async def reset_color_led(self):
self.led_working.color = Color('green')
# channel = self.bot.get_channel(int(self.bell_channel_id))
# with open('/media/pi/8bcf7aa7-4478-493c-a2e9-d0bb42a49e45/Images/saved_img-final.jpg', 'rb') as fp:
# await channel.send(file=discord.File(fp, 'new_filename.png'))
@commands.command()
async def command_color_led(self, ctx):
print('command')
self.led_working.color = Color('orange')
@tasks.loop()
async def send_onready_message(self):
dt = datetime.datetime.now()
tuesdayNight = dt.replace(hour=22, minute=0, second=0)
if dt.weekday() == 1:
if dt == tuesdayNight:
weekNumber = date.today().isocalendar()[1]
if weekNumber % 2 == 0:
colourTxt = " green "
else:
colourTxt = " black "
print("working time")
channel = self.bot.get_channel(int(self.bell_channel_id))
await channel.send("@everyone have the bins been done it's" + colourTxt + "week")
time.sleep(2)
if self.button.is_pressed and time.time() > self.wait + 30:
fTime = open("SwanData.txt", "a")
self.led_working.color = Color('blue')
print("@everyone Someone is at the door!")
channel = self.bot.get_channel(int(self.bell_channel_id))
ringTime = str(round(time.time()))
fTime.write("\n" + ringTime)
self.fTime.close()
await channel.send("@everyone Someone is at the door! - " + ringTime)
# with open('/media/pi/8bcf7aa7-4478-493c-a2e9-d0bb42a49e45/Images/saved_img-final.jpg', 'rb') as fp:
# await channel.send(file=discord.File(fp, 'new_filename.png'))
self.led.on()
self.led.off()
self.wait = time.time()
@send_onready_message.before_loop # wait for the client before starting the task
async def before_send(self):
await self.bot.wait_until_ready()
return
def exit_handler(self):
self.led_working.off()
def setup(bot):
bot.add_cog(PiBell(bot))