How to create a custom CSV file?

108 views
Skip to first unread message

Herwig Diessner

unread,
Oct 17, 2018, 8:40:55 AM10/17/18
to weewx-user
Hello all,

I need to export only 3 pieces of data from weewx into a file.
The file should contain a single line of text in the following format:
date;pressure;temperature

The date is in the format "yyyy-MM-dd HH:mm:ss".
The pressure and temperature are expressed in hPa and °C, respectively

I tried to use the CSV extension and succeeded in
- single line
- time-format

However, all sensor data is exported and the delimiter is fixed to , instead of the required ;

Is there any chance to succeed using the CSV extension (e.g. options to define the delimiter as ; instead of , - and options which sensor data is to be exported)?
Or do I need another extension, or is there even another way?

My searches on "export" and "csv" didn't bring any clues.

In case of interest, this is my use case:
I want to use temperature and pressure data to calculate "refraction" data for astrophotography using a 10micron telescope mount.
This mount allows to calculate refraction data automatically if fed with a text file with the specifications above.
Probably there are more users who might make use of this.

Thank you for any hint,

Herwig

Andrew Milner

unread,
Oct 17, 2018, 9:37:18 AM10/17/18
to weewx-user
the simplest way is to just create a new template and let cheetah do the work for you

eg for example
crerate template called csvdata.txt.tmpl - this will create a file called csvdata.txt when the reports are run - or create a template called csvdata.csv.tmpl will create a file called csvdata.csv in the same way that index.html.tmpl creates index.html

Inside the template .tmpl file put whatever you wish to be in the csv file, separators, data tags etc etc etc

add an report to the skin to create the file by running the template

rmc...@gmail.com

unread,
Oct 17, 2018, 11:03:37 AM10/17/18
to weewx-user
The following mysql select statement gave me the results you wanted.  2016-02-21 19:10:24;29.92;52.34
My database isn't metric but you can convert if necessary.  If you use sqllite i'm sure someone will convert for you.

select timestampadd(second, dateTime, '1970-01-01'),barometer,outTemp into outfile 'test.csv' fields terminated by ';' from archive limit 5;

Thomas Keffer

unread,
Oct 17, 2018, 8:36:35 PM10/17/18
to weewx-user
This is very easy to do in WeeWX. You certainly do not need to write SQL statements.

Create a file called mydata.txt.tmpl in the skins/Standard directory. Inside it, put

$current.dateTime.format("%Y-%m-%d %H:%M:%S"):$current.barometer.mbar:$current.outTemp.degree_C

In your skin configuration file, skin.conf, under the [[ToDate]] section, include the template file name. It should look something like this:

    [[ToDate]]
        # Reports that show statistics "to date", such as day-to-date,
        # week-to-date, month-to-date, etc.
        [[[mytemplate]]]
            template = mydata.txt.tmpl

        [[[day]]]
            template = index.html.tmpl
        
        ... (as before)

When WeeWX runs it will fill out the template and put it in your HTML directory.

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Herwig Diessner

unread,
Oct 20, 2018, 6:57:27 PM10/20/18
to weewx-user
Thank you Thomas, that did the trick - working like a charm. Thank you again!

Gert Andersen

unread,
Apr 17, 2020, 12:36:15 AM4/17/20
to weewx-user
Hi
How can I add lines instead of overwriting the line, so I have lines for each interval.

Gert
Reply all
Reply to author
Forward
0 new messages