Sunday, February 21, 2016

Cashless transaction with local Transport - part 3


package JavaSMSProject;


import java.net.*;

public class CopyOfSMSclass {
public void sendSMS(Integer amount, Integer bal, String recipient) {
        try {
                //String recipient = "918888899999"; // Receipietnt mobile number
                String message = "Your account has been deducted with" + amount + "your current balance is" + bal;
                String username = "xxx";  //Username that you have registered with OzekiNG
                String password = "xxx"; // Password that you have registered with OzekiNG
                String originator = "918888866666"; // Sender mobile number

                String requestUrl  = "http://127.0.0.1:9501/api?action=sendmessage&" +
    "username=" + URLEncoder.encode(username, "UTF-8") +
    "&password=" + URLEncoder.encode(password, "UTF-8") +
    "&recipient=" + URLEncoder.encode(recipient, "UTF-8") +
    "&messagetype=SMS:TEXT" +
    "&messagedata=" + URLEncoder.encode(message, "UTF-8") +
    "&originator=" + URLEncoder.encode(originator, "UTF-8") +
    "&serviceprovider=HTTPServer0" +
    "&responseformat=html";
             
                //GSMModem1



                URL url = new URL(requestUrl);
                HttpURLConnection uc = (HttpURLConnection)url.openConnection();

                System.out.println(uc.getResponseMessage());

                uc.disconnect();

        } catch(Exception ex) {
                System.out.println(ex.getMessage());

        }
}


}


This class triggers SMS gateway and sends the information to the customer.

A basic application to work with SMS along with cashless transaction with local transport and it has few enhancements to work on.






Cashless transaction with local Transport - part 2

Readdatabase.class

package JavaSMSProject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;



public class ReadDatabase {

public void writeToExcel(String fileName, String uid, String amount) throws IOException {

Integer cellValue = 0;
Integer cellAmount = 0;
Integer bal = 0;
Integer phoneNumber = 0;

FileInputStream fsIP= new FileInputStream(new File(fileName));
XSSFWorkbook workbook = new XSSFWorkbook(fsIP);
XSSFSheet sheet = workbook.getSheetAt(0);

int count = sheet.getPhysicalNumberOfRows();
System.out.println(count);

List<String> list = new ArrayList<String>();
/*int size = list.size(); */

  for(int i=0; i < count - 1; i++){

  XSSFRow row1 = sheet.getRow(i + 1);
  Cell cell1 = row1.getCell(0);

  cellValue = (int)Math.round(cell1.getNumericCellValue());

  System.out.println("UserId:" + cellValue);

  String matchuid = cellValue.toString();

  if(uid.equalsIgnoreCase(matchuid)){

  Cell cell2 = row1.getCell(1);

  cellAmount = (int)Math.round(cell2.getNumericCellValue());

  System.out.println("Amount:" + cellAmount);

  bal = cellAmount - Integer.parseInt(amount);

  System.out.println("Bal remaning:" + bal);

  Cell cell3 = row1.getCell(2);

  phoneNumber = (int)Math.round(cell3.getNumericCellValue());

  System.out.println("Phone number:" + phoneNumber);

  cell2.setCellValue(bal.doubleValue());

 
  CopyOfSMSclass sms = new CopyOfSMSclass();
  sms.sendSMS(Integer.parseInt(amount), bal, phoneNumber.toString());

  break;



  }//if


  //list.add(cell1.getStringCellValue());

  }//for

  System.out.println("Sorry no such user found");

  fsIP.close();
 try (FileOutputStream outputStream = new FileOutputStream(new File(fileName))) {
 workbook.write(outputStream);
}

catch (FileNotFoundException e) {
   
       e.printStackTrace();
   }


}

}

Cashless transaction with local Transport

The goal of this project is to send SMS to people who have been registered with an local transport organization where  they pay amount in advance and travel through out the year as  long as they have balance available.

For this project I have used OzekiNG to simulate SMS.


Here are the class files:

Deduct balance.class


package JavaSMSProject;

import java.io.IOException;
import java.util.Scanner;


public class Deductbalance {


public static void main(String[] args) throws IOException {

Scanner in  = new Scanner(System.in);
System.out.println("Enter the user id:");
String user_id = in.next();
//in.close();

Scanner in2  = new Scanner(System.in);
System.out.println("Enter the amount:");
String amount = in2.next();
//sin2.close();

String workingDir = System.getProperty("user.dir");
String fileName = workingDir + "\\resources\\Localtransportdatabase.xlsx";
//String path =

ReadDatabase rd = new ReadDatabase();

rd.writeToExcel(fileName, user_id, amount);


}





}

Other classes are in next posts.





Reading csv file using python

import unicodecsv

with open(filename , 'rb') as f:
    read_data = unicodecsv.DictReader(f)
    data = list(read_data )
   
print data [:]