extract eventernote event time
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const dateStringRegex = /(\d{4})-(\d{2})-(\d{2})/;
|
||||
const dateStringRegex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
|
||||
const timeStringRegexes = [
|
||||
/開場 (?<openHr>\d{2}):(?<openMin>\d{2}) 開演 (?<startHr>\d{2}):(?<startMin>\d{2}) 終演 (?<closeHr>\d{2}):(?<closeMin>\d{2})/,
|
||||
/開場 - 開演 (?<openHr>\d{2}):(?<openMin>\d{2}) 終演 (?<closeHr>\d{2}):(?<closeMin>\d{2})/,
|
||||
/開場 (?<openHr>\d{2}):(?<openMin>\d{2}) 開演 - 終演 (?<closeHr>\d{2}):(?<closeMin>\d{2})/,
|
||||
];
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { name, id } = ctx.params;
|
||||
@@ -32,26 +37,53 @@ module.exports = async (ctx) => {
|
||||
for (let i = 0; i < list.length; ++i) {
|
||||
const event = list[i];
|
||||
|
||||
// extract event title
|
||||
const title = $('div.event > h4 > a', event).text();
|
||||
// extract event name
|
||||
const eventName = $('div.event > h4 > a', event).text();
|
||||
|
||||
// extract event location
|
||||
const location = $('div.event > div.place > a', event).text();
|
||||
const eventLocation = $('div.event > div.place > a', event).text();
|
||||
|
||||
// extract event date
|
||||
const dateMatches = $('div.date > p', event).text().match(dateStringRegex);
|
||||
const year = parseInt(dateMatches[1]);
|
||||
const month = parseInt(dateMatches[2]);
|
||||
const day = parseInt(dateMatches[3]);
|
||||
const time = new Date(year, month, day);
|
||||
const eventYear = dateMatches.groups.year;
|
||||
const eventMonth = dateMatches.groups.month;
|
||||
const eventDay = dateMatches.groups.day;
|
||||
|
||||
// extract event time
|
||||
const timeString = $('div.event > div.place > span.s', event).text();
|
||||
let eventTimeObj = {
|
||||
openHr: null,
|
||||
openMin: null,
|
||||
startHr: null,
|
||||
startMin: null,
|
||||
closeHr: null,
|
||||
closeMin: null,
|
||||
};
|
||||
for (const r of timeStringRegexes) {
|
||||
const m = timeString.match(r);
|
||||
if (m === null) {
|
||||
continue;
|
||||
}
|
||||
eventTimeObj = {
|
||||
...eventTimeObj,
|
||||
...m.groups,
|
||||
};
|
||||
}
|
||||
|
||||
// extract event link
|
||||
const link = $('div.event > h4 > a', event).attr('href');
|
||||
|
||||
// compute event description
|
||||
const eventDescription = `イベント ${eventName}
|
||||
開催場所 ${eventLocation}
|
||||
開場 ${eventYear}-${eventMonth}-${eventDay} ${eventTimeObj.openHr}:${eventTimeObj.openMin}
|
||||
開演 ${eventYear}-${eventMonth}-${eventDay} ${eventTimeObj.startHr}:${eventTimeObj.startMin}
|
||||
終演 ${eventYear}-${eventMonth}-${eventDay} ${eventTimeObj.closeHr}:${eventTimeObj.closeHr}
|
||||
`;
|
||||
|
||||
events.push({
|
||||
title,
|
||||
description: location,
|
||||
pubDate: time.toLocaleString('ja'),
|
||||
title: eventName,
|
||||
description: eventDescription,
|
||||
link,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user