Skip to content

Instantly share code, notes, and snippets.

@serian
Created November 7, 2012 16:06
Show Gist options
  • Save serian/4032479 to your computer and use it in GitHub Desktop.
Save serian/4032479 to your computer and use it in GitHub Desktop.
python delicious はてブ ライブドアクリップ
#!/bin/python
# -*- coding: utf-8 -*-
"""ライブドアクリップやはてなブックマークからDeliciousへ
explain:
TAG_TOPはもとのSBMSの略号
タグのセパレータは空白ではなくてコンマ
タグがない時はnotagタグを付ける
UTF8
"""
import datetime
import time
import feedparser
from pydelicious import *
user = ""
passwd = ""
rss = ""
TAG_TOP = "LDC, "
TAG_NO = "notag"
def main():
d = feedparser.parse(rss)
print_flag = True
dapi = DeliciousAPI(user=user, passwd=passwd, codec='utf8')
for entry in d.entries:
if print_flag:
title = entry.title.encode('utf8')
link = entry.link
desc = entry.description.encode('utf8') or 'nodesc'
tags = TAG_TOP + ','.join([tag.term.encode('utf8') for tag in entry.tags]) if "tags" in entry else TAG_NO
timestamp = datetime.datetime.fromtimestamp(time.mktime(entry.updated_parsed)).isoformat()+'Z'
print link
print timestamp
time.sleep(1.5)
try:
dapi.posts_add(url=link, description=title, extended=desc, tags=tags, dt=timestamp, replace=False)
except DeliciousError, de:
print de
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment