This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from proshunsuke/v5
櫻坂分を増やした
- Loading branch information
Showing
20 changed files
with
413 additions
and
42 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
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,62 @@ | ||
const puppeteer = require('puppeteer'); | ||
let page; | ||
|
||
async function getBrowserPage() { | ||
// Launch headless Chrome. Turn off sandbox so Chrome can run under root. | ||
const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); | ||
return browser.newPage(); | ||
} | ||
|
||
exports.getSakuraSchedule = async (req, res) => { | ||
|
||
if (!page) { | ||
page = await getBrowserPage(); | ||
} | ||
|
||
await page.goto('https://sakurazaka46.com/s/s46/media/list?dy=' + req.query['date']); | ||
|
||
const scheduleEvents = await page.evaluate("scheduleEvents"); | ||
|
||
const scheduleDateList = Array.from(new Set(scheduleEvents.map((scheduleEvent) => scheduleEvent.start.replace(/-/g, '')))); | ||
|
||
const result = []; | ||
|
||
for await (const scheduleDate of scheduleDateList) { | ||
await page.goto('https://sakurazaka46.com/s/s46/media/list?dy=' + scheduleDate); | ||
const scheduleContexts = await page.$$('.com-arclist-part li.box'); | ||
for (const scheduleContext of scheduleContexts) { | ||
const type = await (await scheduleContext.$('.type')).evaluate((el) => el.textContent) || 'その他'; | ||
const times = await (await scheduleContext.$('.times')).evaluate((el) => el.textContent); | ||
const modalCount = (await (await scheduleContext.$('.js-schedule-detail-modal')).evaluate((el) => el.href)).replace(/^.*#/g, ''); | ||
const date = await (await page.$(`.${modalCount} .date.wf-a`)).evaluate((el) => el.textContent); | ||
const title = await (await page.$(`.${modalCount} .title`)).evaluate((el) => el.textContent); | ||
const members = await Promise.all( | ||
(await page.$$(`.${modalCount} .members.fx > li`)).map(async (liElement) => await liElement.evaluate((el) => el.textContent)) | ||
); | ||
const scheduleObject = {title: title, date: date, type: type}; | ||
if (times) { | ||
const startTime = formattedDate(date, times.replace(/~.*/, '')); | ||
const endTimeHourMin = times.replace(/.*~/, ''); | ||
const endTime = endTimeHourMin ? formattedDate(date, endTimeHourMin) : startTime; | ||
scheduleObject.startTime = startTime; | ||
scheduleObject.endTime = endTime; | ||
} | ||
if (members.length !== 0) scheduleObject.description = `メンバー: ${members.join(', ')}`; | ||
result.push(scheduleObject); | ||
} | ||
} | ||
|
||
res.send(result); | ||
}; | ||
|
||
function formattedDate(date, hourMin) { | ||
if ((new Date(`${date} ${hourMin}`)).toString() !== 'Invalid Date') return `${date} ${hourMin}`; | ||
const hour = parseInt(hourMin.replace(/:.*/, '')); | ||
const min = parseInt(hourMin.replace(/.*:/, '')); | ||
const nextDayHour = hour - 24; | ||
const targetDate = new Date(date); | ||
targetDate.setDate(targetDate.getDate() + 1); | ||
targetDate.setHours(nextDayHour); | ||
targetDate.setMinutes(min); | ||
return `${targetDate.getFullYear()}.${(targetDate.getMonth()+1).toString().padStart(2, '0')}.${targetDate.getDate().toString().padStart(2, '0')} ${targetDate.getHours().toString().padStart(2, '0')}:${targetDate.getMinutes().toString().padStart(2, '0')}` | ||
} |
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
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
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,36 @@ | ||
export default class Counter { | ||
private static instance: Counter; | ||
|
||
private createEventCallCount; | ||
|
||
private deleteEventCallCount; | ||
|
||
private constructor() { | ||
this.createEventCallCount = 0; | ||
this.deleteEventCallCount = 0; | ||
} | ||
|
||
public static get getInstance(): Counter { | ||
if (!this.instance) { | ||
this.instance = new Counter(); | ||
} | ||
|
||
return this.instance; | ||
} | ||
|
||
public incrementCreateEventCallCount(): void { | ||
this.createEventCallCount += 1; | ||
} | ||
|
||
public getCreateEventCallCount(): number { | ||
return this.createEventCallCount; | ||
} | ||
|
||
public incrementDeleteEventCallCount(): void { | ||
this.deleteEventCallCount += 1; | ||
} | ||
|
||
public getDeleteEventCallCount(): number { | ||
return this.deleteEventCallCount; | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import dayjs from 'dayjs'; | ||
import KeyakiSiteSchedule from './sites/keyakizaka/keyakiSiteSchedule'; | ||
import SakuraSiteSchedule from './sites/sakurazaka/sakuraSiteSchedule'; | ||
import { SiteScheduleInterface } from './sites/siteSchedule'; | ||
|
||
export default class Schedule { | ||
static async setSchedule(): Promise<void> { | ||
static async setSchedule(startDate: dayjs.Dayjs): Promise<void> { | ||
const siteScheduleList: SiteScheduleInterface[] = [ | ||
new KeyakiSiteSchedule(), | ||
// new KeyakiSiteSchedule | ||
new SakuraSiteSchedule(), | ||
]; | ||
for await (const siteSchedule of siteScheduleList) { | ||
await siteSchedule.setSiteSchedule(); | ||
await siteSchedule.setSiteSchedule(startDate); | ||
} | ||
} | ||
} |
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
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,57 @@ | ||
import { SiteCalendarInterface } from '../../calendarInterface'; | ||
|
||
export const getSakuraCalendarUrl = | ||
process.env.ENV === 'production' | ||
? 'https://asia-northeast1-augc-260709.cloudfunctions.net/getSakuraSchedule?date=' | ||
: 'http://localhost:8081?date='; | ||
|
||
export const sakuraCalendarIds: SiteCalendarInterface[] = [ | ||
{ | ||
type: 'アルバム', | ||
calendarId: '0ivcdulcqpm0majeaqo0f1bml8@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'イベント', | ||
calendarId: 'ulksj6q2hr6hvvre7jqk2rghe4@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'シングル', | ||
calendarId: 'rf2qon3acq2g8fj1iuvngmp7tg@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'その他', | ||
calendarId: '06ol8jcjk0r5bviarevjicta70@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'テレビ', | ||
calendarId: '14elrf80nstbrahsfe2iuem8fg@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'メディア', | ||
calendarId: 'ivej29993ugnjb20l077n233i4@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'ラジオ', | ||
calendarId: 'f01lrnkgl42eqfbs1k97u7mrdc@group.calendar.google.com', | ||
}, | ||
{ | ||
type: 'リリース', | ||
calendarId: 'oo8hkuk4udrflu06337hq42jqo@group.calendar.google.com', | ||
}, | ||
{ | ||
type: '映画', | ||
calendarId: 'hbflgqvcrjvd9c1a07q5t93ork@group.calendar.google.com', | ||
}, | ||
{ | ||
type: '雑誌', | ||
calendarId: '2veim8rg9o7k2js0jtng8i2dug@group.calendar.google.com', | ||
}, | ||
{ | ||
type: '新聞', | ||
calendarId: 'g3puqreu4a67quqqu7ueo58l5k@group.calendar.google.com', | ||
}, | ||
{ | ||
type: '誕生日', | ||
calendarId: '02mgt618voeueel3gonuc62nrs@group.calendar.google.com', | ||
}, | ||
]; |
Oops, something went wrong.