Advertisement
Alexandre_lsv

///

Jul 17th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.69 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.URL;
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. public class Main {
  7.     public Arrays arr;
  8.     public List<String> lst;
  9.     public int max;
  10.     public int[][] usersPriority;
  11.     public String progr[];
  12.     public String sites[];
  13.     public static void main(String[] args) throws IOException{
  14.         Main m=new Main();
  15.         m.SearchProgrAndSites();
  16.     }
  17.     public void SearchProgrAndSites() throws IOException{
  18.         URL url = new URL("http://cabinet.spbu.ru/Lists/1k_EntryLists/");
  19.         InputStream in = url.openStream();
  20.         BufferedReader br = new BufferedReader(new InputStreamReader(in));
  21.         max=0;
  22.         progr = new String[1000];
  23.         sites = new String[1000];
  24.         usersPriority = new int [50000][20];
  25.         int uid=0;
  26.         int count=0;
  27.         while (true) {
  28.             String line = br.readLine();
  29.             if (line != null) {
  30.                if (line.contains("Оригиналы"))
  31.                    break;
  32.             } else break;
  33.         }
  34.         while (true) {
  35.             String line = br.readLine();
  36.             if (line != null) {
  37.                 if (line.contains("<td>"))
  38.                     count++;
  39.                 if (line.contains("</tr>"))
  40.                     count = 0;
  41.                 if (count == 2)
  42.                     uid = Integer.valueOf(line.substring(6, line.length() - 5));
  43.                 if (line.contains("GetPerson")) {
  44.                     GetSites(uid, "http://cabinet.spbu.ru/Lists/1k_EntryLists/data/" + line.substring(line.indexOf("GetPerson") + 18, line.lastIndexOf("GetPerson") + 54) + ".txt" + "\n");
  45.                 }
  46.                 if (count == 5) {
  47.                     usersPriority[uid - 1540000][0] = (line.contains("Да") ? 1 : 0);
  48.                 }
  49.             } else break;
  50.         }
  51.         max-=1;
  52.         GetProgr();
  53.         for (int i=0; i<max; i++)
  54.             CreateTables(i);
  55.     }
  56.     public void GetSites(int uid, String str) throws IOException {
  57.         String site;
  58.         URL url = new URL(str);
  59.         InputStream in = url.openStream();
  60.         BufferedReader br = new BufferedReader(new InputStreamReader(in));
  61.         String line = br.readLine();
  62.         int priority=1;
  63.         while (true) {
  64.             if (line == null)
  65.                 break;
  66.             if (line.contains("программа")) {
  67.                 site = "http://cabinet.spbu.ru/Lists/1k_EntryLists/"+line.substring(line.indexOf("href=\"") + 6, line.indexOf("\">Просмотр")-42) + ".html\n";
  68.                 Conv();
  69.                 if (!(lst.contains(site))) {
  70.                     sites[max]=site;
  71.                     max++;
  72.                 }
  73.                 usersPriority[uid-1540000][priority]=SearchProgr(site);
  74.                 priority++;
  75.             }
  76.             line = br.readLine();
  77.         }
  78.         in.close();
  79.     }
  80.     public void GetProgr() throws IOException {
  81.         String name = "";
  82.         for (int i=0; i<max; i++) {
  83.             URL url = new URL(sites[i]);
  84.             InputStream in = url.openStream();
  85.             BufferedReader br = new BufferedReader(new InputStreamReader(in));
  86.             String line;
  87.             while (true) {
  88.                 line = br.readLine();
  89.                 if (line.contains("Образовательная программа"))
  90.                     break;
  91.                 if (line == null)
  92.                     break;
  93.             }
  94.             name = line.substring(line.lastIndexOf("программа") + 28);
  95.             name = name.substring(0, name.length() - 7);
  96.             while (true) {
  97.                 line = br.readLine();
  98.                 if (line.contains("Форма обучения"))
  99.                     break;
  100.                 if (line == null)
  101.                     break;
  102.             }
  103.             if (line.contains("очно"))
  104.                 name += "_в";
  105.             else
  106.                 name += "_д";
  107.             while (true) {
  108.                 line = br.readLine();
  109.                 if (line.contains("Основа обучения"))
  110.                     break;
  111.                 if (line == null)
  112.                     break;
  113.             }
  114.             if (line.contains("Госбюджетная"))
  115.                 name += "_б";
  116.             else
  117.                 name += "_д";
  118.             line = br.readLine();
  119.             if (line.contains("цел"))
  120.                 name += "_ц";
  121.             if (line.contains("Крым"))
  122.                 name += "_к";
  123.             if (ProgrCheck(name, i))
  124.                 name+="_1";
  125.             progr[i]=name;
  126.         }
  127.     }
  128.     void Conv(){
  129.         lst = arr.asList(sites);
  130.     }
  131.     public boolean ProgrCheck(String str, int max){
  132.         boolean b=false;
  133.         for (int i=0; i<max; i++)
  134.             if (progr[i].contains(str))
  135.                 b=true;
  136.         return b;
  137.     }
  138.     public void CreateTables(int num) throws IOException {
  139.         File myPath = new File("Programms");
  140.         myPath.mkdir();
  141.         myPath.mkdirs();
  142.         File file = new File("Programms/"+progr[num]+".txt");
  143.         try {
  144.             if(!file.exists()){
  145.                 file.createNewFile();
  146.             }
  147.         } catch(IOException e) {
  148.             throw new RuntimeException(e);
  149.         }
  150.         PrintWriter out = new PrintWriter(file.getAbsoluteFile(), "Cp1251");
  151.         out.print(sites[num]+"\n");
  152.         URL url = new URL(sites[num]);
  153.         InputStream in = url.openStream();
  154.         BufferedReader br = new BufferedReader(new InputStreamReader(in));
  155.         String line = br.readLine();
  156.         while (true) {
  157.             if (line.contains("Примечания"))
  158.                 break;
  159.             if (line == null)
  160.                 break;
  161.             line = br.readLine();
  162.         }
  163.         int count=0;
  164.         String s="";
  165.         int Uid=0;
  166.         String name="";
  167.         line = br.readLine();
  168.         while (true) {
  169.             if (line != null) {
  170.                 if (line.contains("</tr>")) {
  171.                     count = 0;
  172.                     out.print(s+"\n");
  173.                     s="";
  174.                 }
  175.                 if (line.contains("<td>"))
  176.                     count++;
  177.                 if (count == 1) {
  178.                     if (Integer.valueOf(line.substring(6,line.length()-5))>999)
  179.                         s += (line.substring(6, line.length() - 5) + " | ");
  180.                     else
  181.                         if (Integer.valueOf(line.substring(6,line.length()-5))>99)
  182.                             s += (line.substring(6, line.length() - 5) + "  | ");
  183.                         else
  184.                             if (Integer.valueOf(line.substring(6,line.length()-5))>9)
  185.                                s += (line.substring(6, line.length() - 5) + "   | ");
  186.                              else
  187.                                  s += (line.substring(6, line.length() - 5) + "    | ");
  188.                 }
  189.                 if (count == 2)
  190.                     Uid=Integer.valueOf(line.substring(6,line.length()-5));
  191.                 if (count == 3)
  192.                     name=(line.substring(57,line.length()-5));
  193.                 if (count == 5)
  194.                     if (line.contains("преим"))
  195.                         s+=(line.substring(6,line.length()-5)+" | ");
  196.                     else {
  197.                         if (line.contains("б/э") || line.contains("в/к"))
  198.                             s += (line.substring(6, line.length() - 5) + "       | ");
  199.                         else
  200.                             s += (line.substring(6, line.length() - 5) + "      | ");
  201.                     }
  202.                 if ((count == 6)) {
  203.                     if (line.length() > 13)
  204.                         s += (line.substring(6, line.length() - 5) + " | ");
  205.                     else
  206.                         s += "    | ";
  207.  
  208.                     if (usersPriority[Uid - 1540000][0] == 0)
  209.                         s += "Нет | ";
  210.                     if (usersPriority[Uid - 1540000][0] == 1)
  211.                         s += "Да  | ";
  212.                     s += (SearchPrior(Uid, progr[num]) + " | ");
  213.                     s += name;
  214.                     name = "";
  215.                 }
  216.             } else
  217.                 break;
  218.             line = br.readLine();
  219.         }
  220.         out.print(s);
  221.         out.close();
  222.     }
  223.     public int SearchProgr(String pr)  {
  224.         int i;
  225.         for (i=1; i<=max; i++){
  226.             if (pr.equals(sites[i])) {
  227.                 break;
  228.             }
  229.         }
  230.         return i;
  231.     }
  232.     public int SearchPrior(int ind, String pr)  {
  233.         int i;
  234.         for (i=1; i<10; i++)
  235.             if (pr.equals(progr[usersPriority[ind-1540000][i]]))
  236.                 break;
  237.         return (i==10?0:i);
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement