Page 1 of 1

Python script för AAVSO rapport filer .

Posted: 2013-08-27 21:01:33
by akjalam2

Code: Select all

#!/usr/bin/python
# Easy script v1.0 , Coded by Pierre Hallsten SVO
#  Use as you wish!!

import os
import shutil
import fnmatch

'''

This script will read all your AAVSO report textfiles and glue them
together into one file named _mall.txt.
For easy upload to AAVSO

1/ Copy this script and all your report files to whatever dir
2/ Create a subdir namnes res
3/ Copy your header file to res and rename it mall.txt
4/ Run this script from the dir with this script and the AAVSO...text batch  

Script will output a new file (_mall.txt) with all your reports glued into one.

You can easily extend or modify script to whatever you need   

The header file i use is:

#TYPE=EXTENDED
#OBSCODE=HPIA
#SOFTWARE=VPhot 3.1
#DELIM=,
#DATE=JD
#OBSTYPE=CCD
#NAME,DATE,MAG,MERR,FILT,TRANS,MTYPE,CNAME,CMAG,KNAME,KMAG,AMASS,GROUP,CHART,NOTES

If you have more or fewer lines in your header file you have to change :

offset_end=8 to how many lines your header has -1. 
 
'''
offset_start=1
offset_end=8

#print "Python is really a great language,", "isn't it?";

shutil.copy2('res/mall.txt', 'res/_mall.txt')	
dir = os.getcwd()
allfiles = os.listdir(dir)
print allfiles


out = open("res/_mall.txt", "a+") #read and append

for file in os.listdir('.'):
	if fnmatch.fnmatch(file, '*.txt'):
		fo = open(file, "r",-1)
		fo.seek(0)
		for x in xrange(offset_start,offset_end): #skip header lines in files
			fo.readline()
		lines=fo.readlines()
		out.writelines(lines)
		fo.close() 
out.close()
		
print "done"

Re: Python script för AAVSO rapport filer .

Posted: 2013-08-27 21:02:52
by akjalam2
Detta script slår samman ett gäng "lösa" AAVSO.txt filer till en.
Tröttnade på att klippa och klistra :)
Enjoy
/Pierre

Re: Python script för AAVSO rapport filer .

Posted: 2013-08-29 10:18:09
by Tompa
Bra idé, detta har jag behov av!
Kan man få en lite mer detaljerad manual för en ny python-användare under windowsmiljö? Jag har inte lyckats få det att funka, men jag kanske har blivit fattlös på gamla dar :D

Mvh,
Tomas W

Re: Python script för AAVSO rapport filer .

Posted: 2013-08-29 21:07:21
by akjalam2
Har faktiskt aldrig kört Python under Windows.
WIndows använder jag när jag måste (typ om det inte finns program för Unix miljö)men aldrig annars.

Men det bör väl inte vara alltför komplicerat att få igång ?
Kolla om det finns några Youtube klipp om ämnet.

Skriptet är annars rätt självförklarande.

Raderna;

shutil.copy2('res/mall.txt', 'res/_mall.txt')
out = open("res/_mall.txt", "a+") #read and append

kan lätt ändras till de directory el filnamn du vill.

Lycka till o fråga gärna om det är ngt specifikt.
/Pierre