diff --git a/lib/v2/parliament/maintainer.js b/lib/v2/parliament/maintainer.js new file mode 100644 index 000000000..8786342eb --- /dev/null +++ b/lib/v2/parliament/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/section77/:type?': ['itpcc'], +}; diff --git a/lib/v2/parliament/radar.js b/lib/v2/parliament/radar.js new file mode 100644 index 000000000..3877df979 --- /dev/null +++ b/lib/v2/parliament/radar.js @@ -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; + }, + }, + ], + }, +}; diff --git a/lib/v2/parliament/router.js b/lib/v2/parliament/router.js new file mode 100644 index 000000000..73230662a --- /dev/null +++ b/lib/v2/parliament/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/section77/:type?', require('./section77')); +}; diff --git a/lib/v2/parliament/section77.js b/lib/v2/parliament/section77.js new file mode 100644 index 000000000..6ceeaf22d --- /dev/null +++ b/lib/v2/parliament/section77.js @@ -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; +}; diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx index 439595e4b..da920cce8 100644 --- a/website/docs/routes/government.mdx +++ b/website/docs/routes/government.mdx @@ -84,6 +84,22 @@ +## Thailand Parliament {#thailand-parliament} + +### Thailand Parliament Draft of Law's public hearing system {#thailand-parliament-thailand-parliament-draft-of-law-s-public-hearing-system} + + + | 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 (ประธานสภาผู้แทนราษฎรวินิจฉัยว่า ไม่เป็นร่างการเงิน). + + ## The United States Trade Representative {#the-united-states-trade-representative} ### Press Releases {#the-united-states-trade-representative-press-releases}