Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Twitter and Jaiku from the command line

The following instructions make it easy to post to Twitter and Jaiku from the command line. The instructions were copied from the article "Ubuntu Unleashed: Howto Twitter From the Command Line in Ubuntu!" [ubuntu-unleashed.com] and modified to post via Rorbuilder's ProjectX API.

sudo apt-get install curl

sudo gedit /usr/bin/jaitwit

Now Paste this in gEdit and simply replace "YourUsername" with your username and "YourPassword" with your twitter passwd, then replace the Jaiku variables (YourUsername, YourPassword, YourCity, YourAccessKey) and ctrl-s to save, then alt-F4 to exit!
curl http://rorbuilder.info/api/projectx.cgi?xml_project=%3Cproject%20name=%22micro_blog%22%3E%3Cmethods%3E%3Cmethod%20name=%22post2jaiku%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22location%22%20val=%22YourCity%22/%3E%3Cparam%20var=%22apikey%22%20val=%22YourAccessKey%22/%3E%3C/params%3E%3C/method%3E%3Cmethod%20name=%22post2twitter%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22password%22%20val=%22YourPassword%22/%3E%3C/params%3E%3C/method%3E%3C/methods%3E%3C/project%3E -o /dev/null
echo Message Sent!

Then chmod for exec privileges:
chmod +x /usr/bin/jaitwit

Then from the CLI type jaitwit followed by your message.
jaitwit "message here without the quotes"

Post to Jaiku using PHP

This example uses the ProjectX API to post to Jaiku.com
<?php
  $msg = 'this is just a test message using the ProjectX API for posting to Jaiku';

  $xml_result =  simplexml_load_file('http://rorbuilder.info/api/projectx.cgi?xml_project=<project name="jaiku"><methods><method name="post"><params><param var="user" val="jrobertson"/><param var="msg" val="' . $msg . '"/><param var="location" val="London"/><param var="apikey" val="9ee6ffd165r364492"/></params></method></methods></project>');
  $method_result = $xml_result->post2jaiku;
  echo 'result' . $method_result;
?>


Reference: SimpleXML processing with PHP [ibm.com]

Post to both Jaiku and Twitter

This XML code is the ProjectX API to post to both Twitter and Jaiku. This is a follow-up example from Post to Jaiku using ProjectX API [dzone.com]

xml_project = <<PROJECT
<project name='micro_blog'>
  <methods>
    <method name='post2jaiku'>
      <params>
        <param var='user' val='YourJaikuUserName'/>
        <param var='msg' val='YourMessage'/>
        <param var='location' val='YourCity'/>
        <param var='apikey' val='YourApiKey'/>
      </params>
    </method>
    <method name='post2twitter'>
      <params>
        <param var='user' val='YourTwitterUserName'/>
        <param var='msg' val='YourMessage'/>
        <param var='password' val='YourPassword'/>
      </params>
    </method>    
  </methods>
</project>"
PROJECT

Post to Jaiku using ProjectX API

This Ruby code uses the ProjectX API on rorbuilder.info to send a post to Jaiku.

Prerequisites:
1) You have a Jaiku account. see http://jaiku.com/
2) You know your Jaiku API key. see http://api.jaiku.com/

#!/usr/bin/ruby
# file: projectx_client.rb

require 'net/http'
require 'rexml/document'
include REXML

class ProjectXClient
  attr :doc
  def initialize(raw_url)
    url = URI.escape(raw_url)
    xml_data = Net::HTTP.get_response(URI.parse(url)).body
    @doc = Document.new(xml_data)
  end
  
end

if __FILE__ == $0

xml_project = <<PROJECT
<project name='jaiku'>
  <methods>
    <method name='post'>
      <params>
        <param var='user' val='YourJaikuUserName'/>
        <param var='msg' val='YourMessage'/>
        <param var='location' val='YourCity'/>
        <param var='apikey' val='YourApiKey'/>
      </params>
    </method>
  </methods>
</project>"
PROJECT
  
  pxc = ProjectXClient.new("http://rorbuilder.info/api/projectx.cgi?xml_project=" + xml_project)
  doc = pxc.doc
  puts doc
    
end



