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 imaplib
import email import email
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993) try:
M.login("mickey@tmnt.com","cowabunga") import credentials
except:
print("Couldn't read crendtials")
exit(1)
status, counts = M.status("INBOX","(MESSAGES UNSEEN)") ok = True
unread = 0
if status == "OK": for account in credentials.accounts:
unread = counts[0].split()[4][:-1]
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: else:
unread = "N/A" print(unread)
print(unread)

View File

@ -1,3 +1,4 @@
local os = require("os")
local wibox = require("wibox") local wibox = require("wibox")
local awful = require("awful") local awful = require("awful")
local naughty = require("naughty") local naughty = require("naughty")
@ -5,38 +6,52 @@ local watch = require("awful.widget.watch")
local path_to_icons = "/usr/share/icons/Arc/actions/22/" 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_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") email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
local previous_value = 0
watch( 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) function(widget, stdout, stderr, exitreason, exitcode)
local unread_emails_num = tonumber(stdout) or 0 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 if (unread_emails_num > 0) then
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png") email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
email_widget:set_text(stdout)
elseif (unread_emails_num == 0) then elseif (unread_emails_num == 0) then
email_icon:set_image(path_to_icons .. "/mail-message-new.png") email_icon:set_image(path_to_icons .. "/mail-message-new.png")
email_widget:set_text("")
end end
end end
) )
function show_emails() function show_emails(timeout)
awful.spawn.easy_async([[bash -c 'python /home/<username>/.config/awesome/email-widget/read_unread_emails.py']], awful.spawn.easy_async_with_shell(home .. "/.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py",
function(stdout, stderr, reason, exit_code) function(stdout, stderr, reason, exit_code)
naughty.notify{ naughty.notify{
text = stdout, text = stdout,
title = "Unread Emails", title = "Unread Emails",
timeout = 5, hover_timeout = 0.5, timeout = timeout,
width = 400, width = 400,
} }
end end
) )
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 imaplib
import email import email.header
import datetime import datetime
def process_mailbox(M): def process_mailbox(mailbox, to = None):
rv, data = M.search(None, "(UNSEEN)") rv, data = mailbox.search(None, "(UNSEEN)")
if rv != 'OK': if rv != 'OK':
print "No messages found!" print("No messages found!")
return return
for num in data[0].split(): for num in data[0].split():
rv, data = M.fetch(num, '(BODY.PEEK[])') rv, data = mailbox.fetch(num, '(BODY.PEEK[])')
if rv != 'OK': if rv != 'OK':
print "ERROR getting message", num print("ERROR getting message", num)
return return
msg = email.message_from_string(data[0][1]) msg = email.message_from_string(data[0][1].decode())
print 'From:', msg['From']
print 'Subject: %s' % (msg['Subject']) 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']) date_tuple = email.utils.parsedate_tz(msg['Date'])
if date_tuple: if date_tuple:
local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(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 # with code below you can process text of email
# if msg.is_multipart(): # if msg.is_multipart():
# for payload in msg.get_payload(): # for payload in msg.get_payload():
# if payload.get_content_maintype() == 'text': # if payload.get_content_maintype() == 'text':
# print payload.get_payload() # print(payload.get_payload())
# else: # else:
# print msg.get_payload() # print(msg.get_payload())
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993) try:
M.login("mickey@tmnt.com","cowabunga") import credentials
except:
print("Couldn't read crendtials")
exit(1)
rv, data = M.select("INBOX") for account in credentials.accounts:
if rv == 'OK':
process_mailbox(M) mailbox = imaplib.IMAP4_SSL(account.host, 993)
M.close() mailbox.login(account.username, account.password)
M.logout()
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 cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget")
local battery_widget = require("awesome-wm-widgets.battery-widget.battery") local battery_widget = require("awesome-wm-widgets.battery-widget.battery")
local ram_widget = require("awesome-wm-widgets.ram-widget.ram-widget") local ram_widget = require("awesome-wm-widgets.ram-widget.ram-widget")
local email_widget = require("awesome-wm-widgets.email-widget.email")
-- Custom imports -- Custom imports
local options = require("options") local options = require("options")
@ -272,6 +273,10 @@ awful.screen.connect_for_each_screen(function(s)
music.icon_widget, music.icon_widget,
music.text_widget, music.text_widget,
delimiter, delimiter,
email_widget.icon,
delimiter2,
email_widget.widget,
delimiter,
ram_widget, ram_widget,
delimiter2, delimiter2,
cpu_widget, cpu_widget,