C++ Program to tweet

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;
}

Easy Clarity – Connect Easily!

‘Disconnection’ is a routine process in dial up internet. Here is an C++ snippet which dials BSNL WLL Clarity without asking for password again and again. It automatically closes on disconnection with a beep sound.

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

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

using namespace std;

int main ()
{
	char username[] = "USERNAME";
	char password[] = "PASSWORD";
	puts("n EasyClarity - Connect wisely!  www.ershadk.wordpress.comnn");
	ofstream myfile;
	system("sudo wvdialconf");
	myfile.open ("/etc/widial.conf");
        myfile << "[Dialer Defaults]nInit1 = ATZnInit2 = ATQ0 V1 E1 S0=0 "
               << "&C1 &D2 +FCLASS=0nInit3 = at+crm=1;+cmux=1;+cps=33;+cta=0"
               << "nModem Type = Analog ModemnISDN = 0nPhone = #777nModem"
               << " = /dev/ttyUSB0nUsername = "<<username<<"nPassword = "
               <<password<<"nBaud = 460800nStupid Mode = 1nAuto DNSnCheck"
                <<" Def Route";
	myfile.close();
	system("sudo wvdial");
	cout << "a";
	return 0;
}