Skip to content

Instantly share code, notes, and snippets.

@kizashi1122
Created October 12, 2015 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kizashi1122/3b8fe8bdda9e80bc7a62 to your computer and use it in GitHub Desktop.
Save kizashi1122/3b8fe8bdda9e80bc7a62 to your computer and use it in GitHub Desktop.
Extract New Movies From Unext Page And Email it (This script is no longer available)
function myFunction() {
var response = UrlFetchApp.fetch("http://pc.unext.jp/title/new_title/0/2");
var array = scrape(response.getContentText());
array.length = 48;
var html = buildTable(array);
var d = Utilities.formatDate( new Date(), 'JST', 'yyyy年M月d日');
MailApp.sendEmail(
"email@example.com", // 送信先メール
"U-NEXT Update - " + d, // メール件名
"",
{
htmlBody: html
}
);
}
function scrape(text) {
var lines = text.split("\n");
var start_mark = false;
var start_regex = /<li class="to-newarrivalbox__col">/;
var end_regex = /^<\/li>$/;
var date_regex = /<p class="to-newarrivalbox__col__rdate">(.*)<\/p>/;
var cont_regex = /\s+<a href="([^"]+)" .+ alt="([^"]+)" data-srcorigin="([^"]+)"/;
var base_url = 'http://pc.unext.jp/';
var array = [];
var title, imgurl, link;
for(var i = 0, len = lines.length; i < len; i++) {
var line = lines[i];
var start_match = line.match(start_regex);
if (start_match) { start_mark = true }
if (start_mark) {
var c = line.match(cont_regex);
if (c) {
link = base_url + c[1];
title = c[2];
imgurl = c[3].replace('amp;', '');
}
var d = line.match(date_regex);
if (d) {
date = d[1];
array.push({date: date, title: title, imgurl: imgurl, link: link});
}
}
}
return array;
}
function buildTable(array) {
var html = '<table style="border-collapse: collapse"><tbody>';
for(var i = 0, len = array.length; i < len; i++) {
var obj = array[i];
if (i % 3 == 0) { html += '<tr>'; }
html += '<td><a href="' + obj['link'] + '" target="_blank"><img src="' + obj['imgurl'] + '" width="112" height="63"></a></td>';
html += '<td><span style="font-weight: bold; color: #666">' + obj['date'] + '</span><br>' + obj['title'] + '</td>';
if (i % 2 == 2) { html += '</tr>'; }
}
html += '</tbody></table>';
return html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment