Skip to content

Instantly share code, notes, and snippets.

@toshimasa-nanaki
Created November 21, 2017 12:55
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 toshimasa-nanaki/5510dadd1aee1e0f03fdf6845748c3a7 to your computer and use it in GitHub Desktop.
Save toshimasa-nanaki/5510dadd1aee1e0f03fdf6845748c3a7 to your computer and use it in GitHub Desktop.
Python3 + Flaskで簡易RSSリーダー
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('#submit').on("click", function() {
$.ajax({
url: "http://127.0.0.1:5000/rss",
type:'POST',
dataType: 'json',
data : {"rss_url": $("#rss_url").val()},
timeout:10000,
}).done(function(data) {
$("ul").empty();
data.forEach(function(element, index, array){
$("ul").append('<li><a href="'+ element.link +'" target="_blank">' + element.title + '</a></li>');
})
$('#submit').prop("disabled", false);
}).fail(function(XMLHttpRequest, textStatus, errorThrown) {
alert("error");
$('#submit').prop("disabled", false);
})
});
});
</script>
<table border="0">
<tr>
<td align="right"><b> RSS URL:</b></td>
<td><input type="text" name="rss_url" id="rss_url"></td>
</tr>
</table>
<input type="button" value="Submit" id="submit"/>
<div id="list">
<ul></ul>
</div>
<div id="detail"></div>
</body>
</html>
from flask import Flask, render_template, request
import feedparser
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html', title='RSS')
@app.route('/rss', methods=['POST'])
def rss():
url = request.form['rss_url']
dictionary = feedparser.parse(url)
import json
return json.dumps(dictionary.entries)
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment