Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit: URL status pinger

  • Loading branch information...
commit c7a819d72e34d4cdc8f66c9e61cb72d5f0abc765 0 parents
@hltbra hltbra authored
29 pinger.py
@@ -0,0 +1,29 @@
+from flask import Flask, render_template
+import datetime
+import socket
+import requests
+
+
+app = Flask(__name__)
+
+@app.route('/')
+def home():
+ sites = open("sites.txt").read().split()
+ result = []
+ for site in sites:
+ try:
+ response = requests.get(site, timeout=1, allow_redirects=True)
+ assert response.text != ''
+ assert response.status_code == 200
+ except (requests.exceptions.Timeout, socket.timeout, AssertionError) as err:
+ result.append((site, "fail"))
+ else:
+ result.append((site, "ok"))
+ now = datetime.datetime.now()
+ return render_template('pinger.html', result=result, last_update=now)
+
+
+if __name__ == '__main__':
+ app.run(debug=True)
+
+
2  requirements.txt
@@ -0,0 +1,2 @@
+requests
+flask
1  sites.txt
@@ -0,0 +1 @@
+http://globo.com
45 templates/pinger.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <style>
+ table {
+ border-collapse: collapse;
+ }
+
+ td {
+ border: solid #888;
+ border-width: 1px;
+ font-weight: bold;
+ padding: 0.75em 1.2em;
+ position: relative;
+ }
+ .ok {
+ background-color: green;
+ }
+ .fail {
+ background-color: red;
+ }
+ .status {
+ font-size: 20px;
+ }
+ </style>
+ <meta http-equiv="Refresh" content="60"/>
+ </head>
+ <body>
+ <div class="content">
+ <table>
+ <tr>
+ <td>Site</td>
+ <td>Status</td>
+ </tr>
+ {% for site, status in result %}
+ <tr>
+ <td><a href="{{ site }}">{{ site }}</a></td>
+ <td class="status {{ status }}"></td>
+ </tr>
+ {% endfor %}
+ </table>
+ Last update: {{ last_update }}
+ </div>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.