Commits

Marcin Kasperski  committed c73924f

Initial import (copied from mekk.feeds)

  • Participants

Comments (0)

Files changed (8)

+syntax: regexp
+
+~$
+semantic\.cache$
+\.py[co]$
+^src/mekk\.greader\.egg-info/
+^build/
+^dist/
+Copyright (c) 2009-2010 Marcin Kasperski
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author or contributors may not be used to endorse or
+   promote products derived from this software without specific prior
+   written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+Extremely minimal PostRank client.
+
+At the moment only feed status checking is implemented.
+
+Source code is available on `BitBucket`_, use this page to
+report bugs and offer patches.
+
+.. _BitBucket: http://bitbucket.org/Mekk/mekk.postrank
+

File sample/test_postrank_client.py

+# -*- coding: utf-8 -*-
+
+from mekk.postrank import PostRankClient
+from pprint import pprint
+
+pr = PostRankClient("mekk.waw.pl/test")
+
+for url in [
+    "http://feeds.feedburner.com/SmashingMagazine",
+    "http://feeds.mekk.waw.pl/NotatnikZapisywanyWieczorami",
+    ]:
+    print 
+    print url
+    print
+    pprint(pr.feed_info(url))
+
+# -*- coding: utf-8 -*-
+# (c) 2008, Marcin Kasperski
+
+from setuptools import setup, find_packages
+
+version = '0.1.0'
+long_description = open("README.txt").read()
+classifiers = [
+    "Programming Language :: Python",
+    "Intended Audience :: Developers",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+    # TODO: Development Status, Environment, Topic
+    ]
+
+setup(name='mekk.postrank',
+      version=version,
+      description="Simple wrapper for PostRank API.",
+      long_description=long_description,
+      classifiers=classifiers,
+      keywords='org',
+      license='BSD',
+      author='Marcin Kasperski',
+      author_email='Marcin.Kasperski@mekk.waw.pl',
+      url='http://bitbucket.org/Mekk/mekk.postrank',
+      package_dir={'':'src'},
+      packages=find_packages('src', exclude=['ez_setup', 'examples', 'tests']),
+      namespace_packages=['mekk'],
+      test_suite = 'nose.collector',
+      include_package_data = True,
+      package_data = {
+        'mekk' : [
+            'README.txt',
+            'LICENSE.txt',
+            #'doc/usage.txt',
+            ],
+        },
+      zip_safe = True,
+      install_requires=[
+        'simplejson',
+      ],
+      tests_require=[
+        'nose',
+        ],
+)

File src/mekk/__init__.py

+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

File src/mekk/postrank/__init__.py

+from postrank_client import PostrankClient

File src/mekk/postrank/postrank_client.py

+# -*- coding: utf-8 -*-
+
+import urllib, urllib2
+import re
+import simplejson
+import time
+
+import logging
+log = logging.getLogger("postrank")
+
+POSTRANK = 'http://api.postrank.com/v1/'
+
+class PostRankClient(object):
+    """
+    PostRank (http://www.postrank.com) access client.
+    """
+
+    def __init__(self, appkey):
+        """
+        appkey - symbolic application identifier, for example domain name
+        """
+        self.appkey = appkey
+
+    def feed_info(self, feed_url):
+        """
+        Dla zadanego feedu zwraca podstawowe informacje na jego temat.
+        
+        Uwaga: funkcja zwykle zwraca rozbudowany słownik ale może
+        zwrócić None gdy dostanie błąd HTTP 202 (co sygnalizuje, że
+        kiedyś się pojawi...)
+        """
+
+        query = {
+            'appkey' : self.appkey,
+            'format' : 'json',
+            'id' : feed_url,
+            }
+        enc_query = urllib.urlencode(query)
+
+        url = "http://api.postrank.com/v2/feed/info?" + enc_query
+
+        request = urllib2.Request(url.encode('utf-8'))
+
+        log.info("Calling: %s" % request.get_full_url())
+        try:
+            f = urllib2.urlopen(request)
+        except urllib2.HTTPError, e:
+            if e.code == 202:
+                log.info("HTTP:202 (accepted) - feed accepted for processing")
+                return None
+            else:
+                raise
+        result = f.read()
+        log.debug("Result: %s" % result)
+
+        return simplejson.loads(result)
+