Pages

@i Blog Posts

Tuesday, December 11, 2007

My first Py

A simple python script to retrieve prayer times form islamicfinder.com. Simply replace the prayerUrl variable to change the location to your preference.




## .-`-. o
## .' .-. `. .
## | ( ) ; |
## `. `-'`'-' `-
## `---
## PrayerTimes v1.0
## 10.12.07

import urllib
from sgmllib import SGMLParser

class TBLParser(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.doit = 0
self.cols = []
self.rows = []

def start_td(self, attrs):
for k, v in attrs:
if attrs == [('class', 'IslamicData'), ('bgcolor', '#FFFFFF'), ('align', 'center')] or \
attrs == [('class', 'IslamicData'), ('bgcolor', '#FFFFCC'), ('align', 'center')]:
self.doit = 1

def end_td(self):
self.doit = 0

def handle_data(self, text):
if self.doit == 1:
self.cols.append(text)
if len(self.cols)%8 == 0:
self.rows.append(self.cols)
self.cols = []


prayerUrl = "http://www.islamicfinder.org/prayerDetail.php?country=australia&city=perth_city&state=08&zipcode=&lang="
sock = urllib.urlopen(prayerUrl)
html = sock.read()
sock.close()

parser = TBLParser()
parser.feed(html)
parser.close()

for row in parser.rows:
for col in row:
print "%5.5s" % col,
print "\n"



Thanks Gold Flake Linux for the inspiration :)

2 comments:

shweetikle said...

is that for india? o.O

@i said...

perth, australia

.::.::.