Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bruno.checkpph;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.TimeUnit;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- public class CheckPPH
- {
- private static final ScheduledExecutorService mScheduler = Executors.newScheduledThreadPool(1);
- public static void main(String[] args)
- {
- mScheduler.scheduleAtFixedRate(mRunnable, 5, 90, TimeUnit.SECONDS);
- }
- private static Runnable mRunnable = new Runnable()
- {
- public void run()
- {
- checkEtc();
- }
- };
- private static void checkEtc()
- {
- File file = new File("/home/brx/jobs.txt");
- Scanner numScan = null;
- try{
- numScan = new Scanner(file);
- }
- catch(FileNotFoundException e){
- e.printStackTrace();
- }
- String line;
- ArrayList<String> links = new ArrayList<String>();
- while(numScan.hasNext()){
- line = numScan.nextLine();
- links.add(line);
- }
- Document doc = null;
- try{
- doc = Jsoup
- .connect(
- "http://www.peopleperhour.com/freelance-android-jobs?remote=GB&onsite=GB&filter=all&sort=latest#scroll=0")
- .get();
- }
- catch(IOException e){
- e.printStackTrace();
- }
- // <a class="job" title="Android App" href="http://www.peopleperhour.com/job/android-app-665907">Android App</a>
- StringBuilder sb = new StringBuilder();
- Elements newsHeadlines = doc.select("a.job");
- for(Element element : newsHeadlines){
- String title = element.attr("title");
- String href = element.attr("href");
- if(!title.equalsIgnoreCase("Post Job") && !href.contains("?ref=topnav_loggedout")){
- if(!links.contains(href)){
- sb.append(href + "\n");
- System.out.print("adding to string buider:" + title);
- notifySend(href);
- }
- else{
- System.out.print("NOT adding to string buider:" + title);
- }
- }
- }
- writeToFile(sb);
- }
- private static void notifySend(String title)
- {
- String command = "notify-send " + title + " -u critical -i '/home/brx/Pictures/pph.png' -t 1000";
- Process p;
- try{
- p = Runtime.getRuntime().exec(command);
- p.waitFor();
- p.destroy();
- }
- catch(Exception e){}
- }
- private static void writeToFile(StringBuilder sb)
- {
- try{
- File file = new File("/home/brx/yo.txt");
- if(!file.exists()){
- file.createNewFile();
- }
- FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(sb.toString());
- bw.close();
- System.out.println("Done writing to /home/brx/yo.txt"); // For testing
- }
- catch(IOException e){
- System.out.println("Error: " + e);
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement