Skip to content

Commit 491e59f

Browse files
committed
Issues after jobs.ua redesign fixed
1 parent da8f0e0 commit 491e59f

File tree

7 files changed

+62
-31
lines changed

7 files changed

+62
-31
lines changed

src/main/java/com/olegshan/parser/impl/ParserImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void parse(JobSite jobSite) {
4444
Elements titleBlock = jobParser.getTitleBlock(job);
4545
String url = jobParser.getUrl(titleBlock);
4646
String title = jobParser.getTitle(titleBlock);
47-
String description = jobParser.getDescription(job);
47+
String description = jobParser.getDescription(job, url);
4848
String company = jobParser.getCompany(job, url);
4949
LocalDateTime date = jobParser.getDate(job, url);
5050

src/main/java/com/olegshan/parser/siteparsers/HeadHunterUaJobParser.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,4 @@ protected LocalDateTime getDateByLine(String dateLine) {
2626

2727
return LocalDate.of(year, month, day).atTime(getTime());
2828
}
29-
30-
//in case we parse in January jobs of last December
31-
private int getYear(int month) {
32-
int year;
33-
if (month > LocalDate.now(ZoneId.of("Europe/Athens")).getMonthValue()) {
34-
year = LocalDate.now().getYear() - 1;
35-
} else {
36-
year = LocalDate.now(ZoneId.of("Europe/Athens")).getYear();
37-
}
38-
return year;
39-
}
4029
}

src/main/java/com/olegshan/parser/siteparsers/JobParser.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String getTitle(Elements titleBlock) {
6060
return titleBlock.text();
6161
}
6262

