-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwr-wifi-status.1m.py
executable file
·53 lines (47 loc) · 1.57 KB
/
gwr-wifi-status.1m.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# <bitbar.title>GWR Wifi Status</bitbar.title>
# <bitbar.version>v0.1</bitbar.version>
# <bitbar.author>Adam Marsh</bitbar.author>
# <bitbar.author.github>Adam2Marsh</bitbar.author.github>
# <bitbar.desc>Shows the WiFi Status when on a GWR train.</bitbar.desc>
# <bitbar.image>http://gwr.passengerwifi.com/library/images/logo-gwr%402x.png</bitbar.image>
# <bitbar.dependencies>GWR-Wifi,python,dryscrape</bitbar.dependencies>
# GWR Passenger Wifi Page
url = "http://gwr.passengerwifi.com/connected.php"
import dryscrape
import re
# import urllib2
try:
# result = urllib2.urlopen(url, timeout = 5).read()
session = dryscrape.Session()
session.visit(url)
result = session.body();
print "🚂"
print "---"
try:
signalStrength = re.search('<div class=\"guagevalue\" id=\"signalvalue\">(\d+%)<\/div>', result);
print "Signal Strength:"
print signalStrength.group(1) + "| href=" + url
except:
print "❌"
print "---"
try:
howBusy = re.search('<div class=\"guagevalue\">([\w\s]+)<\/div>', result);
print "How Busy:"
print howBusy.group(1) + "| href=" + url
except:
print "❌"
print "---"
try:
location = re.search('<div class=\"description\">[\t\n\r]\s+<h2>([\w\s]+)<\/h2>', result);
print "Location:"
print location.group(1) + "| href=" + url
except:
print "❌"
print "---"
except:
print "❌"
print "---"
print "GWR Passenger Wifi Not Available | color=red"
print "---"