Monday, May 16, 2011

Google AppScript URLFetch and Spreasheet Example to Extract Information

Code which pulled all information through urlfetch and load it to spreadsheet.
Simple and cute.



function AddViewCount()
{
  var sheet = SpreadsheetApp.getActiveSheet();
  var prevcount = sheet.getRange(2, 8).getValue();
  prevcount = prevcount + 1;
  sheet.getRange(2, 8).setValue(prevcount);
  SpreadsheetApp.flush();
}

function CollectAllElectionDetails() {
  var sheet = SpreadsheetApp.getActiveSheet();  
  var consttotalcount = 234;
  var rowcount = 1;
  for(var constcount = 1; constcount <= consttotalcount; constcount++)
  {
  var response = UrlFetchApp.fetch("http://eciresults.nic.in/ConstituencywiseS22" + constcount + ".htm");
  var xmldoc = Xml.parse(response.getContentText(), true);
  var root = xmldoc.getElement(); 
  var child1 = root.getElements();
  var bodychilds = child1[1].getElements();
  var bodychilds1 = bodychilds[0].getElements(); 
  var bodychilds11 = bodychilds1[1].getElements();
  var bodychilds111 = bodychilds11[0].getElements();  
  var contestants = bodychilds111[4].getElements();
  var contestantdetails = contestants[0].getElements();
  var call1 = contestantdetails[3].getElements();
  var call11 = call1[1].getElements();
  var call111 = call11[0].getElements("table");
  var cleardetails = Xml.parse(call111[0].toXmlString(), false);
  var rowinfo =  cleardetails.table.tr.td.div.getElements()
  var rowinfo1 =  rowinfo[0].getElements("tr");   
  var constname = rowinfo1[0].td.getText().replace("Tamil Nadu - ","");
  var totalcandidates = rowinfo1.length - 3;
  for(var count=0; count < totalcandidates; count++ )
  {
    var candiname = rowinfo1[count+3].td[0].getText();
    var partyname = rowinfo1[count+3].td[1].getText();
    var totalvotes = rowinfo1[count+3].td[2].getText();
    sheet.getRange(rowcount+1, 1).setValue(constcount);
    sheet.getRange(rowcount+1, 2).setValue(constname);
    sheet.getRange(rowcount+1, 3).setValue(candiname);
    sheet.getRange(rowcount+1, 4).setValue(partyname);
    sheet.getRange(rowcount+1, 5).setValue(totalvotes);
    rowcount++;
  }
} 

}

Monday, May 9, 2011

TIFFtoPDF conversion - Image Bitmap File Lock Problem - Resolved



   string[] files = Directory.GetFiles(faxpath, "*.tif");
            foreach (string infilename in files)
            {
                PdfDocument document = new PdfDocument();                
                StreamReader imgstreamer = new StreamReader(infilename);                
                Bitmap bm = new Bitmap(imgstreamer.BaseStream);
                int total = bm.GetFrameCount(FrameDimension.Page);                
                _logger.Log("TIFtoPDFConversion", LogEntryType.Debug, "Converting TIF File: " + infilename);
                for (Int32 k = 0; k < total; k++)
                {
                    Bitmap bm2 = new Bitmap(infilename);
                    bm2.SelectActiveFrame(FrameDimension.Page, k);
                    XImage image = XImage.FromGdiPlusImage(bm2);
                    PdfPage page1 = document.AddPage();

                    // Get Image width, Height and Resolution and Set output document Width and Height in Inches
                    page1.Width = XUnit.FromInch(image.PixelWidth / image.HorizontalResolution);
                    page1.Height = XUnit.FromInch(image.PixelHeight / image.VerticalResolution);
                    XGraphics gfx = XGraphics.FromPdfPage(page1, XGraphicsPdfPageOptions.Append);
                    gfx.DrawImage(image, 0, 0);
                    gfx.Dispose();
                    image.Dispose();
                    page1.Close();
                    bm2.Dispose();
                }
                string pdffilename = infilename.Substring(0, infilename.ToLower().LastIndexOf(".tif") - 1) + ".pdf";
                _logger.Log("TIFtoPDFConversion", LogEntryType.Debug, "Completed Converting TIF File: " + infilename);
                // Save the PDF
                document.Save(pdffilename);
                imgstreamer.Close();
            }       