63-
public String getDescription(Element job) {
63+
public String getDescription(Element job, String url) throws ParserException {
6464
String[] descriptionData = jobSite.getDescriptionData();
6565
return job.getElementsByAttributeValue(descriptionData[0], descriptionData[1]).text();
6666
}
@@ -89,6 +89,17 @@ protected LocalTime getTime() {
8989
return LocalTime.now(ZoneId.of("Europe/Athens"));
9090
}
9191

92+
//in case we parse in January jobs of last December. Needed for jobs.ua and hh.ua
93+
protected int getYear(int month) {
94+
int year;
95+
if (month > LocalDate.now(ZoneId.of("Europe/Athens")).getMonthValue()) {
96+
year = LocalDate.now().getYear() - 1;
97+
} else {
98+
year = LocalDate.now(ZoneId.of("Europe/Athens")).getYear();
99+
}
100+
return year;
101+
}
102+
92103
protected void check(Object o, String data, String url) throws ParserException {
93104
String jobUrl = url == null ? "" : url;
94105
if (o == null || o.toString().length() == 0) {

src/main/java/com/olegshan/parser/siteparsers/JobsUaJobParser.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,44 @@ public JobsUaJobParser(JobSite jobSite) {
1818
super(jobSite);
1919
}
2020

21+
public Elements getJobBlocks(Document doc) throws ParserException {
22+
Elements jobBlocks = doc.getElementsByAttributeValue(jobSite.getJobBox()[0], jobSite.getJobBox()[1]);
23+
check(jobBlocks, "job blocks", null);
24+
25+
// ad block on jobs.ua has the same tags as the job blocks, so it should be removed
26+
for (int i = 0; i < jobBlocks.size(); i++) {
27+
if (jobBlocks.get(i).getElementsByAttributeValue("class", "b-city__title b-city__companies-title")
28+
.text().contains("VIP компании в Украине:")) {
29+
jobBlocks.remove(i);
30+
}
31+
}
32+
return jobBlocks;
33+
}
34+
35+
@Override
36+
public String getDescription(Element job, String url) throws ParserException {
37+
String[] descriptionData = jobSite.getDescriptionData();
38+
Document descDoc = getDoc(url);
39+
String description = descDoc.getElementsByAttributeValue(descriptionData[0], descriptionData[1]).text();
40+
return description.length() > 250 ? description.substring(0, 250) + ("...") : description;
41+
}
42+
2143
@Override
2244
protected LocalDateTime getDateByLine(String dateLine) {
23-
String[] dateParts = dateLine.substring(0, 10).split(jobSite.getSplit());
45+
dateLine = dateLine.replaceAll("\u00a0", "").trim();
46+
String[] dateParts = dateLine.trim().split(jobSite.getSplit());
2447
MonthsTools.removeZero(dateParts);
25-
return LocalDate.of(parseInt(dateParts[2]), parseInt(dateParts[1]), parseInt(dateParts[0])).atTime(getTime());
48+
49+
int day = parseInt(dateParts[0]);
50+
int month = MonthsTools.MONTHS.get(dateParts[1].toLowerCase());
51+
int year = getYear(month);
52+
53+
return LocalDate.of(year, month, day).atTime(getTime());
2654
}
2755

28-
@Override
2956
public String getCompany(Element job, String url) throws ParserException {
30-
String[] companyData = jobSite.getCompanyData();
31-
Document jobDoc = getDoc(url);
32-
Elements companyBlock = jobDoc.getElementsByAttributeValue(companyData[0], companyData[1]);
33-
34-
String company = companyBlock.get(0).getElementsByTag("a").first().text();
57+
String company = job.getElementsByAttributeValue(jobSite.getCompanyData()[0], jobSite.getCompanyData()[1])
58+
.first().text();
3559
check(company, "company", url);
3660
return company;
3761
}

src/main/java/com/olegshan/service/impl/JobServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void save(Job job) {
3535
update(job);
3636
} else {
3737
saveJob(job);
38-
twitter.tweet(job);
38+
// twitter.tweet(job);
3939
LOGGER.info("New job '{}' on {} found", job.getTitle(), job.getSource());
4040
}
4141
}
@@ -50,7 +50,7 @@ private void update(Job job) {
5050
LocalDate jobDate = job.getDate().toLocalDate();
5151
if (!jobFromDbDate.equals(jobDate)) {
5252
saveJob(job);
53-
twitter.tweet(job);
53+
// twitter.tweet(job);
5454
LOGGER.info("Job '{}', {}, was updated", job.getTitle(), job.getUrl());
5555
}
5656
}

src/main/java/com/olegshan/sites/JobsUa.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
public class JobsUa implements JobSite {
99

1010
private static final String SITE_NAME = "Jobs.ua";
11-
private static final String SITE_URL = "http://www.jobs.ua/vacancy/rabota-kiev-java/";
12-
private static final String URL_PREFIX = "http://www.jobs.ua";
13-
private static final String[] JOB_BOX = {"class", "div_vac_list"};
14-
private static final String[] TITLE_BOX = {"class", "jvac_view"};
15-
private static final String[] COMPANY_DATA = {"class", "viewcontcenter"};
16-
private static final String[] DESCRIPTION_DATA = {"style", "padding-top:12px;"};
17-
private static final String[] DATE_DATA = {"style", "padding-top:10px"};
18-
private static final String SPLIT = "\\.";
11+
private static final String SITE_URL = "https://jobs.ua/vacancy/kiev/rabota-java";
12+
private static final String URL_PREFIX = "";
13+
private static final String[] JOB_BOX = {"class", "b-vacancy__item js-item_list"};
14+
private static final String[] TITLE_BOX = {"class", "b-vacancy__top__title js-item_title"};
15+
private static final String[] COMPANY_DATA = {"class", "b-vacancy__tech__item"};
16+
private static final String[] DESCRIPTION_DATA = {"class", "b-vacancy-full__block b-text"};
17+
private static final String[] DATE_DATA = {"class", "b-vacancy__tech__item b-vacancy__tech__item-top"};
18+
private static final String SPLIT = " ";
1919

2020
public String getSiteName() {
2121
return SITE_NAME;

src/main/java/com/olegshan/social/JTwitter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
@Component
99
public class JTwitter {
1010

11+
private static final String CONSUMER_KEY = "1";
12+
private static final String CONSUMER_SECRET = "1";
13+
private static final String ACCESS_TOKEN = "1";
14+
private static final String ACCESS_TOKEN_SECRET = "1";
15+
16+
/*
1117
private static final String CONSUMER_KEY = System.getProperty("CKjP");
1218
private static final String CONSUMER_SECRET = System.getProperty("CSjP");
1319
private static final String ACCESS_TOKEN = System.getProperty("ATjP");
1420
private static final String ACCESS_TOKEN_SECRET = System.getProperty("ATSjP");
21+
*/
1522

1623
private Twitter twitter;
1724

0 commit comments

Comments
 (0)