mirror of
https://github.com/FAUSheppy/ths-reference-data-collector
synced 2025-12-06 06:51:35 +01:00
stylize xls output to match old manual design
This commit is contained in:
55
main.py
55
main.py
@@ -7,6 +7,7 @@ import requests
|
|||||||
import csv
|
import csv
|
||||||
import pyexcel.cookbook
|
import pyexcel.cookbook
|
||||||
import pyexcel
|
import pyexcel
|
||||||
|
import openpyxl
|
||||||
import glob
|
import glob
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
@@ -20,13 +21,13 @@ OUTSIDE_DATA_URL = "http://umweltdaten.nuernberg.de/csv/wetterdaten/messstat
|
|||||||
|
|
||||||
headerMappings = {
|
headerMappings = {
|
||||||
"time" : "Datum/Zeit",
|
"time" : "Datum/Zeit",
|
||||||
"lufttemperatur-aussen" : "Temperatur [°C]",
|
"lufttemperatur-aussen" : "Temperatur\n[°C]",
|
||||||
"kelvin" : "Temperatur [K]" ,
|
"kelvin" : "Temperatur\n[K]" ,
|
||||||
"luftfeuchte" : "rel. Luftfeuchte [%]",
|
"luftfeuchte" : "rel. Luftfeuchte\n[%]",
|
||||||
"luftdruck" : "Luftdruck [mbar]",
|
"luftdruck" : "Luftdruck\n[mbar]",
|
||||||
"windgeschwindigkeit" : "Windgeschwindigkeit [m/s]",
|
"windgeschwindigkeit" : "Windgeschwindig-\nkeit\n[m/s]",
|
||||||
"windrichtung" : "Windrichtung N=0, O=90, S=180, W=270",
|
"windrichtung" : "Windrichtung\nN=0, O=90,\nS=180, W=270",
|
||||||
"niederschlagsmenge" : "Niederschlag [mm = L/m2]" }
|
"niederschlagsmenge" : "Niederschlag\n[mm = L/m2]" }
|
||||||
|
|
||||||
dtypes = [ "lufttemperatur-aussen", "luftfeuchte", "luftdruck", "windgeschwindigkeit", "windrichtung", "niederschlagsmenge" ]
|
dtypes = [ "lufttemperatur-aussen", "luftfeuchte", "luftdruck", "windgeschwindigkeit", "windrichtung", "niederschlagsmenge" ]
|
||||||
|
|
||||||
@@ -154,4 +155,42 @@ if __name__ == "__main__":
|
|||||||
sheets.update({ os.path.basename(f) : sheet })
|
sheets.update({ os.path.basename(f) : sheet })
|
||||||
|
|
||||||
book = pyexcel.get_book(bookdict=sheets)
|
book = pyexcel.get_book(bookdict=sheets)
|
||||||
book.save_as("Wetterdaten.xlsx")
|
outfileRaw = "Wetterdaten.xlsx"
|
||||||
|
book.save_as(outfileRaw)
|
||||||
|
|
||||||
|
# formating and style #
|
||||||
|
wb = openpyxl.load_workbook(filename=outfileRaw)
|
||||||
|
longColStart = 5
|
||||||
|
for ws in wb.worksheets:
|
||||||
|
|
||||||
|
# width #
|
||||||
|
for col in ws.columns:
|
||||||
|
width = 20
|
||||||
|
longColStart -= 1
|
||||||
|
if longColStart < 0:
|
||||||
|
width = 40
|
||||||
|
ws.column_dimensions[col[0].column_letter].width = 20
|
||||||
|
|
||||||
|
|
||||||
|
# insert month info row
|
||||||
|
ws.insert_rows(1)
|
||||||
|
ws.merge_cells('A1:H1')
|
||||||
|
cell = ws['A1']
|
||||||
|
cell.value = ws.title
|
||||||
|
ws['A1'].alignment = openpyxl.styles.Alignment(horizontal='center')
|
||||||
|
cell.fill = openpyxl.styles.PatternFill(start_color='7F03ADFC',
|
||||||
|
end_color='7F03ADFC', fill_type = 'solid')
|
||||||
|
cell.font = openpyxl.styles.Font(bold=True)
|
||||||
|
|
||||||
|
# row height of header (second row behind title) #
|
||||||
|
ws.row_dimensions[2].height = 40
|
||||||
|
|
||||||
|
# color / wrap_text / bold #
|
||||||
|
for rows in ws.iter_rows(min_row=2, max_row=2, min_col=1):
|
||||||
|
for cell in rows:
|
||||||
|
cell.alignment = openpyxl.styles.Alignment(horizontal='center', vertical='top')
|
||||||
|
cell.font = openpyxl.styles.Font(bold=True)
|
||||||
|
cell.fill = openpyxl.styles.PatternFill(start_color='7F03ADFC',
|
||||||
|
end_color='7F03ADFC', fill_type = 'solid')
|
||||||
|
|
||||||
|
wb.save(outfileRaw)
|
||||||
|
|||||||
Reference in New Issue
Block a user