Added more widgets

This commit is contained in:
Thomas Forgione 2018-11-29 11:39:53 +01:00
parent 03e7d5360c
commit 3d7eeaefe7
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
5 changed files with 95 additions and 42 deletions

View File

@ -0,0 +1,2 @@
__pycache__
credentials.py

32
awesome-wm-widgets/email-widget/count_unread_emails.py Normal file → Executable file
View File

@ -1,16 +1,30 @@
#!/usr/bin/python
#!/usr/bin/env python3
import imaplib
import email
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
M.login("mickey@tmnt.com","cowabunga")
try:
import credentials
except:
print("Couldn't read crendtials")
exit(1)
status, counts = M.status("INBOX","(MESSAGES UNSEEN)")
ok = True
unread = 0
if status == "OK":
unread = counts[0].split()[4][:-1]
for account in credentials.accounts:
mailbox = imaplib.IMAP4_SSL(account.host, 993)
mailbox.login(account.username, account.password)
status, counts = mailbox.status("INBOX","(MESSAGES UNSEEN)")
if status == "OK":
unread += int(counts[0].split()[4][:-1])
else:
ok = False
if not ok and unread == 0:
print('N/A')
else:
unread = "N/A"
print(unread)
print(unread)

View File

@ -1,3 +1,4 @@
local os = require("os")
local wibox = require("wibox")
local awful = require("awful")
local naughty = require("naughty")
@ -5,38 +6,52 @@ local watch = require("awful.widget.watch")
local path_to_icons = "/usr/share/icons/Arc/actions/22/"
email_widget = wibox.widget.textbox()
local home = os.getenv('HOME')
local email_widget = wibox.widget.textbox()
email_widget:set_font('Play 9')
email_icon = wibox.widget.imagebox()
local email_icon = wibox.widget.imagebox()
email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
local previous_value = 0
watch(
"python /home/<username>/.config/awesome/email-widget/count_unread_emails.py", 20,
"bash -c " .. home .. "/.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py", 60,
function(widget, stdout, stderr, exitreason, exitcode)
local unread_emails_num = tonumber(stdout) or 0
if previous_value < unread_emails_num then
previous_value = unread_emails_num
show_emails(10)
end
email_widget:set_text(stdout)
if (unread_emails_num > 0) then
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
email_widget:set_text(stdout)
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
elseif (unread_emails_num == 0) then
email_icon:set_image(path_to_icons .. "/mail-message-new.png")
email_widget:set_text("")
end
email_icon:set_image(path_to_icons .. "/mail-message-new.png")
end
end
)
function show_emails()
awful.spawn.easy_async([[bash -c 'python /home/<username>/.config/awesome/email-widget/read_unread_emails.py']],
function(stdout, stderr, reason, exit_code)
function show_emails(timeout)
awful.spawn.easy_async_with_shell(home .. "/.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py",
function(stdout, stderr, reason, exit_code)
naughty.notify{
text = stdout,
title = "Unread Emails",
timeout = 5, hover_timeout = 0.5,
timeout = timeout,
width = 400,
}
end
)
end
email_icon:connect_signal("mouse::enter", function() show_emails() end)
email_icon:connect_signal("button::press", function() show_emails(5) end)
return {
icon = email_icon,
widget = email_widget
}

57
awesome-wm-widgets/email-widget/read_unread_emails.py Normal file → Executable file
View File

@ -1,42 +1,59 @@
#!/usr/bin/python
#!/usr/bin/env python3
import imaplib
import email
import email.header
import datetime
def process_mailbox(M):
rv, data = M.search(None, "(UNSEEN)")
def process_mailbox(mailbox, to = None):
rv, data = mailbox.search(None, "(UNSEEN)")
if rv != 'OK':
print "No messages found!"
print("No messages found!")
return
for num in data[0].split():
rv, data = M.fetch(num, '(BODY.PEEK[])')
rv, data = mailbox.fetch(num, '(BODY.PEEK[])')
if rv != 'OK':
print "ERROR getting message", num
print("ERROR getting message", num)
return
msg = email.message_from_string(data[0][1])
print 'From:', msg['From']
print 'Subject: %s' % (msg['Subject'])
msg = email.message_from_string(data[0][1].decode())
if to is not None:
print('To: ', to)
print('From:', msg['From'])
decode = email.header.decode_header(msg['Subject'])
subject = ''.join(map(lambda x: x[0].decode(), decode))
print('Subject: %s' % subject)
date_tuple = email.utils.parsedate_tz(msg['Date'])
if date_tuple:
local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
print "Local Date:", local_date.strftime("%a, %d %b %Y %H:%M:%S")
print("Local Date:", local_date.strftime("%a, %d %b %Y %H:%M:%S"))
# with code below you can process text of email
# if msg.is_multipart():
# for payload in msg.get_payload():
# if payload.get_content_maintype() == 'text':
# print payload.get_payload()
# print(payload.get_payload())
# else:
# print msg.get_payload()
# print(msg.get_payload())
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
M.login("mickey@tmnt.com","cowabunga")
try:
import credentials
except:
print("Couldn't read crendtials")
exit(1)
rv, data = M.select("INBOX")
if rv == 'OK':
process_mailbox(M)
M.close()
M.logout()
for account in credentials.accounts:
mailbox = imaplib.IMAP4_SSL(account.host, 993)
mailbox.login(account.username, account.password)
rv, data = mailbox.select("INBOX")
if rv == 'OK':
process_mailbox(mailbox, account.email)
mailbox.close()
mailbox.logout()

5
rc.lua
View File

@ -18,6 +18,7 @@ local volume_bar_widget = require("awesome-wm-widgets.volumebar-widget.volumebar
local cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget")
local battery_widget = require("awesome-wm-widgets.battery-widget.battery")
local ram_widget = require("awesome-wm-widgets.ram-widget.ram-widget")
local email_widget = require("awesome-wm-widgets.email-widget.email")
-- Custom imports
local options = require("options")
@ -272,6 +273,10 @@ awful.screen.connect_for_each_screen(function(s)
music.icon_widget,
music.text_widget,
delimiter,
email_widget.icon,
delimiter2,
email_widget.widget,
delimiter,
ram_widget,
delimiter2,
cpu_widget,