Gmail @conky with python

This is the place for queries that don't fit in any of the other categories.

Gmail @conky with python

Postby Nili » Mon Jul 15, 2013 8:52 am

Hello!
could someone help me with this gmail python script

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

import sys, imaplib

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

username = ''
passwd = ''

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()


----------------------------------------------------------------

What i want to do?

just to colour the part after slash eg: 40/0 New

here it is the code to be coloured: print('{}/{} New'.format(total, total - seen))

can anyone help me, i have read and tried many code on the Internet but I can not fix
really appreciate much some help,
regards,
Nili
Last edited by micseydel on Mon Jul 15, 2013 4:15 pm, edited 1 time in total.
Reason: Added code tags, locked OP.
Nili
 
Posts: 3
Joined: Mon Jul 15, 2013 8:46 am

Re: Gmail @conky with python

Postby metulburr » Mon Jul 15, 2013 3:59 pm

just to colour the part after slash eg: 40/0 New

You could of just as easily asked how do i print this string and color its output. Also use code tags when inserting code into your post. see here

If your terminal doesnt support this, then garbage shows up. http://en.wikipedia.org/wiki/ANSI_escape_code
Code: Select all
class EscapeColor():
   def __init__(self):
      self.reset = '\x1b[0m' #reset; clears all colors and styles (to white on black)
      self.bold_on = '\x1b[1m' #bold on
      self.italic_on = '\x1b[3m' #italics on
      self.underline_on = '\x1b[4m' #underline on
      self.inverse_on = '\x1b[7m' #inverse on; reverses foreground & background colors
      self.strike_on = '\x1b[9m' # strikethrough on
      self.bold_off = '\x1b[22m' # bold off (see below)
      self.italic_off = '\x1b[23m' # italics off
      self.underline_off = '\x1b[24m' # underline off
      self.inverse_off = '\x1b[27m' #inverse off
      self.strike_off = '\x1b[29m'  #strikethrough off

      self.black = '\x1b[30m' #set foreground color to black
      self.red = '\x1b[31m' #set foreground color to red
      self.green = '\x1b[32m' #set foreground color to green
      self.yellow = '\x1b[33m' #set foreground color to yellow
      self.blue = '\x1b[34m' #set foreground color to blue
      self.purple = '\x1b[35m' #set foreground color to magenta (purple)
      self.cyan = '\x1b[36m' #set foreground color to cyan
      self.white = '\x1b[37m' #set foreground color to white
      self.default_white = '\x1b[39m' #set foreground color to default (white)

      self.light_black = '\x1b[1;30m' #set foreground color to black
      self.light_red = '\x1b[1;31m' #set foreground color to red
      self.light_green = '\x1b[1;32m' #set foreground color to green
      self.light_yellow = '\x1b[1;33m' #set foreground color to yellow
      self.light_blue = '\x1b[1;34m' #set foreground color to blue
      self.light_purple = '\x1b[1;35m' #set foreground color to magenta (purple)
      self.light_cyan = '\x1b[1;36m' #set foreground color to cyan
      self.light_white = '\x1b[1;37m' #set foreground color to white
      self.light_default_white = '\x1b[1;39m' #set foreground color to default (white)

      self.Bblack = '\x1b[40m' #set background color to black
      self.Bred = '\x1b[41m' #set background color to red
      self.Bgreen = '\x1b[42m' #set background color to green
      self.Byellow = '\x1b[43m' #set background color to yellow
      self.Bblue = '\x1b[44m' #set background color to blue
      self.Bpurple = '\x1b[45m' #set background color to magenta (purple)
      self.Bcyan = '\x1b[46m' #set background color to cyan
      self.Bwhite = '\x1b[47m' #set background color to white
      self.default_black = '\x1b[49m' #set background color to default (black)

color = EscapeColor()
print('40{}/{}0'.format(color.blue, color.reset))
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1561
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Gmail @conky with python

Postby Nili » Mon Jul 15, 2013 4:54 pm

Hi metulburr,
Sorry for not tag the code above, next time will be more carefully.
thanks for provide the code and the links, but it seems that it doesn't not work for what I want.

I do a little clearer:
Image
I manage my email tea@gmail.com via conky and gmail.py code above.
I have currently on Gmail 43 total / 0 new - "i want to color only the 0 part" that whenever I get a new email to displayed with the colour like: orange - a single color its enough for me on the new mail that coming which in this case is the number zero.
The output should appear on conky desktop like the pic, not in Terminal.

Code: Select all
print('40{}/{}0'.format(color.blue, color.reset))

this code change all the function of gmail because 40/0 was just only for demonstration

Please you can see once again.
Code: Select all
print('{}/{} New'.format(total, total - seen))

{}/{}
the orange bracket is the part that I want to do with colour

Thank you once again
Nili
 
Posts: 3
Joined: Mon Jul 15, 2013 8:46 am

Re: Gmail @conky with python

Postby Yoriz » Mon Jul 15, 2013 6:54 pm

This question seems more specific to how conky outputs data thats given to it, then it has to do with python.
You'll need to find out if conky has any special syntax for changing colours.

Edit: Here a link How To: Configuring Conky
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1164
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Gmail @conky with python

Postby Nili » Mon Jul 15, 2013 7:15 pm

Hello Yoriz!
Thanks for your input ,

from conky code here
Code: Select all
${if_existing /proc/net/route eth0}${color 000000}tea@gmail:${color FF9900}${alignr}${execi 60 python ~/.conky/.gmail.py}${else}${color5}Network Unavailable${color}${endif}${color}

I can change color to something like this Gmail: 40/0 New
but i do not want this,

i pefer like ->> Gmail: 40/0 New <-- and this thing in conky doesn't not work because i know and play with conky sometimes while the gmail code is gmail.py which conky call it with the command "execi 60".
Tried with ${color FF9900} inside gmail.py but can't work because does not recognize

any other suggestions if you can,
thnx very much!

Nili
Nili
 
Posts: 3
Joined: Mon Jul 15, 2013 8:46 am


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests