def make_rss(works): def mkdate(d): format_string = "%Y-%m-%d %H:%M:%S" r = rfc822(datetime.strptime(d, format_string).timestamp()) return r now = rfc822(datetime.now().timestamp()) ver = platform.python_version() print("<?xml version=\"1.0\"?>") print("<rss version=\"2.0\">") print("<channel>") print(" <title>[pixiv] フォロー新着作品</title>") print(" <link>http://www.pixiv.net/bookmark_new_illust.php</link>") print(" <pubDate>" + now + "</pubDate>") print(" <description />") print(" <generator>pixivrss (Python " + ver + ")</generator>") for i in works: title = i['title'] + " | " + i['user']['name'] print("\n <item>") print(" <title>" + escape(title) + "</title>") print(" <link>" + escape(ILLUST_URL + str(i['id'])) + "</link>") if i['caption']: caption = escape(i['caption']).replace("\r\n", "<br />") print(" <description>" + caption + "</description>") print(" <pubDate>" + mkdate(i['created_time']) + "</pubDate>") print(" <guid>" + escape(ILLUST_URL + str(i['id'])) + "</guid>") print(" </item>") print("</channel>") print("</rss>")
def make_rss(works): def mkdate(d): format_string = "%Y-%m-%d %H:%M:%S %z" r = rfc822(datetime.strptime(d + " +0900", format_string).timestamp()) return r now = rfc822(datetime.now().timestamp()) ver = platform.python_version() print('<?xml version="1.0"?>') print('<rss version="2.0">') print("<channel>") print(" <title>[pixiv] フォロー新着作品</title>") print(" <link>http://www.pixiv.net/bookmark_new_illust.php</link>") print(" <pubDate>" + now + "</pubDate>") print(" <description />") print(" <generator>pixivrss (Python " + ver + ")</generator>") for i in works: title = "「%s」/「%s」" % (i['title'], i['user']['name']) url = ILLUST_URL.format(user_id=str(i['user']['id']), illust_id=str(i['id'])) thumb_available = i['age_limit'] == "all-age" print("\n <item>") print(" <title>" + escape(title) + "</title>") print(" <link>" + escape(url) + "</link>") print(" <description><![CDATA[") if i['caption']: print(" " + i['caption'].replace("\r\n", "<br />")) if thumb_available: print(" <br />") if thumb_available: print(' <img src="' + escape(THUMB_URL.format(i['id'])) + '" />') print(" ]]></description>") print(" <pubDate>" + mkdate(i['created_time']) + "</pubDate>") print(" <guid>" + escape(url) + "</guid>") print(" </item>") print("</channel>") print("</rss>")
def mkdate(d): format_string = "%Y-%m-%d %H:%M:%S" r = rfc822(datetime.strptime(d, format_string).timestamp()) return r
def mkdate(d): format_string = "%Y-%m-%d %H:%M:%S %z" r = rfc822(datetime.strptime(d + " +0900", format_string).timestamp()) return r