public
Last active

Post Email to Delicious Script

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
## 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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.