"""Library to access del.icio.us data via Python.
:examples:
Using the API class directly:
>>> a = pydelicious.apiNew('user', 'passwd')
>>> # or:
>>> a = DeliciousAPI('user', 'passwd')
>>> a.tags_get() # Same as:
>>> a.request('tags/get', )
Or by calling the 'convenience' methods on the module.
- def add(user, passwd, url, description, tags = "", extended = "", dt = "", replace="no"):
- def get(user, passwd, tag="", dt="", count = 0):
- def get_all(user, passwd, tag = ""):
- def delete(user, passwd, url):
- def rename_tag(user, passwd, oldtag, newtag):
- def get_tags(user, passwd):
>>> a = apiNew(user, passwd)
>>> a.posts_add(url="http://my.com/", desciption="my.com", extended="the url is my.moc", tags="my com")
True
>>> len(a.posts_all())
1
>>> get_all(user, passwd)
1
This are short functions for getrss calls.
>>> rss_
def get_userposts(user):
def get_tagposts(tag):
def get_urlposts(url):
def get_popular(tag = ""):
>>> json_posts()
>>> json_tags()
>>> json_network()
>>> json_fans()
:License: pydelicious is released under the BSD license. See 'license.txt'
for more informations.
:berend:
- Rewriting comments to english. More documentation, examples.
- Added JSON-like return values for XML data (del.icio.us also serves some JSON...)
- better error/exception classes and handling, work in progress.
- Encoding seems to be working (using UTF-8 here).
:@todo:
- Source code SHOULD BE ASCII!
- More tests.
- Parse datetimes in XML.
- Salvage and test RSS functionality?
- Setup not used, Still works? Should setup.py be tested?
- API functions need required argument checks.
* lizense einbinden und auch via setup.py verteilen
* readme auch schreiben und via setup.py verteilen
* auch auf anderen systemen testen (linux -> uni)
* automatisch releases bauen lassen, richtig benennen und in das
richtige verzeichnis verschieben.
* was k[o]nnen die anderen librarys denn noch so? (ruby, java, perl, etc)
* was wollen die, die es benutzen?
* wof[u]r k[o]nnte ich es benutzen?
* entschlacken?
:done:
* Refactored the API class, much cleaner now and functions dlcs_api_request, dlcs_parse_xml are available for who wants them.
* stimmt das so? muss eher noch t[a]g str2utf8 konvertieren
>>> pydelicious.getrss(tag="t[a]g")
url: http://del.icio.us/rss/tag/t[a]g
* requester muss eine sekunde warten
* __init__.py gibt die funktionen weiter
* html parser funktioniert noch nicht, gar nicht
* alte funktionen fehlen, get_posts_by_url, etc.
* post funktion erstellen, die auch die fehlenden attribs addiert.
* die api muss ich noch weiter machen
* requester muss die 503er abfangen
* rss parser muss auf viele m[o]glichkeiten angepasst werden
"""
import sys
import os
import time
import datetime
import hashlib
import http.client
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, time
from io import StringIO
import collections
try:
from elementtree.ElementTree import parse as parse_xml
except ImportError:
from xml.etree.ElementTree import parse as parse_xml
import feedparser
### Static config
__version__ = '0.5.0'
__author__ = 'Frank Timmermann <regenkind_at_gmx_dot_de>' # GP: does not respond to emails
__contributors__ = [
'Greg Pinero',
'Berend van Berkum <berend+pydelicious@dotmpe.com>']
__url__ = 'http://code.google.com/p/pydelicious/'
__author_email__ = ""
# Old URL: 'http://deliciouspython.python-hosting.com/'
__description__ = '''pydelicious.py allows you to access the web service of del.icio.us via it's API through python.'''
__long_description__ = '''the goal is to design an easy to use and fully functional python interface to del.icio.us. '''
DLCS_OK_MESSAGES = ('done', 'ok') # Known text values of positive del.icio.us <result> answers
DLCS_WAIT_TIME = 4
DLCS_REQUEST_TIMEOUT = 444 # Seconds before socket triggers timeout
#DLCS_API_REALM = 'del.icio.us API'
DLCS_API_HOST = 'https://api.del.icio.us'
DLCS_API_PATH = 'v1'
DLCS_API = "%s/%s" % (DLCS_API_HOST, DLCS_API_PATH)
DLCS_RSS = 'http://del.icio.us/rss/'
ISO_8601_DATETIME = '%Y-%m-%dT%H:%M:%SZ'
USER_AGENT = 'pydelicious.py/%s %s' % (__version__, __url__)
DEBUG = 0
if 'DLCS_DEBUG' in os.environ:
DEBUG = int(os.environ['DLCS_DEBUG'])
# Taken from FeedParser.py
# timeoutsocket allows feedparser to time out rather than hang forever on ultra-slow servers.
# Python 2.3 now has this functionality available in the standard socket library, so under
# 2.3 you don't need to install anything. But you probably should anyway, because the socket
# module is buggy and timeoutsocket is better.
try:
import timeoutsocket # http://www.timo-tasi.org/python/timeoutsocket.py
timeoutsocket.setDefaultSocketTimeout(DLCS_REQUEST_TIMEOUT)
except ImportError:
import socket
if hasattr(socket, 'setdefaulttimeout'): socket.setdefaulttimeout(DLCS_REQUEST_TIMEOUT)
if DEBUG: print("Set socket timeout to %s seconds" % DLCS_REQUEST_TIMEOUT, file=sys.stderr)
### Utility classes
class _Waiter:
"""Waiter makes sure a certain amount of time passes between
successive calls of `Waiter()`.
Some attributes:
:last: time of last call
:wait: the minimum time needed between calls
:waited: the number of calls throttled
pydelicious.Waiter is an instance created when the module is loaded.
"""
def __init__(self, wait):
self.wait = wait
self.waited = 0
self.lastcall = 0;
def __call__(self):
tt = time.time()
timeago = tt - self.lastcall
if self.lastcall and DEBUG>2:
print("Lastcall: %s seconds ago." % lastcall, file=sys.stderr)
if timeago <= self.wait:
if DEBUG>0: print("Waiting %s seconds." % self.wait, file=sys.stderr)
time.sleep(self.wait)
self.waited += 1
self.lastcall = tt + self.wait
else:
self.lastcall = tt
Waiter = _Waiter(DLCS_WAIT_TIME)
class PyDeliciousException(Exception):
'''Std. pydelicious error'''
pass
class DeliciousError(Exception):
"""Raised when the server responds with a negative answer"""
class DefaultErrorHandler(urllib.request.HTTPDefaultErrorHandler):
'''@xxx:bvb: Where is this used? should it be registered somewhere with urllib2?
Handles HTTP Error, currently only 503.
'''
def http_error_503(self, req, fp, code, msg, headers):
raise urllib.error.HTTPError(req, code, throttled_message, headers, fp)
class post(dict):
"""Post object, contains href, description, hash, dt, tags,
extended, user, count(, shared).
@xxx:bvb: Is this needed? Right now this is superfluous,
"""
def __init__(self, href = "", description = "", hash = "", time = "", tag = "", extended = "", user = "", count = "",
tags = "", url = "", dt = ""): # tags or tag?
self["href"] = href
if url != "": self["href"] = url
self["description"] = description
self["hash"] = hash
self["dt"] = dt
if time != "": self["dt"] = time
self["tags"] = tags
if tag != "": self["tags"] = tag # tag or tags? # !! tags
self["extended"] = extended
self["user"] = user
self["count"] = count
def __getattr__(self, name):
try: return self[name]
except: object.__getattribute__(self, name)
class posts(list):
"""@xxx:bvb: idem as class post, python structures (dict/list) might
suffice or a more generic solution is needed.
"""
def __init__(self, *args):
for i in args: self.append(i)
def __getattr__(self, attr):
try: return [p[attr] for p in self]
except: object.__getattribute__(self, attr)
### Utility functions
def str2uni(s):
# type(in) str or unicode
# type(out) unicode
return ("".join([str(i) for i in s]))
def str2utf8(s):
# type(in) str or unicode
# type(out) str
return ("".join([str(i)
没有合适的资源?快使用搜索试试~ 我知道了~
pydelicious
共1个文件
py:1个
5星 · 超过95%的资源 需积分: 7 27 下载量 71 浏览量
2016-10-17
16:56:01
上传
评论
收藏 10KB ZIP 举报
温馨提示
解压后,直接放在python 中的Lib中就可以直接使用了。
资源推荐
资源详情
资源评论
收起资源包目录
pydelicious.zip (1个子文件)
2967f9c5ec8ebab5f622-a15baa8364f3795a1b21866696db95c20c1c3ac1
pydelicious.py 28KB
共 1 条
- 1
资源评论
- pchccc2017-07-20非常感谢,可以使用~~~
- luojlu2017-06-12可用,测试过了
鱼的一滴泪1990
- 粉丝: 16
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功