Introduction and goal

As I know that will help at least one person, here is how I publish new spoonerisms on my other Twitter account @kontrepeteries on a regular and automated basis.

(A) Solution

The solution I chosed is to CRON a servlet deployed on GAE/J. This servlet uses Twitter4J, a very quick & simple API.

Servlet code

The code is shortened for brevity.

Actually, the servlet displays what is tweeted so that I could verify all went well at write+test time.

public class FetchLatestContrepServlet extends HttpServlet {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
        {
                ...             
                // get spoonerism (gets PHP-generated JSON from my Free.fr website and unmarshall it)
                Contrep c = VaVoirChezFree.getUneContrepAvecIdSuperieur(bi.getHighestContrepId()); // just the id of the latest fetched contrep as parameter. 
                
                // UPD twitter status
                Twitter tw = new Twitter("YOUR_LOGIN","YOUR_PASSWORD");
                try {
                        tw.updateStatus( c.getText() );
                } catch (TwitterException e) {
                        log("twitter update error " + e.getMessage() );
                }

                writer.append( c.getId() );
                writer.append( c.getText() );
                w.flush();
                w.close();
        }
}

Configuration

Do usual conf in war\WEB-INF\web.xml

Example for file war\WEB-INF\cron.xml.

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
        <cron>
                <url>YOUR APP-RELATIVE URL HERE (starts with /) </url>
                <description>tweete a spoonerism</description>
                <schedule>every 8 hours</schedule>
        </cron>
</cronentries>

There is a possibility to restrain usage to the "admin" role so that you get sure it's only executed by the CRON launcher. See official documentation. But if you want to run it by hand, don't.

Epilogue

No rocket science here. This is how to do a CRON in GAEJ, you may modify this code to read tweets on a regular basis and save them to wherever you want (cloud, Free, ....).

If you have an Android device and a wave account, you may also check A wave regularly to save new blips to another place (twitter, DB) so that you can use your own (lighter) client to read waves. I've been told GW is slow on Android,

IMO, for wave-to-whatever data-transfer, use a wave robot.

Stay tuned for the release of my wave robot framework.

Meanwhile, if you understand French wordplays, @kontrepeteries may entertain you.

Follow me @wadael , it's sometimes worth it.

See you

Jérôme