-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Thai Department Of Lands e-LandsAnnouncement website (#14245)
* 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
Showing
5 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/announce/:owner?/:province?/:office?': ['itpcc'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters