Kim:Name Shifter: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
(New page: import java.io.*; import java.util.*; public class Name_Shifter_KG { public static void main(String []args) throws FileNotFoundException { Scanner console = new Scanner(System.in)...)
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Edit page to access code
<!--
// Name Shifter, By Kevin Gray
// This program moves entries from the "undergraduates" or "research scientists"
// sections of the website to the "former members" section. It requires two text
// files: 1) The body of the undergraduate section titled "UndergradCode" and 2)
// the body of the former members section, titled "FormerCode". Output files for the
// Undergraduates or Former Members sections are respectively titled UndergradPage.txt and
// FormerPage.txt.
import java.io.*;  
import java.io.*;  
import java.util.*;
import java.util.*;
Line 4: Line 16:
public class Name_Shifter_KG {
public class Name_Shifter_KG {


public static void main(String []args) throws FileNotFoundException {
  public static void main(String []args) throws FileNotFoundException {
  Scanner console = new Scanner(System.in);
      Scanner console = new Scanner(System.in);
  PrintStream removeables = new PrintStream( new File("removeables.txt"));
      ArrayList<String> ActiveMembers = new ArrayList<String>();
  String more = "y";
      ArrayList<String> FormerMembers = new ArrayList<String>();
  while (more.equals("y")){
      Map<String,String> Pics = new TreeMap<String,String>();
      System.out.println("enter a name to delete");
      Map<String,String> Emails = new TreeMap<String,String>();
      removeables.println(console.nextLine());
      Map<String,String> Position = new TreeMap<String,String>();
      System.out.println("any more names? y/n");
 
      more = console.nextLine();
      Scanner ActiveInput = new Scanner(new File("UndergradCode.txt"));
      Scanner FormerInput = new Scanner(new File("FormerCode.txt"));
      PrintStream UndergradPage = new PrintStream(new File("UndergradPage.txt"));
      PrintStream FormerPage = new PrintStream(new File("FormerPage.txt"));  
   
      assignNames(ActiveInput, ActiveMembers, Pics, Emails, Position);     
      String more = "y";
      while (more.equals("y")){
        System.out.println(ActiveMembers);
        System.out.println("enter a person to deactivate");
        String Name = console.nextLine();
      FormerMembers.add("\'\'\'" + Name + "\'\'\'");
      ActiveMembers.remove("\'\'\'" + Name + "\'\'\'");
        System.out.println("any more names? y/n");
        more = console.nextLine();
      }
 
PrintPage(ActiveMembers, Emails, Pics, UndergradPage, Position);
  for (String i : FormerMembers) {
      Position.put(i, "Undergraduate Student"); // Change to "Research Scientist" when updating
                                                // Reaserch Scientist page
   }
   }
 
 
   
assignNames(FormerInput, FormerMembers, Pics, Emails, Position);
 
PrintPage(FormerMembers, Emails, Pics, FormerPage, Position);
  PrintStream out1 = new PrintStream(new File("template.txt"));
  PrintStream out2 = new PrintStream(new File("pics.txt"));
  PrintStream out3 = new PrintStream(new File("names.txt"));
  PrintStream FormerMembers = new PrintStream(new File("Former_Members.txt"));
 
  Scanner input = new Scanner(new File("original_code.txt"));
  Scanner template = new Scanner(new File("template.txt"));
  Scanner pics = new Scanner(new File("pics.txt"));
  Scanner names = new Scanner(new File("names.txt")); 
 
  clearer(input, out1, out2, out3);
  compiler(template, pics, names);
   }
   }
    
    
public static void clearer(Scanner input, PrintStream out1, PrintStream out2,  
  // Extracts information from the webpage necessary to transfer member profiles from one
                                                              PrintStream out3) throws FileNotFoundException {    
  // section to another
       while (input.hasNextLine()) {
public static void assignNames(Scanner input, ArrayList<String> Members,
String line = input.nextLine();
                            Map<String,String> Pics, Map<String,String> Emails,
if (line.startsWith("|[[Image:")) {
                            Map<String, String> Position) {
out1.println("||");
 
              if (keep(line))  {
       String Line = input.nextLine();
      out2.println(line);
  int i = Members.size();
              }
      Queue<String> store = new LinkedList<String>();
            } else if (line.startsWith("|width=\"175\"|'''")) {
  while (input.hasNextLine()) {
out1.println("|width=\"175\"|");
        if (Line.startsWith("|[")) {
              if (keep(line)) {
            store.add(Line.substring(1));  
                  out3.println(line);
  } else if (Line.startsWith("|width=\"175\"|\'\'\'")) {
              }
  Members.add("\'\'\'" + Line.split("\'\'\'")[1] + "\'\'\'");
} else {
  Emails.put(Members.get(i), Line.split("<br>")[1]);
out1.println(line);
            Pics.put(Members.get(i), store.remove());
}
            Line = Line + " ";
}
            Position.put(Members.get(i), Line.split("<br>")[2]);
  }
  i++;
 
  public static boolean keep(String line) throws FileNotFoundException {
      Scanner toRemove = new Scanner(new File("removeables.txt"));    
      line = line.replace(" ", "");
      line = line.replace("_", "");
      int same = 0;
      while (toRemove.hasNextLine()) {
        String reference = toRemove.nextLine();
        reference = reference.replace(" ", "");
        reference = reference.replace("_", "");  
        if (line.contains(reference)) {
            same++;
         }
         }
  Line = input.nextLine();
       }
       }
        
       Members.add(" ");
       return same == 0;
  Members.add(" ");
  } 
       Emails.put(" "," ");
        
      Pics.put(" "," ");
     
       Position.put(" ", " ");
  }
    
    
public static void compiler(Scanner template, Scanner pics, Scanner names) {
  // Prints a list of names, pictures, and associated info into the correct format with
     
  // which the website can be updated
      while (template.hasNextLine()) {
public static void PrintPage(ArrayList List, Map<String,String> Emails, Map<String,
         String line = template.nextLine();
                        String> Pics, PrintStream Page, Map<String,String> Position) {
        if (line.startsWith("||") && pics.hasNextLine()) {
for (int i = 0; i < List.size() / 3; i++) {
            System.out.println(pics.nextLine());
         Page.println("|-align=\"center\"");
         } else if (line.startsWith("|width=\"175\"|") && names.hasNextLine()) {
Page.println("|");
            System.out.println(names.nextLine());
Page.println("|" + Pics.get(List.get(3 * i)));
        } else {
Page.println("|");
            System.out.println(line);
Page.println("|" + Pics.get(List.get(3 * i + 1)));
        }
Page.println("|");
      }
Page.println("|" + Pics.get(List.get(3 * i + 2)));
  }
         Page.println();
Page.println( "|-align=\"center\" valign=\"top\"");
Page.println("|width=\"25\"|");
Page.println("|width=\"175\"|" + List.get(3 * i) + "<br> " + Emails.get(List.get(3 * i)) + "<br>" + Position.get(List.get(3 * i)));
Page.println("|width=\"70\"|");
Page.println("|width=\"175\"|" + List.get(3 * i + 1) + "<br> " + Emails.get(List.get(3 * i + 1)) + "<br>" + Position.get(List.get(3 * i + 1)));
Page.println("|width=\"70\"|");
Page.println("|width=\"175\"|" + List.get(3 * i + 2) + "<br> " + Emails.get(List.get(3 * i + 2)) + "<br>" + Position.get(List.get(3 * i + 2))); 
Page.println("|width=\"25\"|");
Page.println();
 
}
}
}
}
-->

Latest revision as of 15:29, 12 January 2017

Edit page to access code