gmail-parser.py failure

hakerdefo

How about a shot in the dark  ;)


sudo apt-get install python-feedparser


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

VastOne

As stated above, I actually wrote the how to's on this thing..

Yes, it and python3-feedparser is installed
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

#17
Doesn't happen to be a python2-feedparser used by your other installs, does there?

And I get identical error messages using python, python2.7 and python3.5 in

python /home/location_of_file/gmail_parser.py yourusername yourpassword

running the script on Void linux, python-feedparser version 5.2.1
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

VastOne

#18
Nope..  Just the latest SID version..  5.1.3-3
VSIDO      VSIDO Change Blog    

    I dev VSIDO

jedi

not that it's any comfort, but mine is the exact same way. same error, tried all of above and no joy...
Forum Netiquette

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

hakerdefo

#20
I think I've figured this one! Warning, I've been proved wrong before  ;)
VastOne, Time has come to update this script cause changes made in python and urllib has rendered it obsolete! Are you sure gmail-parser.py is working on other Debian Sid installs? Anyways here is the modification of gmail-parser.py that should hopefully work with python 3 & co.

#! /usr/bin/env python3

import urllib.request
import urllib             # For BasicHTTPAuthentication
import feedparser         # For parsing the feed
from textwrap import wrap # For pretty printing assistance
import sys
import time

_URL = "https://mail.google.com/gmail/feed/atom/unread"
WRAP_LIMIT = 50

def auth():

    username = "your_gmail_username_here"
    password = "your_gmail_password_here"
   
    auth_handler = urllib.request.HTTPBasicAuthHandler()
    auth_handler.add_password(realm='New mail feed',
                              uri='https://mail.google.com/',
                              user= username,
                              passwd= password)

    opener = urllib.request.build_opener(auth_handler)
    # ...and install it globally so it can be used with urlopen.
    urllib.request.install_opener(opener)
   
    '''The method to do HTTPBasicAuthentication'''
   
    f = opener.open(_URL)
    feed = f.read()
    return feed

def fill(text, width):
    '''A custom method to assist in pretty printing'''
    if len(text) < width:
        return text + ' '*(width-len(text))
    else:
        return text

def readmail(feed):
    '''Parse the Atom feed and print a summary'''
    atom = feedparser.parse(feed)

    print ("${color white}You have %s new mails${color} ${alignr}Updated: ${color white}%s" % ((len(atom.entries)), time.strftime("%I:%M")))

    for i in range(len(atom.entries)):
        if(i>10):
            break
        if(len(atom.entries[i].title) > WRAP_LIMIT):
        #print ("%s" % (fill(wrap(atom.entries[i].title, 50)[0]+" ...", 55)))
            print ("${color1}%s" % (wrap(atom.entries[i].title, WRAP_LIMIT)[0]+" ..."))
        else:
            print ("${color1}%s" % (wrap(atom.entries[i].title, WRAP_LIMIT)[0]))

def countmail(feed):
    '''Parse the Atom feed and print a summary'''
    atom = feedparser.parse(feed) 
    print ("Emails: %s new" %len(atom.entries))
               
if __name__ == "__main__":
    f = auth()  # Do auth and then get the feed
    if(len(sys.argv) > 1):
        countmail(f)
    else:
        readmail(f) # Let the feed be chewed by feedparse



You will need to add your Gmail username and password to the following fields in the script before using it,


username = "your_gmail_username_here"
password = "your_gmail_password_here"


Save it somewhere in your $PATH and call it like this from conky,


execpi 600 /path/to/gmail-parser.py


Of-course you will have to replace '/path/to/gmail-parser.py' above with the actual path where you have saved the script.

Absolutely untested as I don't have python 3 on this box! Might blow up your computer! You've been warned! Good luck!

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

PackRat

I get an error running it in a terminal -

Traceback (most recent call last):
  File "./gmail-parser.py", line 5, in <module>
    import feedparser         # For parsing the feed
ImportError: No module named 'feedparser'


@vastone - python-feedparser the only depndency?
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

Hi there PackRat,
You will need 'python3-feedparser' for the modified script I've posted. So just do,


sudo apt-get install python3-feedparser


And things should be fine!

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

PackRat

Ok, I get a whole bunch of new errors -

Traceback (most recent call last):
  File "./gmail-parser.py", line 62, in <module>
    f = auth()  # Do auth and then get the feed
  File "./gmail-parser.py", line 30, in auth
    f = opener.open(_URL)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 504, in error
    result = self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 696, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized


This system is Void linux - I can check your script on my Debian system once the crew heads for Girl Scouts and the desk is free.
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

VastOne

Similar (if not same as PackRat) errors

Traceback (most recent call last):
  File "/home/vastone/gmail_parser.py", line 62, in <module>
    f = auth()  # Do auth and then get the feed
  File "/home/vastone/gmail_parser.py", line 30, in auth
    f = opener.open(_URL)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 504, in error
    result = self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 693, in http_error_302
    fp.read()
  File "/usr/lib/python3.5/http/client.py", line 458, in read
    s = self.fp.read()
  File "/usr/lib/python3.5/socket.py", line 576, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.5/ssl.py", line 937, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.5/ssl.py", line 799, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.5/ssl.py", line 583, in read
    v = self._sslobj.read(len, buffer)
OSError: [Errno 0] Error
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

@vastone - you have a link to your #! HowTo? I didn't see it recreated here. Void is crazy minimal so I need to make sure I have the packages installed - there no recommneded packages with Void just hard dependencies (wget isn't even part of the default install - distro is bat-shit crazy in some ways).
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

VastOne

There is a How To on #! but I'll be damned if I can find it there..

The earliest references I have found of a How To on this by me is here on the Ubuntu forums in a thread about conky

The only requirement though is and has always been python-feedparser, nothing else
VSIDO      VSIDO Change Blog    

    I dev VSIDO

hakerdefo

@PackRat @VastOne
You've got following installed?


python3-openssl
python3-requests
python3-urllib3


Install if missing and re-run the script!

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

jedi

Traceback (most recent call last):
  File "/home/jedi/conky/gmail_parser.py", line 23, in <module>
    maxlen = sys.argv[3]
IndexError: list index out of range



Still the same...
Forum Netiquette

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

Snap

Folks, AFAIK there's currently something libssl breaking python. Might be that driving you mad?