misc.py

Wed, 28 Jun 2017 13:11:37 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 28 Jun 2017 13:11:37 +0300
changeset 32
ca1a0ea81cf6
parent 24
e6bdb9c54096
child 71
d2e19670b772
permissions
-rw-r--r--

Yhdistetty pysäkki.png ja iso-pysäkki.png

from datetime import datetime, date, time, timedelta

def today():
	return date.today()
	#return date(2017, 1, 10)

def now():
	return datetime.now()
	#return datetime.combine(today(), datetime.now().time())

def read_csv(file, transformations = None):
	import csv
	lukija = csv.reader(file)
	keys = next(lukija)
	for i in range(len(keys)):
		keys[i] = keys[i].replace('\ufeff', '').strip()
	for rivi in lukija:
		entry = dict(zip(keys, rivi))
		if transformations:
			for key, transformation in transformations.items():
				entry[key] = transformation(entry[key])
		yield entry

def is_night_time(time):
	return time.hour >= 23 or time.hour < 5

mercurial