Python: Wunderground Todays Weather to Email SMS to Phone

wunderground

I could see somebody setting this as a cron task to send every morning so when you wake up, you get the current weather as a text message. 

I am about to set it up. 

Enjoy
————————————————————

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import urllib2
import time
ZIP = "20190"
ACCOUNT = "d37"  # put your gmail email account name here
PASSWORD = "neah"  # put your gmail email account password here
to_addrs = "[email protected], [email protected]"
subject = "Wunderground Email"
 
try:
	f = urllib2.urlopen('http://www.wund.com/cgi-bin/findweather/getForecast?query='+ZIP)
	page = f.read()
	i = page.find('<div id="main">')
	page2 = page[i:]
	i = page2.find("<span>")+6
	page = page2[i:]
	i = page.find("</span>")
	temperature = page[:i]
 
	i = page.find("<h4>")+4
	page = page[i:]
	i = page.find("</h4>")
	current = page[:i]
 
	i = page.find("<span>")+6
	page = page[i:]
	i = page.find("</span>")
	wind = page[:i]
 
 
	i = page.find("<span>")+6
        page = page[i:]
        i = page.find("</span>")
        dewpoint = page[:i]
 
 
	i = page.find("<b>")+3
        page = page[i:]
        i = page.find("</b>")
        pressure = page[:i]
 
 
        i = page.find('<div class="b">')+15
        page = page[i:]
        i = page.find("</div>")
        humidity = page[:i]
 
 
        i = page.find("<span>")+6
        page = page[i:]
        i = page.find("</span>")
        visibility = page[:i]
 
 
	page = page[9:]
 
        i = page.find("</span>")+8
        page = page[i:]
        i = page.find("</h5")
        updated = page[:i]
 
 
	i = page.find('<div id="forecast">')
	page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
	i=page.find('</span>')
	d1n = page[:i]
 
	i = page.find('<div>')+4
	page = page[i:]
	i = page.find('<div>')+5
	page = page[i:]
	i = page.find('</div>')
	d1 = page[:i]
 
	page = page[i:]
	i = page.find('<span>')+6
	page = page[i:]
	i = page.find('</span>')
        d1h = page[:i]
 
	page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d1l = page[:i]
 
	i = page.find('<td')
	page = page[i:]
 
#===================
        i = page.find('<span>')+6
        page = page[i:]
        i=page.find('</span>')
        d2n = page[:i]
 
        i = page.find('<div>')+4
        page = page[i:]
        i = page.find('<div>')+5
        page = page[i:]
        i = page.find('</div>')
        d2 = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d2h = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d2l = page[:i]
 
        i = page.find('<td')
        page = page[i:]
 
#===================
        i = page.find('<span>')+6
        page = page[i:]
        i=page.find('</span>')
        d3n = page[:i]
 
        i = page.find('<div>')+4
        page = page[i:]
        i = page.find('<div>')+5
        page = page[i:]
        i = page.find('</div>')
        d3 = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d3h = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d3l = page[:i]
 
        i = page.find('<td')
        page = page[i:]
 
#===================
        i = page.find('<span>')+6
        page = page[i:]
        i=page.find('</span>')
        d4n = page[:i]
 
        i = page.find('<div>')+4
        page = page[i:]
        i = page.find('<div>')+5
        page = page[i:]
        i = page.find('</div>')
        d4 = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d4h = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d4l = page[:i]
 
        i = page.find('<td')
        page = page[i:]
 
#===================
        i = page.find('<span>')+6
        page = page[i:]
        i=page.find('</span>')
        d5n = page[:i]
 
        i = page.find('<div>')+4
        page = page[i:]
        i = page.find('<div>')+5
        page = page[i:]
        i = page.find('</div>')
        d5 = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d5h = page[:i]
 
        page = page[i:]
        i = page.find('<span>')+6
        page = page[i:]
        i = page.find('</span>')
        d5l = page[:i]
 
        i = page.find('<td')
        page = page[i:]
 
 
except URLError, e:
	print e.code
	print e.read()
 
#print "Temp:" + temperature
#print "Current" + current
#print "Wind: " + wind
##print "Dew: "+ dewpoint
#print "Pressure:" + pressure
#print "Humid:" + humidity
#print "Visib:" + visibility
#print "Updated: " + updated
 
#print d1n + "-" + d1 + ":" + d1h + "/" + d1l
#print d2n + "-" + d2 + ":" + d2h + "/" + d2l
#print d3n + "-" + d3 + ":" + d3h + "/" + d3l
#print d4n + "-" + d4 + ":" + d4h + "/" + d4l
#print d5n + "-" + d5 + ":" + d5h + "/" + d5l
 
#temperature, current, wind, dewpoint, pressure, humidity, visibility
#	updated, dXn, dX, dXh, hXl (x=1-5, h=high, l=low, n=name)
 
subject += updated
msg = "Now:"+current+"-"+temperature
msg += "\r\nHum:"+humidity
msg += "\r\n"+d1n + "-" + d1 + ":" + d1h + "/" + d1l
msg += "\r\n"+d2n + "-" + d2 + ":" + d2h + "/" + d2l
msg += "\r\nUpdated:"+updated
 
 
 
 
import smtplib
HOST = "smtp.gmail.com"
PORT = 587
 
try:
	server = smtplib.SMTP(HOST,PORT)
	#server.set_debuglevel(1)    # you don't need this
	server.ehlo()
	server.starttls()
	server.ehlo()
	server.login(ACCOUNT, PASSWORD)
	headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (ACCOUNT, to_addrs, subject)
	server.sendmail(ACCOUNT, to_addrs, headers + msg)
	server.quit()
except:
	time.sleep(1)

Python – Cell Phone Number Pad Input

Here is the first version of a little python program I made that will translate input from a cellphone text pad or a number pad to text.
UPDATE: VERSION 2
It’s pretty darn simple.

It would go perfect with this:
http://www.flickr.com/photos/svofski/3383950702/in/pool-make

Continue reading “Python – Cell Phone Number Pad Input”

SSH/SCP/SFTP I love them all.

ssh_binary_packet_alt_sm.jpg
I pretty much use ssh for everything. I use it mostly to connect to my home/web/this server and use it as an interface. The best program to use alongside ssh is screen.

To install both ssh and screen, you may do this:

  1. sudo apt-get install ssh
  2. sudo apt-get install screen

If I were good with words, I would write a poem for ssh. But alas, I am not. So, you get the first page from the Wikipedia Entry.

Secure Shell or SSH is a network protocol that allows data to be exchanged over a secure channel between two computers. Encryption provides confidentiality and integrity of data. SSH uses public-key cryptography to authenticate the remote computer and allow the remote computer to authenticate the user, if necessary.

Here are a few of the best SSH/SCP commands EVER:

  1. ssh server.com
  1. scp server.com:./ /home/local/downloadhere/
    Popular/Best SSH/SCP/Clients (mostly for windows, because linux usually already has tools built in.):

  • WinSCP
  • Putty
  • gFTP
  • the normal commands that come with Linux(ssh, scp)

Facebot – My Facebook Robot

facebot

I have written a new program. It’s called facebot. This program takes the public RSS feed from many people and converts it into a visual display of the relationships on facebook.

Go here to check it out.

Py2Html

Python-Command Line Python-To-Html Converter. Makes posting Python to blogs quick.

by: Daniel Folkes

This is Licensed under GPLv3. Give Back.

Py2Html

    Download Source

  1. print “”” This is a simple program that takes a python file and replaces the
  2. plain text punctuation with the easily postable html code.
  3. written by :    Daniel Folkes
  4.         danfolkes @t gm@il d0t c0m
  5.         http://danfolkes.com
    Continue reading “Py2Html”

Python Torrent Search and Download (TPB)

This python command line utility will search the pirate bay for a specific search string and pull out the torrent files and download them to your current directory.

by: Daniel Folkes

This is Licensed under GPLv3. Give Back.

tpb.jpg

    Download Source

  1. print “””Pirate Bay Torrent Downloader – Command Line Interface
  2. Program Written by: Daniel Folkes
  3. website: http://danfolkes.com
  4. email: danfolkes @t gmail dot c0m
    Continue reading “Python Torrent Search and Download (TPB)”

Learning Python

I just checked UPS tracking for a book I ordered. IT HAS ARRIVED!!!

Learning Python, I hope, will be the first stepping stone to me becoming a more well rounded programmer. I have started to have interest in Python(cool name) because of Ubuntu and OLPC(One Laptop Per Child). Both of these projects aim to help the world, and they depend on Python. I would love to be able to write a great application that would easily work for kids of developing countries , and/or on my operating system of choice, Ubuntu(or any Linux).

I decided to choose Python over Perl (I bought “Learning Perl” about a year ago). Creating GUIs in Python seems more intuitive, and I prefer object oriented programming(I don’t think Perl is) .

Python over Java : I wanted something more nerdy and that could integrate with UNIX better.

Python over C++: C++ is much to hard. Just compare the list structure in both languages. Also, DB work will be easier (I hope :))

So, while I’m stuck away from home until tomorrow, my book will sit on my front porch. I can not wait to get home and rip it open. :)~

Comments about “Learning Perl”

The Perl book was excellently written, and the authors deserve awards for how easy it was to read. I got through most of the book in 2 days. It just so happens that the two days had about 11 months in-between. Because the book was so good, it almost makes me feel bad about deserting Perl, but it must happen.