You are not logged in.

#1 2016-09-01 05:00:56

micke
Member
Registered: 2012-12-28
Posts: 12

Unable to show e-mail in conky

Heya,

I am trying to set conky to to show my gmail inbox.
I am using the below gmail.py

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys, imaplib

port = 993
server = 'imap.gmail.com'

username = 'username'
passwd = 'password'

imap_server = imaplib.IMAP4_SSL(server, port)
try:
	imap_server.login(username, passwd)
except:
	print('?? new')
	sys.exit( 1 )

typ, data = imap_server.select ('Inbox', True)
if typ == 'OK':
	total = int(data[0])
	typ, data = imap_server.search (None, 'SEEN')
	if typ == 'OK':
		seen = len(data[0].split())
		print('{}/{} new'.format(total, total - seen))

if typ != 'OK':
	print('?? new')

imap_server.logout()

and I have added the below line to conky

${execpi 300 python ~/.scripts/gmail.py}

But nothing is showing up, I am very inexperienced with python scripts, so if someone please can assist me getting this up and running I would be pretty happy.

Cheers,
Micke

Offline

#2 2016-09-01 07:30:25

oliver
Administrator
Registered: 2010-11-04
Posts: 2,209

Re: Unable to show e-mail in conky

Does the script work outside of conky?  What is the output if you run it from a terminal?

Offline

#3 2016-09-01 09:46:55

Mr Green
Administrator
Registered: 2010-11-07
Posts: 6,920

Re: Unable to show e-mail in conky

Is script executable? Be very aware that conky nows uses lua syntax too...


Comments, suggestions please feel free to contact me mrgreen(at)archbang(dot)org

Offline

#4 2016-09-02 06:20:45

micke
Member
Registered: 2012-12-28
Posts: 12

Re: Unable to show e-mail in conky

oliver wrote:

Does the script work outside of conky?  What is the output if you run it from a terminal?

Yes the script is working fine after running it in a terminal.

Mr Green wrote:

Does the script work outside of conky?  What is the output if you run it from a terminal?

Yep I am aware of it running lua now, below is my entire conky.conf.

conky.config = {
	alignment = 'top_right',

	cpu_avg_samples = 1,
	net_avg_samples = 1,
	update_interval = 1,

	default_color = 'white',
	default_outline_color = 'white',
	default_shade_color = 'white',
	color2 = '947a3a',
	color3 = '947a3a',

	use_xft = true,
	font = 'DejaVu Sans Mono:size=8',


	draw_borders = false,
	draw_shades = false,
	draw_graph_borders = false,
	draw_outline = false,

	border_width = 0,

	gap_x = 0,
	gap_y = 0,

	own_window = true,
	own_window_type = 'desktop',
	own_window_transparent = true,
	own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
	own_window_argb_visual = true,

	use_spacer = 'left',
	double_buffer = true,
	no_buffers = true,
	maximum_width = 1240,
	minimum_size = 0,
	total_run_times = 0,
	background = true,

	lua_load = '~/.conky/draw_bg.lua',
	lua_draw_hook_pre = 'draw_bg',
}

conky.text = [[
${offset 140}${color2}[${color}$nodename${color2}]${execpi 300 python ~/.scripts/gmail.py} UP:${color3}[${color}$uptime${color3}]${color2} CPU:${color3}[${color}${cpu cpu0}%/${cpu cpu1}%/${cpu cpu2}%/${color}${cpu cpu3}%${color3}]${color2} RAM:${color3}[${color}$memperc%${color3}] ${color2}DISKS:${color3}[${color}ROOT ${fs_free_perc /mnt}%${color3}]${color2} ${color3}[${color}HOME ${fs_free_perc /home}%${color3}] BATTERY:[${color}${battery_percent BAT0}%${color2}] TIME:${color2}[${color}${time %H}:${color}${time %M}:${time %S}${color2}]${offset 10}
]]

Offline

#5 2016-09-03 12:59:23

micke
Member
Registered: 2012-12-28
Posts: 12

Re: Unable to show e-mail in conky

Ok, I got it to work by just moving the script and it worked correctly.

But it is showing my total amount of e-mails, and I would prefer to only see new e-mails.
So if anyone is good with python scripting if they could provide me with the correct script that only shows new e-mails.

Offline

#6 2016-09-04 19:50:51

oliver
Administrator
Registered: 2010-11-04
Posts: 2,209

Re: Unable to show e-mail in conky

I just ran the script and it gives output like:

3/2 new

meaning 3 emails in total, 2 of which are unread


If you just want to see the number of new you can change line 25 to be

print(total - seen, 'new')

New output is

2 new


For what it's worth, I'd say it's worth changing lines 16 and 28 too

Line 16

print('?? new')

Might be better as

print('failed to login')

Line 28 might be better as

print('failed to get new count')

Just makes it a bit more obvious where the script fails if/when google change something

It might mess up your conky display if you have specific widths set so it's purely a cosmetic issue but it's nice to know what part of the script is bombing out

Offline

Board footer

Powered by FluxBB