Сегодня появилась проблема. Хочу, что бы Conky выводил пришедшие на почту gmail письма. Скачал скрипт gmail_parser.py:
Код: Выделить всё
import sys
import urllib # 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 = 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 '${color1} %s new email(s)\n' % (len(atom.entries))
for i in range(min(len(atom.entries), maxlen)):
print ' ${color2}%s' % atom.entries[i].title
#uncomment the following line if you want to show the name of the sender
# print ' ${color2}%s' % atom.entries[i].author
if len(atom.entries) > maxlen:
print ' ${color}more...'
if __name__ == "__main__":
f = auth() # Do auth and then get the feed
readmail(f, int(maxlen)) # Let the feed be chewed by feedparser
В .conkyrc прописал:
Код: Выделить всё
E-MAIL ${hr 2}
${alignc}${color}${font}${execpi 300 python /home/rabe/Conkyrc/Scripts/gmail_parser.py ЗДЕСЬ_МОЙ_НИК@gmail.com ЗДЕСЬ_МОЙ_ПАССВОРД}
${alignc}
И не хочет это работать, хоть тресни.
Аутентификация проходит успешно, и даже отображается количество пришедших писем, но сами письма не отображаются.
Вот что пишет терминал:
Код: Выделить всё
rabe@rabe-desktop:~$ conky -c .conkyrc2
Conky: desktop window (18000a6) is subwindow of root window (c3)
Conky: window type - override
Conky: drawing to created window (0x3400001)
Conky: drawing to double buffer
Traceback (most recent call last):
File "/home/rabe/Conkyrc/Scripts/gmail_parser.py", line 47, in <module>
readmail(f, int(maxlen)) # Let the feed be chewed by feedparser
File "/home/rabe/Conkyrc/Scripts/gmail_parser.py", line 39, in readmail
print ' ${color2}%s' % atom.entries[i].title
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0423' in position 19: ordinal not in range(128)
Видимо, проблема в кодировке. Но не знаю, что делать. Погуглил. Понял, что проблема распространенная. Говорят, что питон такой мать его за ногу нехороший (вообще в Conky русские буквы отображаются нормально). Короче, многое понял, но не ясно, как эту проблему решить. Английский у меня хромает жутко. А на русских форумах ничего путного не нашел Помогите пожалуйста. Или посоветуйте другой способ реализации нужной мне функции. Буду очень благодарен...