Commits

hideki nara committed 1210837

yummy.py -> ym.py

  • Participants
  • Parent commits b1b0dbb

Comments (0)

Files changed (6)

 yummy
 ========================================================================
 
-under development.
+under development.
+
+
+Delicious account in Pit
+------------------------------
+
+::
+    
+    python -c "from pit import Pit;Pit.set('delicious')"
+
-Sphinx
+Sphinx
+pit
 NAME='yummy'
 DESCRIPTION=''
 PACKAGES=['yummy',]
-SCRIPTS=['src/scripts/yummy.py', ]
+SCRIPTS=['src/scripts/ym.py', ]
 try:
     INSTALL_REQUIRES=[ r for r in open('requirements.txt').read().split('\n') if len(r)>0]
 except:

src/scripts/ym.py

+import os
+from pit import  Pit
+import urllib2
+from xml.dom import minidom
+
+UA='Python yummy.py'
+
+def main_old():
+#     curl https://$DUID:$DPWD@api.del.icio.us/v1/posts/all?tag=bitbucket
+#          https://            api.del.icio.us/v1/post?tags=bitbucket
+
+
+    conf =Pit.get('delicious')
+    auth_handler = urllib2.HTTPBasicAuthHandler()
+    auth_handler.add_password("del.icio.us API", "%(api_scheme)s://%(api_host)s/" % conf, 
+                            conf['username'], conf['password'])
+
+    opener = urllib2.build_opener(auth_handler)
+    opener.addheaders = [("User-agent", UA)] 
+    urllib2.install_opener(opener)
+
+   
+    POST= "%(api_scheme)s://%(api_host)s/%(api_ver)s/posts/all?tag=bitbucket" % conf
+
+    print conf
+    print POST
+    if False:
+        return
+
+    res = urllib2.urlopen(POST)
+
+    xmldom = minidom.parseString(res.read())
+
+    for post in xmldom.documentElement.childNodes:
+        postdict = {}
+        print "Description:", post.attributes['description'].value
+        print "URL:",post.attributes['href'].value
+        print ""
+
+def main():
+    from yummy.api import Api
+    for post in api.post(tag='bitubuker').documentElement.childNodes:
+        postdict = {}
+        print "Description:", post.attributes['description'].value
+        print "URL:",post.attributes['href'].value
+        print ""
+    
+if __name__ == '__main__':
+    main()

src/scripts/yummy.py

-import os
-
-def main():
-    pass
-
-if __name__ == '__main__':
-    main()
+import os
+from pit import  Pit
+import urllib2
+from xml.dom import minidom
+
+UA='Python yummy.py'
+
+class Api(object):
+
+    def __init__(self,conf=None):
+        if conf == None:
+            conf =Pit.get('delicious')
+
+        self.conf = conf
+        self.conf['UA'] = UA
+        self.basic_auth()
+
+    def basic_auth(self):
+        conf = self.conf
+        auth_handler = urllib2.HTTPBasicAuthHandler()
+        auth_handler.add_password("del.icio.us API", "%(api_scheme)s://%(api_host)s/" % conf, 
+                                conf['username'], conf['password'])
+    
+        opener = urllib2.build_opener(auth_handler)
+        opener.addheaders = [("User-agent", conf['UA'])] 
+        urllib2.install_opener(opener)
+
+    
+    def _request(self,url):
+        res = urllib2.urlopen(url)
+        return  minidom.parseString(res.read())
+
+    def post(self,tag=None):
+        url =  "%(api_scheme)s://%(api_host)s/%(api_ver)s/posts/all?" % self.conf
+        if tag:
+            #: URL encoding....
+            url = url + "tag=%s" % tag
+
+        return self._reuqest(url)