So Simple as that. Add pdfsharp in the reference nothing else to install.
Pdfsharp can be obtained from PDFSharp.

Friday, May 6, 2011

Call a WCF Service from Linux Nusoap



include('lib/nusoap.php');

$client = new nusoap_client('http://url.svc?wsdl', 'wsdl',
                $proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();
if ($err) {
echo "Constructor error";
exit;
}
$client->soap_defencoding = 'UTF-8';
$result = $client->call('DoWork');
echo $result['DoWorkResult'];
//echo $client->debug_str;
echo "\n";

Wednesday, April 20, 2011

TIFF to PDF Conversion using .Net - Free



            string infilename = "c:\\temp\\faxsample.tif";
            PdfDocument document = new PdfDocument();
            Bitmap bm = new Bitmap(infilename);
            int total = bm.GetFrameCount(FrameDimension.Page);
            for (Int32 k = 0; k < total; k++)
            {
                Bitmap bm2 = new Bitmap(infilename);
                bm2.SelectActiveFrame(FrameDimension.Page, k);
                XImage image = XImage.FromGdiPlusImage(bm2);
                PdfPage page1 = document.AddPage();
                
                // Get Image width, Height and Resolution and Set output document Width and Height in Inches
                page1.Width = XUnit.FromInch(image.Width / image.HorizontalResolution);
                page1.Height = XUnit.FromInch(image.Height / image.VerticalResolution);
                XGraphics gfx = XGraphics.FromPdfPage(page1, XGraphicsPdfPageOptions.Append);
                gfx.DrawImage(image, 0, 0);
                gfx.Dispose();
                image.Dispose();
                page1.Close();
                bm2.Dispose();
            } 
            document.Save("c:\\temp\\faxsample.pdf");
            Console.WriteLine("Total Pages: " + total);


So Simple as that. Add pdfsharp in the reference nothing else to install.
Pdfsharp can be obtained from PDFSharp.

Monday, April 18, 2011

Tropo ClicktoCall with Conference in PHP - Cloud Telephony



$calloptions['onAnswer'] = 'secondCallInitiator';
$calloptions['callerID'] = 'Calleridhere';
call('+1'.$numbertodial, $calloptions);

function secondCallInitiator($event)
{
$confid = $conferenceid;
$confoptions['mute'] = false;
$confoptions['playTones'] = true;
$confoptions['leaveprompt'] = 'beep';
$sleep(2);
Say('Please hold');
Conference($confid,$confoptions);
}


Pass two variables, numbertodail & conferenceid as POST parameters.
ClicktCall with Conference, That is so Simple to a Complex Infrastructure.

Tropo ClicktoCall PHP Script - Cloud Internet Telephony Made Easy !



$aftercalloptions['onAnswer'] = 'onAnswerCB';
call('+1'. agentnumber, $aftercalloptions);

function onAnswerCB($event)
{
    global $customernumber;
    Sleep(3);
    transfer('+1' . $customernumber);
}



Cool and Pretty for a Complex Need !

Initiate a call with the following URL
https://api.tropo.com/1.0/sessions?action=create&token=yourtoken&agentnumber=agentnum&customernumber=custnum

Ensoy !

Monday, September 27, 2010

Adding a New Call to the SugarCRM through Code

Ass a new Call to the SugarCRM through Code.



                    $call = new Call();

                    $call->direction = 'Outbound';

                    $call->status = 'Planned';

                    $call->contact_id = $contactid;

                    $call->duration_hours = '0';

                    $call->duration_minutes = '15';

                    $call->date_start = $date; // (mm/dd/yyyy hh:mmTT) format

                    $call->name = $subjectstring;

                    $call->assigned_user_id = $current_user->id;

                    $call->team_id = '1';

                    $call->team_set_id = '1';

                    $call->save();

                // Create the relationship to Contact to appear in the Contact Subpanel

                    $contact = new Contact();

                    $contact->retrieve($call->contact_id);

                    $contact->load_relationship('calls');

                    $contact->calls->add($call->id);



Enjoy.