Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.URL;
- import java.util.Arrays;
- import java.util.List;
- public class Main {
- public Arrays arr;
- public List<String> lst;
- public int max;
- public int[][] usersPriority;
- public String progr[];
- public String sites[];
- public static void main(String[] args) throws IOException{
- Main m=new Main();
- m.SearchProgrAndSites();
- }
- public void SearchProgrAndSites() throws IOException{
- URL url = new URL("http://cabinet.spbu.ru/Lists/1k_EntryLists/");
- InputStream in = url.openStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- max=0;
- progr = new String[1000];
- sites = new String[1000];
- usersPriority = new int [50000][20];
- int uid=0;
- int count=0;
- while (true) {
- String line = br.readLine();
- if (line != null) {
- if (line.contains("Оригиналы"))
- break;
- } else break;
- }
- while (true) {
- String line = br.readLine();
- if (line != null) {
- if (line.contains("<td>"))
- count++;
- if (line.contains("</tr>"))
- count = 0;
- if (count == 2)
- uid = Integer.valueOf(line.substring(6, line.length() - 5));
- if (line.contains("GetPerson")) {
- GetSites(uid, "http://cabinet.spbu.ru/Lists/1k_EntryLists/data/" + line.substring(line.indexOf("GetPerson") + 18, line.lastIndexOf("GetPerson") + 54) + ".txt" + "\n");
- }
- if (count == 5) {
- usersPriority[uid - 1540000][0] = (line.contains("Да") ? 1 : 0);
- }
- } else break;
- }
- max-=1;
- GetProgr();
- for (int i=0; i<max; i++)
- CreateTables(i);
- }
- public void GetSites(int uid, String str) throws IOException {
- String site;
- URL url = new URL(str);
- InputStream in = url.openStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String line = br.readLine();
- int priority=1;
- while (true) {
- if (line == null)
- break;
- if (line.contains("программа")) {
- site = "http://cabinet.spbu.ru/Lists/1k_EntryLists/"+line.substring(line.indexOf("href=\"") + 6, line.indexOf("\">Просмотр")-42) + ".html\n";
- Conv();
- if (!(lst.contains(site))) {
- sites[max]=site;
- max++;
- }
- usersPriority[uid-1540000][priority]=SearchProgr(site);
- priority++;
- }
- line = br.readLine();
- }
- in.close();
- }
- public void GetProgr() throws IOException {
- String name = "";
- for (int i=0; i<max; i++) {
- URL url = new URL(sites[i]);
- InputStream in = url.openStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String line;
- while (true) {
- line = br.readLine();
- if (line.contains("Образовательная программа"))
- break;
- if (line == null)
- break;
- }
- name = line.substring(line.lastIndexOf("программа") + 28);
- name = name.substring(0, name.length() - 7);
- while (true) {
- line = br.readLine();
- if (line.contains("Форма обучения"))
- break;
- if (line == null)
- break;
- }
- if (line.contains("очно"))
- name += "_в";
- else
- name += "_д";
- while (true) {
- line = br.readLine();
- if (line.contains("Основа обучения"))
- break;
- if (line == null)
- break;
- }
- if (line.contains("Госбюджетная"))
- name += "_б";
- else
- name += "_д";
- line = br.readLine();
- if (line.contains("цел"))
- name += "_ц";
- if (line.contains("Крым"))
- name += "_к";
- if (ProgrCheck(name, i))
- name+="_1";
- progr[i]=name;
- }
- }
- void Conv(){
- lst = arr.asList(sites);
- }
- public boolean ProgrCheck(String str, int max){
- boolean b=false;
- for (int i=0; i<max; i++)
- if (progr[i].contains(str))
- b=true;
- return b;
- }
- public void CreateTables(int num) throws IOException {
- File myPath = new File("Programms");
- myPath.mkdir();
- myPath.mkdirs();
- File file = new File("Programms/"+progr[num]+".txt");
- try {
- if(!file.exists()){
- file.createNewFile();
- }
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- PrintWriter out = new PrintWriter(file.getAbsoluteFile(), "Cp1251");
- out.print(sites[num]+"\n");
- URL url = new URL(sites[num]);
- InputStream in = url.openStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String line = br.readLine();
- while (true) {
- if (line.contains("Примечания"))
- break;
- if (line == null)
- break;
- line = br.readLine();
- }
- int count=0;
- String s="";
- int Uid=0;
- String name="";
- line = br.readLine();
- while (true) {
- if (line != null) {
- if (line.contains("</tr>")) {
- count = 0;
- out.print(s+"\n");
- s="";
- }
- if (line.contains("<td>"))
- count++;
- if (count == 1) {
- if (Integer.valueOf(line.substring(6,line.length()-5))>999)
- s += (line.substring(6, line.length() - 5) + " | ");
- else
- if (Integer.valueOf(line.substring(6,line.length()-5))>99)
- s += (line.substring(6, line.length() - 5) + " | ");
- else
- if (Integer.valueOf(line.substring(6,line.length()-5))>9)
- s += (line.substring(6, line.length() - 5) + " | ");
- else
- s += (line.substring(6, line.length() - 5) + " | ");
- }
- if (count == 2)
- Uid=Integer.valueOf(line.substring(6,line.length()-5));
- if (count == 3)
- name=(line.substring(57,line.length()-5));
- if (count == 5)
- if (line.contains("преим"))
- s+=(line.substring(6,line.length()-5)+" | ");
- else {
- if (line.contains("б/э") || line.contains("в/к"))
- s += (line.substring(6, line.length() - 5) + " | ");
- else
- s += (line.substring(6, line.length() - 5) + " | ");
- }
- if ((count == 6)) {
- if (line.length() > 13)
- s += (line.substring(6, line.length() - 5) + " | ");
- else
- s += " | ";
- if (usersPriority[Uid - 1540000][0] == 0)
- s += "Нет | ";
- if (usersPriority[Uid - 1540000][0] == 1)
- s += "Да | ";
- s += (SearchPrior(Uid, progr[num]) + " | ");
- s += name;
- name = "";
- }
- } else
- break;
- line = br.readLine();
- }
- out.print(s);
- out.close();
- }
- public int SearchProgr(String pr) {
- int i;
- for (i=1; i<=max; i++){
- if (pr.equals(sites[i])) {
- break;
- }
- }
- return i;
- }
- public int SearchPrior(int ind, String pr) {
- int i;
- for (i=1; i<10; i++)
- if (pr.equals(progr[usersPriority[ind-1540000][i]]))
- break;
- return (i==10?0:i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement