Python3 gmail and conky [solved by using python2]

I have become quite dependent on conky displaying the contents of my gmail mailboxes and something seems to have broken since python3 came about.
Can anyone with python knowledge point me to how to get it working again?
Old code
## needs The urllib and feedparser Python libraries
import sys
import urllib3 # For BasicHTTPAuthentication
import feedparser # For parsing the feed
from textwrap import wrap
_URL = "https://mail.google.com/gmail/feed/atom"
uname = sys.argv[1]
password = sys.argv[2]
maxlen = sys.argv[3]
urllib.FancyURLopener.prompt_user_passwd = lambda self, host, realm: (uname, password)
def auth():
'''The method to do HTTPBasicAuthentication'''
opener = urllib.FancyURLopener()
f = opener.open(_URL)
feed = f.read()
return feed
def readmail(feed, maxlen):
'''Parse the Atom feed and print a summary'''
atom = feedparser.parse(feed)
print '%s' % (len(atom.entries))
if __name__ == "__main__":
f = auth() # Do auth and then get the feed
readmail(f, int(maxlen)) # Let the feed be chewed by feedparser
error
File "theabovescript.py", line 26
print '%s' % (len(atom.entries))
^
SyntaxError: invalid syntax
Last edited by tawan (2010-10-19 20:05:50)

Thanks for the above - my python2 script broke again recently, even with the hacks, so I've taken your python3 one and adapted to my needs
fuzymonkey wrote:
I've managed to hack this together:
#!/usr/bin/env python
import urllib.request
import re
URL = "https://mail.google.com/gmail/feed/atom"
username = "username"
password = "********"
def find(term, lines):
for line in lines:
if re.search(term, line):
return line
print("?")
exit(1)
def get_feed():
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)
urllib.request.install_opener(opener)
try:
feed = urllib.request.urlopen(URL).read()
except urllib.error.URLError:
print("?")
exit(1)
return feed
xml = get_feed()
xml = xml.decode()
linebyline = xml.splitlines()
count = find("<fullcount>", linebyline)
count = re.sub("^.*(\d+).*$", r"\1", count)
print(count)

Similar Messages

  • I have a annual plan, it supposed must be used in two terminals, but i haven´t been able to install any app in a second computer, it always says that the app is only available as a trial download. What can I do to solve this issue, and be able to use my p

    I have a annual plan, it supposed must be used in two terminals, but i haven´t been able to install any app in a second computer, it always says that the app is only available as a trial download. What can I do to solve this issue, and be able to use my paid plan in two computers?

    Hi Susan,
    Please refer to the help document to fix this issue:
    Creative Cloud applications unexpectedly revert to trial mode | CS6, CCM
    You may also refer to the thread as below:
    creative cloud software says my free trial has expired, but I have a paid subscription
    Regards,
    Sheena

  • Why yahoo/gmail retrieval and facebook app so so slow when in WIFI. But using the internet to check for emails and facebook is fast using the same WIFI connection??

    Why yahoo/gmail retrieval and facebook app so so slow when in WIFI. But using the internet to check for emails and facebook is fast using the same WIFI connection??

    Hi SandyS_VZW,
    Yes tried resetting the wifi connection and problem still persist.
    Here it is...to make it clear. Connected thru the same wifi at home...
    -> emails (yahoo/gmail) and facebook WEBSITES are working fine and fast when using/accessing thru a browser (chrome/samsung browser) - no problem with this.
    -> emails (yahoo/gmail) and facebook APP is soooooo sloooww (thru the App). Slow I mean comparing it to using their browser/websites... news feeds/emails refreshing so quickly but not when using the APP installed in Samsung Galaxy Note 4. Slow like - It will take around 5-10minutes just to get your emails and news feed refreshed.
    THIS HAPPENS ONLY WHEN CONNECTED THRU A WIFI which has a speed of 10-20mb. It is not happening when connected to the network data/plan.
    My wife has the same Samsung Galaxy Note 4 (coming from different provider at&t) - same setup (emails, fb app), same wifi connection, but she's not experiencing anything like it.
    Not sure why, I dont want to believe that while connected to a WIFI, Verizon is restricting anything and ******* me off to make me switch to my data plan connection everytime - which is Unfair!
    Was there a known issue similar about this case?
    thanks,

  • HT1296 How can I transfer my ipad calendar to my iphone and ipod touch without using gmail?

    How can I transfer the Calendar on my ipad2 to my iphone5 and ipod touch without using gmail, and keep them synced?

    You could use iCloud, or you could sync them through iTunes on a Mac or a Windows computer.

  • How can I use apple mail (linked to gmail) and get it to only do autofill on the contacts that I have in apple address book?

    How can I use apple mail (linked to gmail) and get it to only do autofill on the contacts that I have in apple address book? Everytime I write an email on the Apple mail app (as well as in Gmail) it recommends a bunch of emails that are not my contacts. I want it to just autofill for the contacts that I have in my address book. Is this possible? Thank you. I have an Imac Intel version and an Iphone 5 phone.

    Mail > Window > Previous Recipients

  • I am running OS10.6.8 and have a mail box duplication. I use gmail and when I open my mail I have both the Apple Mail and another set of boxes for Gmail. Both get all mail and when I delete from one, it deletes from the other. How can I get rid of the dup

    I am running OS10.6.8 and have a mail box duplication. I use gmail and when I open my mail I have both the Apple Mail and another set of boxes for Gmail. Both get all mail and when I delete from one, it deletes from the other. How can I get rid of the dup

    Hi,
    According to your descriptioin, I don't think this is system problem, it should be Intel driver problem. It would be contact Intel to confirm this issue whether this is their driver problem.
    Roger Lu
    TechNet Community Support

  • After installing the new Yosemite OS on my iMac I can no longer send email. I can receive email, but not send. I use gmail and can send email on the gmail (google) site, but not on "mail" on my iMac. Any others with this problem? What should we do?

    After installing the new Yosemite OS on my iMac I can no longer send email. I can receive email, but not send. I use gmail and can send email on the gmail (google) site, but not on "mail" on my iMac. Any others with this problem? What should we do?

    My gmail, which is correctly configured for Mail with gmail SMTP and Google IMAP, works for awhile on Mail, which I leave open while working on other applications. But several times a day I get msg from Google: "We recently blocked a sign-in attempt to your Google Account" . . . and requiring me to verify my account details, re-enter passwords, confirm security settings (or change them from "disable" to "enable less secure methods" and so on). In Mail I also have tried "taking all accounts online", and re-entering my gmail password inside Mail account settings. These steps successfully re-set comms between gmail and Mail ... for awhile, then it happens again. Enough occurrences over a work day that I just quit Mail and revert to accessing gmail directly. Apple Care advisor and an Apple knowledge base article say that Apple can't deal with this, as gmail is third-party app, and they refer me to gmail, and so far I've found nothing helpful there.
    From today I also have several instances of a window saying "Mail has unexpectedly closed" and asking me to Re-open it.
    I also use Yahoo mail, which stops working with Mac Mail at the same time as gmail, but I do not receive notices to re-verify from Yahoo.
    I recently upgraded from Mavericks to Yosemite. The Mail problem happened occasionally with Mavericks but is far more frequent with Yosemite.

  • TS3899 With Yahoo Mail, and anotare account (Inacap Mail), I can only receive mails but I can't send emails. I don't know if this is a problem of the iPad or it is a problem with yahoo mail, because using Gmail and the email of my job I don' have this pro

    With Yahoo Mail, and anotare account (Inacap Mail), I can only receive mails but I can't send emails. I don't know if this is a problem of the iPad or it is a problem with yahoo mail, because using Gmail and the email of my job I don' have this problem.

    Google them to confirm the settings that you need for the outgoing server, then check the setting you entered on the pad.  Pay real close attention to the outgoing server name, and port.  You may need to change in on the pad. 

  • I've lost the use of predictive text in the subject line of gmail and I want to get it back

    I used to be able to hit a few characters in the subject line of a gmail compose window and it would bring up past subject lines with the same characters. That doesn't work anymore. How do I get it back? I've tried changing the settings under preferences/privacy/history but it doesn't seem to make any difference. Any ideas? Thanks

    See:
    *Firefox > Preferences > Privacy > Firefox will: "Use custom settings for history": "Remember search and form history"
    *https://support.mozilla.org/kb/Form+autocomplete
    This Gmail web page may be using autocomplete=off to prevent Firefox from storing form data.
    You can remove autocomplete=off with a bookmarklet to make Firefox store form data.
    *http://kb.mozillazine.org/User_name_and_password_not_remembered
    Note that Firefox won't auto-fill saved form data automatically when autocomplete=off is used, so you need to double-click the empty name field to get a drop-down list.

  • TS3899 "cannot get mail" in iphone5 suddenly. been using iphone to check 2 email accounts for months now, one is gmail and not troubled. the other is thunderbird and i get this error message now. no settings have been changed or anything! ideas?

    hey all, I have been getting the "cannot get mail" error message on my iphone5 suddenly.
    ive been using iphone to check two email accounts for months now, one is gmail and not troubled. the other is mail from thunderbird and i get this error message now saying it is not responding. no settings have been changed or anything, it just suddenly stopped receiving mail on my device as of Tuesday afternoon.
    Does anyone have iny ideas about why? i have yet to update to the new OS7 yet, could that be it?

    'The installer has insufficient privileges to modify this file C:\Program Files (x86)\Common Files\Apple\Apple Application Support\Web kit.resources\inspector\Images\Spinner Inactive Selected.gif.'
    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • Bug in Mail when using Google Apps Gmail and sync

    I found a bug in the sync process between the Mac and the phone. If you have Mail (on the computer) set to use Google Apps for Your Domain, the sync on the phone changes the user for the mail account. I assume this is because it sees "smtp.gmail.com" or something and decides to "protect" you from having an incorrect user account.
    So for example, if you're using Google Apps and your e-mail is [email protected], Mail (on the computer) will also have smtp.gmail.com and pop.gmail.com as the servers. When sync'd to the phone, iTunes or the phone decide to change the user account for both servers to [email protected]@gmail.com, which is of course not what we want.
    I'm kind of annoyed that they're trying to protect us like this.

    Yeah unfortunately if you tried to send an e-mail
    before discovering that bug, you will have an error
    message show every time you access Mail saying "the
    sender address [email protected]@gmail.com was
    rejected by the server."
    I can't get it to go away even by deleting the
    account on iPhone and not setting it to sync.
    Anybody know of a fix?
    -AJT
    Yes. Create the GMail account on your iPhone using the Other shortcut instead of the GMail shortcut. That will let you specify whatever address you want.

  • We use the Apple mail server to get e-mails from our gmail and comcast mail accounts. Recently we have been getting spam that claims to be sent to a gmail address, but when I check that address directly, there is no such e-mail. ???

    We use the Apple mail server to get e-mails from our gmail and comcast mail accounts. Recently we have been getting spam that claims to be sent to a gmail address, but when I check that address directly, there is no such e-mail, either in the inbox or in the spam folder. Is it possible to bypass the gmail account and send directly to the Apple mail server, spoofing the gmail address?

    Maybe some info here for you about spoofing. (and much additional info)
    http://www.thesafemac.com
    Hope this helps

  • Hi guys, I have a problem with imessage. My iphone 4S is factory unlocked and i have been using t-mobile carrier. i tried settings - messages - imessage on but there is this 'waiting for activation' thing. Does anyone know how to solve this? Thanks!

    Hi guys, I have a problem with imessage. My iphone 4S is factory unlocked and i have been using t-mobile carrier. i tried settings - messages - imessage on but there is this 'waiting for activation' thing. Does anyone know how to solve this?
    Thanks!

    If you are in the UK:
    Please upgrade your plan to Web n Walk plus. One of our users on T-Mobile UK had this to report back to us:
    T-Mobile UK are in fact port blocking to ensure fair usage on their base Web and Walk Plan. I have upgraded to Web and Walk Plus and as a result the port blocks are lifted and I get a higher data allowance!
    We were also recently contacted by T-Mobile UK, who stated the following:
    Any smart phone (iphone, android etc) that is bought directly from T-Mobile should be automatically provisioned with Web n Walk plus, if customers have bought a handset sim free then they will need to call customer services and get this added. It is free of charge for most price plans (including new plans) but some older plans will generate a charge of £5pm for this.

  • My iPod touch has 2 Notes account: 'Gmail' and 'From my Mac'. Now I know where my 'Gmail' notes are synced on my mac but I've no idea where my 'From My Mac' notes are synced on my mac. Mine is a Mac Book Air using Mac OS X Lion 10.7.5

    My iPod touch has 2 Notes account: 'Gmail' and 'From my Mac'.
    Now I know where my 'Gmail' notes are synced on my mac but I've no idea where my 'From My Mac' notes are synced on my mac.
    Mine is a Mac Book Air using Mac OS X Lion 10.7.5.
    Any ideas?

    Go step by step and check.
    1. Start up in Safe Mode.
        http://support.apple.com/kb/PH11212
    2. Backup your computer.
    3. Empty Trash.
       http://support.apple.com/kb/PH13806
    4. Re-index Macintosh HD.
        This will take a while. Wait until it is finished.
        System Preferences > Spotlight > Privacy
        http://support.apple.com/kb/ht2409
    5.Try OmniDiskSweeper. This will show the storage size details of the items.
       https://www.omnigroup.com/more
       Select Macintosh HD and click  “Sweep Selected Drive” at the bottom.
       Be careful. Delete only the files that can be safely  deleted. If you are not sure about any file, don’t touch it.

  • When I print an email using firefox as my browser the print if very, very tiny. No problem using Internet Explorer. This happens with both my Gmail and my AOL emails.

    My emails are printing in very tiny type (unreadable). This happens in both my Gmail and AOL email accounts. When I use internet explorer it doesn't happen. I have researched the answers online and it seems that if I go to Firefox>file>page setup>scale and set it to 100% it may fix the problem. However, I cannot figure out how to take the first step. Where can I find "file"????
    Sorry to be such a dummy.

    1. orange Firefox button in the upper-left corner - then click on Print - then click on Page Setup
    2. if that orange Firefox button isn't showing and the Menu bar is - click to open File - then click to open Page Setup

Maybe you are looking for