New curl and python method to get gmail output

VastOne

Over on this thread we have been discussing gmail conky script changes. And so far it is anything but successful even though we are getting great help from so many

I have found an interesting alternative that uses curl and works flawlessly from terminal... if that's all you wanted

The ideal thing would be to get this to format to a conky output

(change location of gmail.py if you put it somewhere other than /home/your_username)

vastone@vsido:~$ curl -u gmail_login:gmail_password --silent "https://mail.google.com/mail/feed/atom" | ./gmail.py

gmail.py (must be executable)

#!/usr/bin/env python3

import sys
import xml.etree.ElementTree as ET

colors = {
             'RED' : '\033[31m',      'LRED' : '\033[91m',
           'GREEN' : '\033[32m',    'LGREEN' : '\033[92m',
          'YELLOW' : '\033[93m',   'LYELLOW' : '\033[93m',
            'BLUE' : '\033[34m',     'LBLUE' : '\033[94m',         
         'MAGENTA' : '\033[35m',  'LMAGENTA' : '\033[95m',
            'CYAN' : '\033[36m',     'LCYAN' : '\033[96m',
            'GREY' : '\033[37m',     'WHITE' : '\033[97m',
            'BOLD' : '\033[1m',
            'ENDC' : '\033[0m'
         }

def print_data( tag, flist, template ):
    values = {}
    for f in flist:
        node = tag.find( '/'.join( xmlns+x for x in f.split('/') ) )
        values[f.replace('/','_')] = node.text
        values.update( colors )
    print( template.format( **values ) )

# -----------------

fields = ( 'title', 'tagline', 'fullcount' )
e_fields = ( 'title', 'summary', 'author/name', 'author/email', 'issued' )

template = """{BOLD}{MAGENTA}{title}{ENDC}
{GREEN}{tagline} ({BOLD}{fullcount}{ENDC}{GREEN}){ENDC}"""

e_template = """
{LCYAN}{BOLD}{author_name}{ENDC}   [{issued}]
{LGREEN}{title}{ENDC}
"""



data = ''.join( sys.stdin.readlines() )
xroot = ET.fromstring( data )
xmlns = xroot.tag[:xroot.tag.find('}')+1]

print_data( xroot, fields, template )

for e in xroot.findall( xmlns+'entry' ):
    print_data( e, e_fields, e_template )


Let me know what y'all think and if successful in getting it to conky
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

#2
I get this error -

Traceback (most recent call last):
  File "/home/doug/bin/cgmail.py", line 45, in <module>
    print_data( xroot, fields, template )
  File "/home/doug/bin/cgmail.py", line 22, in print_data
    values[f.replace('/','_')] = node.text
AttributeError: 'NoneType' object has no attribute 'text'


I suspect I'm missing a python package that debian brings in automatically, but Void does not consider a hard dependency (the upside of Debian's dependency hell).

Does that command not run in conky as:

${excepi 600 <command>}     # change 600 to however long you want between mail checks

You may want to fold the output, or have a real wide conky window.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

jedi

Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

PackRat

Google admin just sent me an email - apparently I need to configure Google to allow access from unsecure apps for this to work; so I stop looking through the python3 packages available to see if I'm missing something.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

Quote from: PackRat on November 15, 2016, 01:42:07 PM
Google admin just sent me an email - apparently I need to configure Google to allow access from unsecure apps for this to work; so I stop looking through the python3 packages available to see if I'm missing something.
Hi there RatMan,
Perhaps you missed my last post,

http://vsido.org/index.php?topic=1222.msg13801#msg13801

As stated there a better option in this scenario is to generate and use app password than allowing, what google considers unsecure, apps the access to your account.

Cheers!!!
You Can't Always Git What You Want