Members List |
Social Groups |
Calendar |
Search |
Today's Posts |
![]() |
![]() |
#181 | ||
|
|||
Member
Join Date: Apr 2013
Location: 2 1/2 hours from the North Store
Posts: 362
|
Does it matter what your number is? When they get to you then you will be notified. Numbers are being assigned to all 19000 orders. When yours comes up you will be notified. If your number is above the allotment of the years 1911's you be in line for next year
|
||
![]() |
![]() |
![]() |
#182 | |||
|
||||
Senior Member
Join Date: Mar 2010
Location: Cuba on the Chesapeake
Posts: 5,484
|
OK CMP, here you go.
This Java code will read in a file of customers emails, assign randomly, numbers starting at 1000, write the results to a CSV like that can be read by a spreadsheet, and email these out to everyone. /* * */ package com.siriusjava.cmprng.cmprng; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Random; import javax.mail.Session; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.Multipart; import javax.mail.PasswordAuthentication; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; /** * * @author dreadpirate */ public class ProcessCustomers { private class Customer { private String customerNumber; private String customerEmail; private int randomNumber; public String getCustomerNumber() { return customerNumber; } public void setCustomerNumber(String customerNumber) { this.customerNumber = customerNumber; } public String getCustomerEmail() { return customerEmail; } public void setCustomerEmail(String customerEmail) { this.customerEmail = customerEmail; } public int getRandomNumber() { return randomNumber; } public void setRandomNumber(int randomNumber) { this.randomNumber = randomNumber; } public String getDataLine() { return customerEmail + "," + customerNumber + "," + randomNumber; } @Override public String toString() { return "Customer{" + "customerNumber=" + customerNumber + ", customerEmail=" + customerEmail + ", randomNumber=" + randomNumber + '}'; } } private List<Customer> customerData = new ArrayList<Customer>(); private String dataFileInName; private String dataFileOutName; private Properties prop = new Properties(); private Session session; private ProcessCustomers() { } public static void main(String[] args) { int statusCode = 0; ProcessCustomers instance = new ProcessCustomers(); try { System.out.println("Start ..."); instance.processArgs(args); instance.readNamesFromFile(); instance.assignRandomNumbers(); instance.writeResults(); instance.emailOutNotice(); } catch (Exception e) { statusCode = 1; e.printStackTrace(); } System.out.println("Done"); System.exit(statusCode); } public void processArgs(String[] args) { dataFileInName = args[0]; dataFileOutName = args[1]; } public void readNamesFromFile() { try ( BufferedReader objReader = new BufferedReader(new FileReader(dataFileInName))) { String strCurrentLine = null; while ((strCurrentLine = objReader.readLine()) != null) { String[] fields = strCurrentLine.split(","); String email = fields[0]; String customerNumber = fields[1]; Customer customer = new Customer(); customer.setCustomerEmail(email.trim()); customer.setCustomerNumber(customerNumber.trim()); customerData.add(customer); } } catch (IOException e) { throw new RuntimeException(e); } } public void assignRandomNumbers() { assignRandom(); for (Customer c : customerData) { System.out.println(c); } } public void writeResults() { try ( FileWriter writer = new FileWriter(dataFileOutName, true); BufferedWriter bufferedWriter = new BufferedWriter(writer) ![]() for (Customer c : customerData) { String lineOut = c.getDataLine(); bufferedWriter.write(lineOut); bufferedWriter.newLine(); } } catch (Exception e) { throw new RuntimeException(e); } } public void emailOutNotice() { setupEmailProps(); createEmailSession("myEmailUser", "myEmailPass"); for (Customer c : customerData) { sendEmail(c); } } private void assignRandom() { Random rand = new Random(); List<Customer> givenList = new ArrayList(customerData); int randomNumber = 1000; int numberOfElements = customerData.size(); for (int i = 0; i < numberOfElements; i++) { int randomIndex = rand.nextInt(givenList.size()); Customer randomCustomer = givenList.get(randomIndex); randomCustomer.setRandomNumber(randomNumber++); givenList.remove(randomIndex); } } private void createEmailSession(String username, String password) { session = Session.getInstance(prop, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); } private void setupEmailProps() { prop.put("mail.smtp.auth", true); prop.put("mail.smtp.starttls.enable", "true"); prop.put("mail.smtp.host", "smtp.mailtrap.io"); prop.put("mail.smtp.port", "25"); prop.put("mail.smtp.ssl.trust", "smtp.mailtrap.io"); } private void sendEmail(Customer customer) { try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("nobody@cmp.org")); message.setRecipients( Message.RecipientType.TO, InternetAddress.parse(customer.getCustomerEmail()) ); message.setSubject("CMP 1911 Random Number Assignment"); String msg = "Your random number assigment is " + customer.getRandomNumber(); MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeBodyPart.setContent(msg, "text/html"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(mimeBodyPart); message.setContent(multipart); Transport.send(message); } catch (Exception e) { throw new RuntimeException(e); } } }
__________________
US Army Veteran 82 - 92 NRA Life Member Maryland Shall Issue Executive Member SOTAR Alumnus |
|||
![]() |
![]() |
![]() |
#183 | |||
|
||||
HVAC Expert
Join Date: Sep 2011
Location: Outside the Gates
Posts: 11,365
|
Which grade are purchasers selecting?
__________________
2A ... Federal Preemption Thus, the only inquiry that this Court should conduct is to determine whether the firearms prohibited by the Act are protected by the Second Amendment. Because they are, the Act is simply unconstitutional. |
|||
![]() |
![]() |
![]() |
#184 | |||
|
||||
Heavy weight
|
I havent heard anything. I guess we will see.
|
|||
![]() |
![]() |
![]() |
#185 | ||
|
|||
Member
Join Date: Apr 2013
Location: 2 1/2 hours from the North Store
Posts: 362
|
only grade available now is Service Grade
|
||
![]() |
![]() |
![]() |
#186 | |||
|
||||
HVAC Expert
Join Date: Sep 2011
Location: Outside the Gates
Posts: 11,365
|
__________________
2A ... Federal Preemption Thus, the only inquiry that this Court should conduct is to determine whether the firearms prohibited by the Act are protected by the Second Amendment. Because they are, the Act is simply unconstitutional. |
|||
![]() |
![]() |
![]() |
#187 | ||
|
|||
Member
Join Date: Jan 2013
Location: The Burnie
Posts: 404
|
They did. All the packets have numbers. When they get to the packet, in that numerical order, they check it, then send out the email telling you what your number is and if the packet is good to go or not. Or at least that’s the impression I got reading their forum from the admins.
|
||
![]() |
![]() |
![]() |
#188 | ||
|
|||
Member
Join Date: Jan 2013
Location: The Burnie
Posts: 404
|
It’s not that your packet doesn’t have a number yet. It’s that they haven’t gotten to that number of checking packets yet.
|
||
![]() |
![]() |
![]() |
#189 | ||
|
|||
Member
Join Date: Apr 2013
Location: 2 1/2 hours from the North Store
Posts: 362
|
exactly, some people just don't understand
|
||
![]() |
![]() |
![]() |
#190 | |||
|
||||
Scribe
Join Date: Dec 2008
Posts: 4,880
|
||||
![]() |
![]() |
![]() |
|
Thread Tools | |
Display Modes | |
|
|