SkySafari의 관측 목록 신속 생성(Observing Lists)

14394 단어
import re
def writealllines(lines,src,srccoding="utf-8",filetype="txt",crlf=True):
    rf = ''
    if crlf == True:
        rf = '
'
fp = open(src, "w", encoding=srccoding) fp.writelines([line + rf for line in lines]) fp.close() def skylistMake(src,ngcdat=None): lins = ['SkySafariObservingListVersion=3.0', 'SortedBy=Default Order'] num = 0 for line in open(src, "r").read().splitlines(): it = line cm = '' if ',' in line: it = line.split(',',1)[0] cm = line.split(',',1)[1] elif '\t' in line: it = line.split(',',1)[0] cm = line.split(',',1)[1] itp = re.match('^([A-z]+)(.*)$', it) if itp: it = itp.group(1) + ' ' + itp.group(2) lins.append('SkyObject=BeginObject') lins.append('\tObjectID=4,-1,-1') lins.append('\tCatalogNumber=' + it) lins.append('\tDefaultIndex=' + str(num)) if cm != '': lins.append('\tComment=' + cm) lins.append('EndObject=SkyObject') num += 1 writealllines( lins,src.replace('.txt','.skylist')) return if __name__ == '__main__': skylistMake('list.txt')

PK 및 PNG의 경우
def PNsolve(it):
    gp1 = re.match('^PK\s*(.+)([\-\+])(.+)$',it)
    if gp1:
        return 'PK'+gp1.group(1).zfill(3)+gp1.group(2)+gp1.group(3).zfill(4)
    gp2 = re.match('^PN G\s*(.+)([\-\+])(.+)$',it)
    gp2p = re.match('^PNG\s*(.+)([\-\+])(.+)$',it)
    if gp1:
        return 'PN G'+gp1.group(1).zfill(5)+gp1.group(2)+gp1.group(3).zfill(4)
    if gp2p:
        return 'PN G'+gp2p.group(1).zfill(5)+gp2p.group(2)+gp2p.group(3).zfill(4)
    return it

def solveDSO(it):
    it = it.strip()
    it = it.replace(' ','')
    it = it.replace('\t','')
    it = PNsolve(it)
    return it
    

좋은 웹페이지 즐겨찾기