Skip to content

Instantly share code, notes, and snippets.

@lmeulen
lmeulen / UT2ALL_segments.py
Last active May 28, 2021 14:12
UT2ALL_segments
def pop_val(datastring, index):
b = None
res = shift = 0
while b is None or b >= 0x20:
b = ord(datastring[index]) - 63
res |= ( (b & 0x1f) << shift )
index += 1
shift += 5
if res & 1:
return ~(res >> 1), index
@lmeulen
lmeulen / UT2ALL_create_gpd.py
Created May 25, 2021 19:29
UT2ALL_create_gpd
segments_df['line'] = segments_df.apply(lambda x: LineString([Point(x["lon_x"], x["lat_x"]),
Point(x["lon_y"], x["lat_y"])]),
axis=1)
geodata = gpd.GeoDataFrame(segments_df, geometry=segments_df['line'])
geodata['width'] = 5 * (geodata['count']) / (geodata['count'].max())
@lmeulen
lmeulen / UT2ALL_plot.py
Created May 25, 2021 19:47
UT2ALL_plot
geodata.plot(figsize=(15, 15), linewidth=np.minimum(np.maximum(df5['width'], 0.1), 2.75))
@lmeulen
lmeulen / UT2ALL_basemap.py
Created May 26, 2021 18:37
UT2ALL_basemap
plt.figure(figsize=(15, 15))
ax = plt.gca()
geodata.plot(ax=ax)
import contextily as ctx
ctx.add_basemap(ax, crs='EPSG:4326', source=ctx.providers.OpenStreetMap.Mapnik)
@lmeulen
lmeulen / UT2ALL_with_basemap.py
Last active May 27, 2021 18:40
UT2ALL_with_basemap
ax = geodata.plot(figsize=(15,15))
import contextily as ctx
ctx.add_basemap(ax, crs='EPSG:4326', source=ctx.providers.OpenStreetMap.Mapnik)
@lmeulen
lmeulen / Screens_basescript.py
Last active June 1, 2021 12:36
Screens_basescript
import sys, logging, utils
from importlib import import_module
from logging.handlers import RotatingFileHandler
CONFIG_FILE = 'systems.cred'
if __name__ == '__main__':
logger = logging.getLogger('home automation')
logger.setLevel(logging.DEBUG)
fh = RotatingFileHandler('script.log', mode='a', maxBytes=10485760, backupCount=2)
@lmeulen
lmeulen / Screens_emptyscript.py
Last active May 31, 2021 19:45
Screens_emptyscript
import utils, logging
STATUS_FILE = "example.dat"
def run():
logger = logging.getLogger('home automation')
logger.debug("Script: Example script")
example_bool = utils.get_current_status(STATUS_FILE, default=False)
logger.debug("Example bool: " + str(example_bool))
example_bool = not example_bool
utils.save_current_state(STATUS_FILE, example_bool)
@lmeulen
lmeulen / Screens_tahoma_package.py
Last active May 30, 2021 08:45
Screens_tahoma_package
import logging, requests
logger = logging.getLogger('home automation')
class Screens(object):
def __init__(self, ifttt_key):
self.ifttt_key = ifttt_key
def ifttt_call(self, triggername):
logger.debug('Firing screen trigger : ' + triggername)
requests.post("https://maker.ifttt.com/trigger/" + triggername + "/with/key/" +
@lmeulen
lmeulen / Screens_mainloop.py
Last active May 30, 2021 11:41
Screens_mainloop
import tahoma, utils, logging, datetime
CONFIG_FILE = 'systems.cred'
STATUS_FILE = "status_screens.dat"
COUNT_FILE = "status_screens_count.dat"
COUNT_FILE_OPENNOW = "status_screens_count_opennow.dat"
DELAY_MINUTES = 7
def run(config=None):
@lmeulen
lmeulen / Screens_mainloop_booleans.py
Last active May 31, 2021 19:45
Screens_mainloop_booleans
import tahoma, utils, logging, datetime
CONFIG_FILE = 'systems.cred'
STATUS_FILE = "status_screens.dat"
COUNT_FILE = "status_screens_count.dat"
COUNT_FILE_OPENNOW = "status_screens_count_opennow.dat"
DELAY_MINUTES = 7
def run():