C++ Program to tweet

less than 1 minute read

It's very interesting to play with C++ and if it is in GNU/Linux, lots of tools like 'wget', 'grep',etc. are there to help us in time. Here is a simple C++ snippet which tweets directly to your time line. Feel free to add more features and would be great if you could share it with me too :)

/*
 *      shell-tweet.cpp
 *
 *      Copyright 2009 Ershad K  ershad92@gmail.com
 *      Licensed under GPL Version 3
 *
 *      Please change USERNAME, PASSWORD and compile with g++
 *      To compile - g++ shell-tweet.cpp
 *      To execute - ./a.out
 */

#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int main()
{
char name[] = "username", password[] = "password", status[500], cmd[500];

char sym[] = {char(34),''};

again: cout << "n Status: ";
fgets (status,140,stdin);

cout << "n Length = " << strlen(status);

if (strlen(status) > 139)
{
cout << " Exceeds 140 character limit, Type again n";
goto again;
}
else
{

strcpy(cmd,"wget -nv --keep-session-cookies --http-user=");

strcat(cmd,name);
strcat(cmd," --http-password=");
strcat(cmd,password);
strcat(cmd," --post-data=");
strcat(cmd,sym);
strcat(cmd,"status=");
strcat(cmd,status);
strcat(cmd,sym);
strcat(cmd," http://twitter.com:80/statuses/update.xml");

system(cmd);

cout << "n Done";
}
return 0;
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...