Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ramat gan tree fix #754

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions server/api/lib/trees/ramat_gan_tree_permit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ const {
REASON_SHORT, PLACE, STREET,
TREES_PER_PERMIT, PERSON_REQUEST_NAME, TREE_PERMIT_URL
} = require('../../model/tree_permit_constants');
const { formatDate } = require('./utils');
const { formatDate, figureLastObjectionDate } = require('./utils');
const Log = require('../log');

const TREES_RAMAT_GAN_URL = `https://www.ramat-gan.muni.il/tashtiot/view/forest_commissioner/license/${new Date().getFullYear()}/`;
const RGTreePermit = {
urls:[TREES_RAMAT_GAN_URL]
};

const HOUR_PERMIT = '09:00';
const DATE_FORMAT_PERMIT = 'YYYY-MM-DDTHH:mm';

async function parseTreesHtml(url) {
const treesHtml = await proxy.get(url);

Expand All @@ -40,7 +43,7 @@ async function parseTreesHtml(url) {
const treePermit = {};
dom(elem).find('TD,TH').each((idx, elem) => {
const value = idx === 6 ? dom(elem).find('a').attr('href') : dom(elem).text().trim();
if (value.length > 0) {
if (value && value.length > 0) {
const key = keys[idx];
treePermit[key] = value;
}
Expand All @@ -61,14 +64,21 @@ function processRawPermits(rawPermits) {
const parts = raw['שם הרחוב'].split('\n'); // captures (כריתה), (העתקה)
const street = parts[0];
const action = parts.length > 1 ? parts[1] : 'כריתה';
const last_date_to_objection = parsePermitDates(raw['ניתן להגיש ערעור עד'])[0];

const dates = parsePermitDates(raw['מתאריך – עד תאריך']);

var last_date_to_objection = parsePermitDates(raw['ניתן להגיש ערעור עד'])[0];
if (!last_date_to_objection) {
Log.error(`No / Bad dates format, ignore this license: Ramat Gan, ${raw['שם הרחוב']} , ${raw['ניתן להגיש ערעור עד']}`);
return null;
if (dates[0]) {
last_date_to_objection = figureLastObjectionDate(dates[0], HOUR_PERMIT, DATE_FORMAT_PERMIT);
} else {
Log.error(`No / Bad dates format, ignore this license: Ramat Gan, ${raw['שם הרחוב']} , ${raw['ניתן להגיש ערעור עד']}`);
return null;
}
}
const treesPerPermit = raw['סוג העצים'] !== undefined ? parseTreesPerPermit(raw['סוג העצים']) : {};
const totalTrees = raw['סוג העצים'] !== undefined ? sum(Object.values(treesPerPermit)) : 0;
const dates = parsePermitDates(raw['מתאריך – עד תאריך']);


const permitNumber = `meirim-rg-${street}-${dates[0]}`;

Expand All @@ -86,7 +96,7 @@ function processRawPermits(rawPermits) {
[TOTAL_TREES]: totalTrees,
[START_DATE]: dates[0],
[END_DATE]: dates[1],
[TREE_PERMIT_URL]: 'https://www.ramat-gan.muni.il/' + raw['הבקשה'],
[TREE_PERMIT_URL]: raw['הבקשה'] ? 'https://www.ramat-gan.muni.il/' + raw['הבקשה'] : '',
};
const permit = new TreePermit(attributes);
return permit;
Expand Down Expand Up @@ -151,7 +161,7 @@ function parseGushHelka(gushHelkaStr) {

function parsePermitDates(treeDatesStr) {
const dates = treeDatesStr ? treeDatesStr.split('-') : [];
return dates.map(date => formatDate(date, '09:00', 'DD.MM.YY'));
return dates.map(date => formatDate(date, HOUR_PERMIT, 'DD.MM.YY'));
}

function sum(treeArray) {
Expand Down
Loading