Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Post Email to Delicious Script
## Requires:
## svn checkout http://feedparser.googlecode.com/svn/trunk/ feedparser
## svn checkout http://pydelicious.googlecode.com/svn/trunk/ pydelicious
import sys, os, imaplib, email
from pydelicious import DeliciousAPI, DeliciousItemExistsError
MAIL_IMAP_SERVER = 'imap.gmail.com'
MAIL_IMAP_SSL_PORT = 993
MAIL_IMAP_USERNAME = 'XXXXXXXXXX@gmail.com'
MAIL_IMAP_PASSWORD = 'XXXXXXXXXX'
MAIL_IMAP_INBOX = 'Inbox'
dlc = DeliciousAPI(user='XXXXXXXXXX', passwd='XXXXXXXXXX')
class DeliciousIMAPClient(object):
def __init__(self):
self.username = MAIL_IMAP_USERNAME
self.password = MAIL_IMAP_PASSWORD
self.server = imaplib.IMAP4_SSL(MAIL_IMAP_SERVER, MAIL_IMAP_SSL_PORT)
self.inbox = MAIL_IMAP_INBOX
self.server.login(self.username, self.password)
def process_messages(self):
status, count = self.server.select(self.inbox)
(retcode, messages) = self.server.search(None, '(UNSEEN)')
for msg in messages[0].split(' '):
if msg:
(ret, msginfo) = self.server.fetch(msg, '(RFC822)')
message = email.message_from_string(msginfo[0][1])
self._process_message(message)
self.server.store(msg, '+FLAGS', '\\Seen')
def _process_message(self, message):
subj = message['Subject']
url = message.get_payload().split()[0]
print 'Posting "%s" to Delicious' % subj
try:
rs = dlc.posts_add(url=url, description=subj, shared=False, tags="email-import")
except DeliciousItemExistsError:
print '\tAlready exists.'
if __name__ == "__main__":
client = DeliciousIMAPClient()
client.process_messages()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.