Get number of your subscribers from Feedburner
January 27, 2010 | python, toolsauthor: Karol Zielinski | comments: 1 | views: 1188
Tags: django, feed, feedburner, google, python, rss, subscriber
While we already know how to create script for getting number of followers from twitter – now it’s the best time for getting number of subscribers from feedburner. Everything will be done in python (django).
What is Feedburner? It’s a great tool for managing RSS feeds.
Why I may want to have number of subscribers? Because we may want to show that number on our website.
We will use Feedburner’s API. What you should read is: Past Basic Feed Awareness Data
I will use XMLObject class to parse XMLs, because I simply like it.
Ok, let’s code…
Open your *.py file (it could be main/views.py) and add there one new method:
def getFeedburner(request):
from datetime import datetime as datetime2now
today = datetime2now.now().date()
actTime = datetime2now.now().timetz()
actTime = str(actTime)
actTime = actTime[:8]
oneDay = datetime.timedelta(days=1)
twoDays = datetime.timedelta(days=2)
yesterday = today - oneDay
twodaysago = today - twoDays
from develway.main.xmlobject import XMLFile
url = 'https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=URI_OF_MY_WEBSITE&dates=' + str(twodaysago) + ',' + str(yesterday)
f = urllib.urlopen(url)
xml = f.read()
xml = XMLFile(raw=xml)
entries = xml.root.feed.entry
circulation_yesterday = None
circulation_twodaysago = None
for each_entry in entries:
if each_entry._get('date') == str(yesterday):
circulation_yesterday = each_entry._get('circulation')
elif each_entry._get('date') == str(twodaysago):
circulation_twodaysago = each_entry._get('circulation')
if circulation_yesterday:
value = circulation_yesterday
elif circulation_twodaysago:
value = circulation_twodaysago
return HttpResponse(str(value))
That’s all. Now add new view to your urls.py:
(...)
(r'^get-feedburner/$', 'YOUR_PROJECT.main.views.getFeedburner'),
and test it by going to the URL: http://your_domain/get-feedburner/
Everything should work fine.
Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.
January 27, 2010, 4:55 am
[...] tech.karolzielinski.com Follow us on Twitter 22 śledzących RSS Feed 187 czytelników Liczba subskrybentów z Feedburner'a 1 głosuj! Tworzymy skrypt do pobierania liczby subskrybentów kanału RSS z [...]