Skip to content

Commit

Permalink
feat: Add Thai Department Of Lands e-LandsAnnouncement website (#14245)
Browse files Browse the repository at this point in the history
* feat: Add Thai DOL website

* feat: Add timezone, Radar for Thai DOL e-LandsAnnoucements

* Update lib/v2/dol/maintainer.js

* Update website/docs/routes/government.mdx

* Update lib/v2/dol/radar.js

---------

Co-authored-by: rrachasak <dev@rachasak.org>
  • Loading branch information
itpcc and rachasakr authored Jan 18, 2024
1 parent 5c91e50 commit ba3c292
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
92 changes: 92 additions & 0 deletions lib/v2/dol/announce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const baseUrl = 'https://announce.dol.go.th';
const { owner, province, office } = ctx.params;
const queryParams = {
searchprovince: '',
searchoffice: '',
searchtype: '',
searchconcerned: owner ?? '',
};

const result = {
title: `ประกาศสำนักงานที่ดิน${province ? 'จังหวัด' + province + ' ' : ''}${office ? 'สำนักงานที่ดิน' + office : ''}${owner ? 'ชื่อผู้ถือกรรมสิทธิ/ผู้ขอ ' + owner : ''}`,
link: `${baseUrl}/index.php`,
item: [],
};

// If office/province provided, fetch index page to lookup province/office code
if (province || office) {
const { data: response } = await got(`${baseUrl}/index.php`);
const $ = cheerio.load(response);

if (province) {
const slcProvince = $(`select#searchprovince option:contains('${province}')`);

if (!slcProvince.length) {
ctx.state.data = result;
return;
}

queryParams.searchprovince = slcProvince.attr('value');
}

if (office) {
const slcOffice = $(`select#searchoffice option:contains('${office}')`);

if (!slcOffice.length) {
ctx.state.data = result;
return;
}

queryParams.searchoffice = slcOffice.attr('value');
}
}

result.link = `${baseUrl}/index.php?${new URLSearchParams(queryParams).toString()}`;

const { data: response } = await got(result.link, {
https: {
rejectUnauthorized: false,
},
});
const $ = cheerio.load(response);

result.item = $('div#div table tbody tr:not([class])')
.toArray()
.map((item) => {
item = $(item);
/** @type cheerio.Cheerio<th>[] */
const [, topic, requester, reqType, anceBegDate, anceEndDate, officeName, anceFile] = item
.find('th')
.toArray()
.map((item) => $(item));
const dateList = anceBegDate.text().split('-');
return {
title: `${topic.text()} (ผู้ถือกรรมสิทธิ/ผู้ขอ ${requester.text()})`,
// Template text from Form ท.ด.๒๕
description: `ประกาศ${officeName.text()} เรื่อง${topic.text()}
ด้วย ${requester.text()} ได้ยื่นเรื่องราว ${reqType.text()}
จึงขอประกาศให้ทราบทั่วกัน ถ้าผู้ใดจะคัดค้านประการใด ให้ยื่นคำคัดค้านต่อพนักงานเจ้าหน้าที่ ภายใน ${anceEndDate.text()}
ประกาศ ณ วันที่ ${anceBegDate.text()}
`,
link: `${baseUrl}/${anceFile.find('a').attr('href')}`,
pubDate: timezone(
new Date(
// The date is in Buddish year
parseInt(dateList[2]) - 543,
parseInt(dateList[1]) - 1,
parseInt(dateList[0])
),
+7
),
author: officeName.text(),
category: [reqType.text()],
};
});

ctx.state.data = result;
};
3 changes: 3 additions & 0 deletions lib/v2/dol/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/announce/:owner?/:province?/:office?': ['itpcc'],
};
33 changes: 33 additions & 0 deletions lib/v2/dol/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
'dol.go.th': {
_name: 'กรมที่ดิน (Thaland Department of Lands)',
announce: [
{
title: 'ประกาศกรมที่ดิน',
docs: 'https://docs.rsshub.app/routes/government#thailand-department-of-lands-e-landsannouncement',
source: '/index.php',
target: (params, url, document) => {
const queryParams = new URL(url).searchParams;
let rssPath = '/dol/announce';
if (!queryParams.has('searchconcerned')) {
return rssPath;
}

rssPath += `/${encodeURIComponent(queryParams.get('searchconcerned'))}`;

const province = document && document.querySelector('#searchprovince').value !== '' ? document.querySelector(`#searchprovince option[value="${document.querySelector('#searchprovince').value}"]`).text() : '';

const office = document && document.querySelector('#searchoffice').value !== '' ? document.querySelector(`#searchoffice option[value="${document.querySelector('#searchoffice').value}"]`).text() : '';

if (!province || !office) {
return rssPath;
}

rssPath += `/${encodeURIComponent(province)}/${encodeURIComponent(office)}`;

return rssPath;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/dol/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/announce/:owner?/:province?/:office?', require('./announce'));
};
6 changes: 6 additions & 0 deletions website/docs/routes/government.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@

<Route author="nczitzk" example="/us/supremecourt/argument_audio" path="/us/supremecourt/argument_audio/:year?" paramsDesc={['Year, current year by default']} notOperational="1" />

## Thailand Department of Lands {#thailand-department-of-lands}

### e-LandsAnnouncement {#thailand-department-of-lands-e-landsannouncement}

<Route author="itpcc" example="/dol/announce" path="/dol/announce/:owner?/:province?/:office?" paramsDesc={['Requester/former land owner', 'Province which the land is belongs to', 'DOL office name which the land is belongs to (สำนักงานที่ดิน(กรุงเทพมหานคร|จังหวัด*) [สาขา*])']} />

## The United States Trade Representative {#the-united-states-trade-representative}

### Press Releases {#the-united-states-trade-representative-press-releases}
Expand Down

0 comments on commit ba3c292

Please sign in to comment.