forked from evilsocket/pwnagotchi-plugins-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclock.py
63 lines (54 loc) · 2.17 KB
/
clock.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
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins
import pwnagotchi
import logging
import datetime
import os
import toml
import yaml
class PwnClock(plugins.Plugin):
__author__ = 'https://github.com/LoganMD'
__version__ = '1.0.4'
__license__ = 'GPL3'
__description__ = 'Clock/Calendar for pwnagotchi'
__defaults__ = {
'enabled': False,
}
def on_loaded(self):
if 'date_format' in self.options:
self.date_format = self.options['date_format']
else:
self.date_format = "%m/%d/%y"
if 'time_format' in self.options:
self.time_format = self.options['time_format']
else:
self.time_format = "%I:%M %p"
logging.info("[clock] Plugin loaded.")
def on_ui_setup(self, ui):
memenable = False
config_is_toml = True if os.path.exists(
'/etc/pwnagotchi/config.toml') else False
config_path = '/etc/pwnagotchi/config.toml' if config_is_toml else '/etc/pwnagotchi/config.yml'
with open(config_path) as f:
data = toml.load(f) if config_is_toml else yaml.load(
f, Loader=yaml.FullLoader)
if 'memtemp' in data["main"]["plugins"]:
if 'enabled' in data["main"]["plugins"]["memtemp"]:
if data["main"]["plugins"]["memtemp"]["enabled"]:
memenable = True
logging.info(
"[clock] memtemp is enabled")
if ui.is_waveshare_v2():
pos = (130, 84) if memenable else (200, 84)
ui.add_element('clock', LabeledValue(color=BLACK, label='', value='-/-/-\n-:--',
position=pos,
label_font=fonts.Small, text_font=fonts.Small))
def on_ui_update(self, ui):
now = datetime.datetime.now()
time_rn = now.strftime(self.date_format + "\n" + self.time_format)
ui.set('clock', time_rn)
def on_unload(self, ui):
with ui._lock:
ui.remove_element("clock")