Created
June 6, 2011 06:17
-
-
Save hj91/1009817 to your computer and use it in GitHub Desktop.
Generic class to enable posting and eading mentions on identi.ca or statusnet microblogging sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# * coding: utf-8 * | |
# (c) Harshad Joshi, 2011 | |
# Post on identi.ca using CLI | |
import json, urllib2 | |
from urllib import urlencode | |
import sys,feedparser | |
class IdentiCa: | |
def __init__(self,user,pwd,apibase): | |
self.user = user | |
self.pwd = pwd | |
self.apibase = apibase | |
def post(self,msg): | |
# connection magic | |
pwd_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
pwd_mgr.add_password(None, self.apibase, self.user, self.pwd) | |
handler = urllib2.HTTPBasicAuthHandler(pwd_mgr) | |
opener = urllib2.build_opener(handler) | |
urllib2.install_opener(opener) | |
# now define a message | |
self.msg = msg | |
if (self.msg.lower() == 'exit'): | |
sys.exit(0) | |
else: | |
if (self.msg.lower() == 'mentions'): | |
a=urllib2.urlopen("http://identi.ca/api/statuses/mentions/hj91.rss") | |
b=feedparser.parse(a) | |
for i in range(len(b.entries)): | |
print b.entries[i].title | |
del(a) | |
del(b) | |
else: | |
# url encode it nicely and set your own client name – no links in source! | |
themsg =urlencode({'status':self.msg,'source':'CollaborativeMicroblogging'}) | |
# and send the notice | |
urllib2.urlopen(self.apibase+'/statuses/update.json?s', themsg) | |
m=IdentiCa(user = "hj91",pwd = " ",apibase = "https://identi.ca/api") | |
while(1): | |
c=raw_input ("Enter somthing >> ") | |
m.post(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This class is part of SocialBridge v0.1