You can also pass the url including xml into the address bar and it will post to Jaiku successfully.
eg.
http://rorbuilder.info/api/projectx.cgi?xml_project="<project name='jaiku'><methods><method name='post'><params><param var='user' val='jrobertson'/><param var='msg' val='testing 223'/><param var='location' val='London'/><param var='apikey' val='5ugr6ttr754y214445'/></params></method></methods></project>"

Note:
Your api key is not in any way stored by the website rorbuilder.info.
Rorbuilder.info is a 3rd party developer website which is not part of Jaiku.com.

jaiku.conf

// example configuration file for jaiku.py

config = "jaiku.conf"
xmlrpcurl = "http://api.jaiku.com/xmlrpc"
feedurlstart = "http://"
feedurlend = ".jaiku.com/feed/atom"
itemdelimeter = "<entry>"
titledelimeter1 = "<title>"
titledelimeter2 = "</title>"
username = "mcandre"
personalkey = "FILL IN YOUR API KEY HERE"
location = ""

jaiku.py

// Set and view Jaiku statuses

#!/usr/bin/env python

__author__="Andrew Pennebaker (andrew.pennebaker@gmail.com)"
__date__="28 Jun 2007"
__copyright__="Copyright 2007 Andrew Pennebaker"
__license__="GPL"
__version__="0.0.1"
__URL__="http://snippets.dzone.com/posts/show/4223"

import sys, getopt, urllib2, xmlrpclib

import configreader

STATUS_MODE="STATUS"
VIEW_MODE="VIEW"

def set_status(settings, status):
	s=xmlrpclib.ServerProxy(settings["xmlrpcurl"])
	
	calldata={"user":settings["username"], "personal_key":settings["personalkey"], "message":status, "location":settings["location"]}
	
	try:
		s.presence.send(calldata)
	except:
		raise "Could not connect."

def view_status(settings):
	item=settings["itemdelimeter"]
	t1=settings["titledelimeter1"]
	t2=settings["titledelimeter2"]

	try:
		instream=urllib2.urlopen(
			settings["feedurlstart"]+settings["username"]+settings["feedurlend"]
		)

		for line in instream:
			if item in line:
				break

		title=instream.readline()

		instream.close()

		status=title[title.index(t1)+len(t1):title.index(t2)]

		return status

	except IOError, e:
		raise "Could not connect."

def usage():
	print "Usage: %s [options]" % (sys.argv[0])
	print "\nWithout any options, uses status mode. Leftover args are concatenated to form message."
	print "\n-u|--username <username> specified in jaiku.conf"
	print "-p|--personal-key <key>"
	print "-l|--location <location>"
	print "-s|--status mode"
	print "-v|--view status"
	print "-c|--config <configfile>"
	print "-h|--help"

	sys.exit()

def main():
	global STATUS_MODE
	global VIEW_MODE

	systemArgs=sys.argv[1:]

	mode=STATUS_MODE

	settings={
		"config":"jaiku.conf",
		"xmlrpcurl":"http://api.jaiku.com/xmlrpc",
		"feedurlstart":"http://",
		"feedurlend":".jaiku.com/feed/atom",
		"itemdelimeter":"<entry>",
		"titledelimeter1":"<title>",
		"titledelimeter2":"</title>",
		"username":"mcandre",
		"personalkey":"",
		"location":""
	}

	optlist, args=[], []

	try:
		optlist, args=getopt.getopt(systemArgs, "u:p:l:svc:h", ["username=", "personal-key=", "location=", "status", "view", "config=", "help"])
	except e:
		usage()

	for option, value in optlist:
		if option=="-c" or option=="--config":
			settings["config"]=value

	try:
		configreader.load(open(settings["config"], "r"), settings)
	except IOError, e:
		pass

	for option, value in optlist:
		if option=="-h" or option=="--help":
			usage()

		elif option=="-u" or option=="--username":
			settings["username"]=value
		elif option=="-p" or option=="--personal-key":
			settings["personalkey"]=value
		elif option=="-l" or option=="--location":
			settings["location"]=value
		elif option=="-s" or option=="--status":
			mode=STATUS_MODE
		elif option=="-v" or option=="--view":
			mode=VIEW_MODE

	if mode==STATUS_MODE:
		if len(args)<1:
			usage()

		message=" ".join(args)

		set_status(settings, message)
	elif mode==VIEW_MODE:
		print view_status(settings)

if __name__=="__main__":
	try:
		main()
	except KeyboardInterrupt, e:
		pass
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS