Author Topic: gmail-parser.py failure  (Read 3378 times)

hakerdefo

  • Posts: 495
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #15 on: November 13, 2016, 09:40:09 PM »
How about a shot in the dark  ;)

Code: [Select]
sudo apt-get install python-feedparser

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

VastOne

  •      v-ger
  • Posts: 3874
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #16 on: November 13, 2016, 09:52:53 PM »
As stated above, I actually wrote the how to's on this thing..

Yes, it and python3-feedparser is installed
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 1823
    • View Profile
Re: gmail-parser.py failure
« Reply #17 on: November 14, 2016, 12:58:01 AM »
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

Code: [Select]
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

  •      v-ger
  • Posts: 3874
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #18 on: November 14, 2016, 02:34:42 AM »
Nope..  Just the latest SID version..  5.1.3-3
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

jedi

  • DEFCON 1
  • Posts: 1495
  • Not all those who wander are lost.
    • View Profile
    • NixNut.com
Re: gmail-parser.py failure
« Reply #19 on: November 14, 2016, 06:24:31 AM »
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

  • Posts: 495
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #20 on: November 14, 2016, 05:55:56 PM »
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.
Code: [Select]
#! /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,

Code: [Select]
username = "your_gmail_username_here"
password = "your_gmail_password_here"

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

Code: [Select]
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

  • Posts: 1823
    • View Profile
Re: gmail-parser.py failure
« Reply #21 on: November 14, 2016, 07:40:19 PM »
I get an error running it in a terminal -

Code: [Select]
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

  • Posts: 495
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #22 on: November 14, 2016, 07:50:01 PM »
Hi there PackRat,
You will need 'python3-feedparser' for the modified script I've posted. So just do,

Code: [Select]
sudo apt-get install python3-feedparser

And things should be fine!

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

PackRat

  • Posts: 1823
    • View Profile
Re: gmail-parser.py failure
« Reply #23 on: November 14, 2016, 09:26:22 PM »
Ok, I get a whole bunch of new errors -

Code: [Select]
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

  •      v-ger
  • Posts: 3874
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #24 on: November 15, 2016, 12:02:07 AM »
Similar (if not same as PackRat) errors

Code: [Select]
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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 1823
    • View Profile
Re: gmail-parser.py failure
« Reply #25 on: November 15, 2016, 03:18:25 AM »
@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

  •      v-ger
  • Posts: 3874
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #26 on: November 15, 2016, 03:31:51 AM »
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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 495
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #27 on: November 15, 2016, 06:08:33 AM »
@PackRat @VastOne
You've got following installed?

Code: [Select]
python3-openssl
python3-requests
python3-urllib3

Install if missing and re-run the script!

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

jedi

  • DEFCON 1
  • Posts: 1495
  • Not all those who wander are lost.
    • View Profile
    • NixNut.com
Re: gmail-parser.py failure
« Reply #28 on: November 15, 2016, 06:41:17 AM »
Code: [Select]
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

  • Posts: 462
    • View Profile
Re: gmail-parser.py failure
« Reply #29 on: November 15, 2016, 07:19:43 AM »
Folks, AFAIK there's currently something libssl breaking python. Might be that driving you mad?