File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ import socket
2
+
3
+ ip = raw_input ("IP: " )
4
+ port = int (raw_input ("Port: " ))
5
+
6
+ try :
7
+ s = socket .socket ()
8
+ s .settimeout (5 )
9
+ s .connect ((ip ,port ))
10
+ s .send ("HEAD / HTTP/1.0 \r \n \r \n " )
11
+
12
+ result = s .recv (1024 )
13
+ s .close ()
14
+ print str (result )
15
+
16
+ except Exception , e :
17
+ print str (e )
18
+ import socket
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+ print "Content-Type: text/plain\n \n "
3
+ import urllib , re , sys
4
+ import cgi
5
+
6
+ url = "http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MGRAI1"
7
+
8
+ url_1 = "http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAR795"
9
+
10
+ # Create the regex and use multiline
11
+
12
+ webpage = urllib .urlopen (url ).read ()
13
+
14
+ webpage1 = urllib .urlopen (url_1 ).read ()
15
+
16
+ match = re .search ("<city>([^<]*)</city>" , webpage )
17
+ loc = match .group (1 )
18
+
19
+ match = re .search ("<observation_time>([^<]*)</observation_time>" , webpage )
20
+ time = match .group (1 )
21
+
22
+ match = re .search ("<windchill_string>([^<]*)</windchill_string>" , webpage )
23
+ wind_chill = match .group (1 )
24
+
25
+ match = re .search ("<state>([^<]*)</state>" , webpage )
26
+ state = match .group (1 )
27
+
28
+ match = re .search ("<temperature_string>([^<]*)</temperature_string>" , webpage )
29
+ temp = match .group (1 )
30
+
31
+ match = re .search ("<wind_string>([^<]*)</wind_string>" , webpage )
32
+ wind = match .group (1 )
33
+
34
+ match = re .search ("<relative_humidity>([^<]*)</relative_humidity>" , webpage )
35
+ rh = match .group (1 )
36
+
37
+ match = re .search ("<elevation>([^<]*)</elevation>" , webpage )
38
+ ele = match .group (1 )
39
+
40
+ match = re .search ("<precip_today_string>([^<]*)</precip_today_string>" , webpage )
41
+ precip = match .group (1 )
42
+
43
+ print " Black Canyon Weather Report"
44
+ print " Elevation" , ele
45
+ print " Temperature" , temp
46
+ print " Wind" ,wind
47
+ print " Precipitation Today" , precip
48
+ print " RH" ,rh ,"%"
49
+ print " " ,time
You can’t perform that action at this time.
0 commit comments