feat: Add Thai Parliament's Public hearing (according to Thai constitution section 77) (#14260)
* feat: Add Thai DOL website * feat: Add timezone, Radar for Thai DOL e-LandsAnnoucements * Update lib/v2/dol/maintainer.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update website/docs/routes/government.mdx Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/dol/radar.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Feat: Init Thai Parliament section77 * Switch got to Puppetteer, add radar, doc * Fix DeepScan: Expression 'parseInt(maxPageElem.attr('id'))' always passes null check. Consider using 'isNaN()' instead if invalid number checking was intended. * Change NaN handling to satisfy DeepScan * Fix ESLint issues * Fix: Reject PuppeTeer, embrace got with ToughJar. Thk @TonyRL * Correct header style * perf: Remove fetching pagination. Only first page. * chore: Move original text out of header * Update lib/v2/parliament/radar.js --------- Co-authored-by: rrachasak <dev@rachasak.org>
This commit is contained in:
co-authored by
Tony
rrachasak
parent
7caac20234
commit
e390030ca1
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/section77/:type?': ['itpcc'],
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
module.exports = {
|
||||
'parliament.go.th': {
|
||||
_name: 'รัฐสภา',
|
||||
'.': [
|
||||
{
|
||||
title: 'รับฟังความคิดเห็นต่อร่าง พ.ร.บ. ตามมาตรา 77 ของรัฐธรรมนูญ',
|
||||
docs: 'https://docs.rsshub.app/routes/government#thailand-parliament',
|
||||
source: ['/section77/index.php', '/section77/survey_list77.php', '/section77/survey_more_news.php'],
|
||||
target: (_params, url) => {
|
||||
const queryParams = new URL(url).searchParams;
|
||||
let rssPath = '/parliament/section77';
|
||||
if (!queryParams.has('type')) {
|
||||
return rssPath;
|
||||
}
|
||||
|
||||
rssPath += `/${encodeURIComponent(queryParams.get('type'))}`;
|
||||
return rssPath;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/section77/:type?', require('./section77'));
|
||||
};
|
||||
@@ -0,0 +1,161 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { CookieJar } = require('tough-cookie');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.parliament.go.th/section77';
|
||||
const { type = '' } = ctx.params;
|
||||
const cookieJar = new CookieJar();
|
||||
|
||||
let title = 'ร่างพระราชบัญญัติที่เปิดรับฟังความคิดเห็นตามมาตรา 77 ของรัฐธรรมนูญ';
|
||||
|
||||
if (type) {
|
||||
const [presenter, isMonetaryAct = ''] = type.split('-');
|
||||
|
||||
title +=
|
||||
{
|
||||
presentbymp: 'ที่เสนอโดยสมาชิกสภาผู้แทนราษฏร',
|
||||
presentbyperson: 'ที่เสนอโดยประชาชน',
|
||||
openwsu: 'ที่กำลังเปิดรับฟังความคิดเห็น',
|
||||
closewsu: 'ที่ปิดรับฟังความคิดเห็น',
|
||||
reportwsu: ' รายงานผลการรับฟังความคิดเห็น',
|
||||
substatus1: 'ซึ่งรอคำรับรองจากนายกรัฐมนตรี',
|
||||
substatus2: 'ที่บรรจุเข้าระเบียบวาระ',
|
||||
substatus3: 'ที่พิจารณาแล้ว',
|
||||
closewsubypm: 'ที่นายกฯ ไม่รับรอง',
|
||||
}[presenter] ?? '';
|
||||
|
||||
title +=
|
||||
{
|
||||
m: ' (ประธานสภาผู้แทนราษฎรวินิจฉัยว่า เป็นร่างการเงิน)',
|
||||
nm: ' (ประธานสภาผู้แทนราษฎรวินิจฉัยว่า ไม่เป็นร่างการเงิน)',
|
||||
}[isMonetaryAct] ?? '';
|
||||
}
|
||||
|
||||
const result = {
|
||||
title,
|
||||
link: `${baseUrl}/survey_more_news.php${type ? '?type=' + type : ''}`,
|
||||
language: 'th-th',
|
||||
item: [],
|
||||
};
|
||||
|
||||
const queryParams = {
|
||||
page: 1,
|
||||
type,
|
||||
};
|
||||
if (type) {
|
||||
queryParams.type = type;
|
||||
}
|
||||
|
||||
const url = `${baseUrl}/ajax/pagination.php?${new URLSearchParams(queryParams).toString()}`;
|
||||
const { data: response } = await got({
|
||||
url,
|
||||
cookieJar,
|
||||
});
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
if ($.text() === 'ยังไม่มีข้อมูล') {
|
||||
return result;
|
||||
}
|
||||
|
||||
const actList = $('div.item-77')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
link: `${baseUrl}/${item.find('a').attr('href')}`,
|
||||
category: item
|
||||
.find('label')
|
||||
.toArray()
|
||||
.map((l) => $(l).text()),
|
||||
};
|
||||
});
|
||||
|
||||
if (!actList.length) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const actListFull = await Promise.all(
|
||||
actList.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got({
|
||||
url: item.link,
|
||||
cookieJar,
|
||||
});
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
// Select the first element with the class name 'comment-body'
|
||||
item.title = $('.title h5').first().text();
|
||||
item.author = $('.present-by')
|
||||
.first()
|
||||
.text()
|
||||
.replaceAll(/^\s*เสนอโดย\s*/g, '');
|
||||
item.description = $('.des').first().html();
|
||||
|
||||
// Act draft status
|
||||
const [, presenter, monetaryType] = $('.type77 h5').text().split(' ');
|
||||
item.category = [
|
||||
...item.category,
|
||||
$('.container-fluid .bg-status .col-md-8.p-0 h5 span,a')
|
||||
.toArray()
|
||||
.map((statusElem) => $(statusElem).text()),
|
||||
presenter,
|
||||
monetaryType,
|
||||
];
|
||||
|
||||
const voteText = $('.row.bg-status .col-md-4.text-right').text().trim();
|
||||
const voteRegex = /^ผู้แสดงความคิดเห็น\s*(\d+)\s*คน\s*(\d+(?:\.\d+)?)%\s*(\d+(?:\.\d+)?)%/g.exec(voteText);
|
||||
|
||||
if (voteRegex) {
|
||||
const voteTotal = Number.parseInt(voteRegex[0]);
|
||||
const upvotePercent = Number.parseFloat(voteRegex[1]);
|
||||
const downvotePercent = Number.parseFloat(voteRegex[2]);
|
||||
|
||||
item.upvotes = Number.parseInt((upvotePercent / 100) * voteTotal);
|
||||
item.downvotes = Number.parseInt((downvotePercent / 100) * voteTotal);
|
||||
}
|
||||
|
||||
const dateText = $('.banner-detail .banner-detail-caption .blockquote p:last-child').text();
|
||||
const dateRegex = /^รับฟังตั้งแต่วันที่\s(\d{1,2})\s*([\u0E00-\u0E7F]+)\s*(\d{4})/g.exec(dateText);
|
||||
|
||||
if (dateRegex) {
|
||||
item.pubDate = timezone(
|
||||
new Date(
|
||||
Number.parseInt(dateRegex[3]) - 543,
|
||||
{
|
||||
มกราคม: 0,
|
||||
กุมภาพันธ์: 1,
|
||||
มีนาคม: 2,
|
||||
เมษายน: 3,
|
||||
พฤษภาคม: 4,
|
||||
มิถุนายน: 5,
|
||||
กรกฎาคม: 6,
|
||||
สิงหาคม: 7,
|
||||
กันยายน: 8,
|
||||
ตุลาคม: 9,
|
||||
พฤศจิกายน: 10,
|
||||
ธันวาคม: 11,
|
||||
}[dateRegex[2].trim()],
|
||||
Number.parseInt(dateRegex[1])
|
||||
),
|
||||
+7
|
||||
);
|
||||
}
|
||||
|
||||
// Every property of a list item defined above is reused here
|
||||
// and we add a new property 'description'
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
if (!actListFull.length) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result.item = actListFull;
|
||||
|
||||
ctx.state.data = result;
|
||||
};
|
||||
@@ -84,6 +84,22 @@
|
||||
|
||||
<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 (สำนักงานที่ดิน(กรุงเทพมหานคร|จังหวัด*) [สาขา*])']} />
|
||||
|
||||
## Thailand Parliament {#thailand-parliament}
|
||||
|
||||
### Thailand Parliament Draft of Law's public hearing system {#thailand-parliament-thailand-parliament-draft-of-law-s-public-hearing-system}
|
||||
|
||||
<Route author="itpcc" example="/parliament/section77" path="/parliament/section77/:type?" paramsDesc={['Type of hearing status, see below']} radar="1">
|
||||
| Presented by MP \* | Presented by People \* | Hearing Ongoing | Hearing ended | Hearing result reported | Waiting for PM approval | Assigned into the session | Processed | PM Rejected |
|
||||
| ------------------------ | ---------------------- | ------------------- | --------------- | ------------------------ | ----------------------- | ------------------------- | ---------- | ------------- |
|
||||
| presentbymp | presentbyperson | openwsu | closewsu | reportwsu | substatus1 | substatus2 | substatus3 | closewsubypm |
|
||||
| เสนอโดยสมาชิกสภาผู้แทนราษฏร | เสนอโดยประชาชน | กำลังเปิดรับฟังความคิดเห็น | ปิดรับฟังความคิดเห็น | รายงานผลการรับฟังความคิดเห็น | รอคำรับรองจากนายกรัฐมนตรี | บรรจุเข้าระเบียบวาระ | พิจารณาแล้ว | นายกฯ ไม่รับรอง |
|
||||
|
||||
*Note:* For `presentbymp` and `presentbyperson`, it can also add:
|
||||
|
||||
- `-m` for the draft which Speaker of Parliament considered as a monetary draft (ประธานสภาผู้แทนราษฎรวินิจฉัยว่า เป็นร่างการเงิน), or
|
||||
- `-nm` for non-monetary one (ประธานสภาผู้แทนราษฎรวินิจฉัยว่า ไม่เป็นร่างการเงิน).
|
||||
</Route>
|
||||
|
||||
## The United States Trade Representative {#the-united-states-trade-representative}
|
||||
|
||||
### Press Releases {#the-united-states-trade-representative-press-releases}
|
||||
|
||||
Reference in New Issue
Block a user