1
##************************************************************************##
2
# supernova_updates_parser.py - K Desktop Planetarium #
3
# ------------------- #
5
# copyright : (C) 2011 by Samikshan Bairagya #
6
# email : samikshan@gmail.com #
7
##************************************************************************##
9
##************************************************************************##
11
# This program is free software; you can redistribute it and/or modify #
12
# it under the terms of the GNU General Public License as published by #
13
# the Free Software Foundation; either version 2 of the License, or #
14
# (at your option) any later version. #
16
##************************************************************************##
18
### Supernova Updates Parser. This program reads data from http://www.cbat.eps.harvard.edu/lists/RecentSupernovae.html
19
### This page gives details on supernovae that have occurred since the start of 2010.
25
from PyKDE4.kdecore import KStandardDirs
28
parsed = toCSV(re.sub('<.*?>','',line))
31
#FIXME: The extracted data is converted to CSV by inserting commas
32
#after definite number of characters. There might be a better
35
commaInterval= [7,24,36,44,51,63,68,86,110,129,133,143]
36
for i in range(0,len(line)-1):
37
if i in commaInterval:
38
edited = line [ :i ] + "," +line [ i+1: ]
42
sock = urllib.urlopen("http://www.cbat.eps.harvard.edu/lists/RecentSupernovae.html")
43
pageLines=sock.readlines()
48
output = open(KStandardDirs().locateLocal('data','kstars/supernovae.dat'),'w')
49
#print KStandardDirs().locateLocal('data','kstars/supernovae.dat')
52
p = re.compile("</pre>")
58
parsedLine = "#" + parse(i)
63
output.write(parsedLine)
65
p = re.compile("<pre>")