Browse Source

added openpyxl to requirements

pyinstaller
Holger Frey 7 years ago
parent
commit
766b0ca5aa
  1. 2
      LICENSE
  2. 33
      arduino_timetable/__init__.py
  3. 1
      setup.py

2
LICENSE

@ -1,4 +1,4 @@
Copyright (c) <year> <owner> . All rights reserved. Copyright (c) 2017, Holger Frey . All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

33
arduino_timetable/__init__.py

@ -8,8 +8,11 @@ from collections import namedtuple
from datetime import datetime, timedelta from datetime import datetime, timedelta
__version__ = '0.0.1'
# example time table for the TrapControl # example time table for the TrapControl
example = ''' example = '''
00:00.0 close 00:00.0 close
00:06.0 open 00:06.0 open
00:08.0 close 00:08.0 close
@ -36,12 +39,12 @@ def parse_time_table(timetable, available_commands):
timetable: timetable:
a textual representaion of time and commands like a textual representaion of time and commands like
00:12.0 close 00:12.0 close
00:14.0 open 00:14.0 open
00:16.0 close 00:16.0 close
00:18.0 open 00:18.0 open
available_commands: available_commands:
a dictionary containing the available human readable commands as a dictionary containing the available human readable commands as
keys and the commands to send as values keys and the commands to send as values
@ -56,7 +59,7 @@ def parse_time_table(timetable, available_commands):
content_lines = (line.strip() for line in raw_lines) content_lines = (line.strip() for line in raw_lines)
# remove empty lines # remove empty lines
lines = (line for line in content_lines if line) lines = (line for line in content_lines if line)
timed_commands =[] timed_commands =[]
for line in lines: for line in lines:
# split the lines into time and command # split the lines into time and command
@ -113,7 +116,7 @@ def parse_command(command, available_commands):
{'open': 0, 'close': 1} {'open': 0, 'close': 1}
returns the command to send over serial returns the command to send over serial
''' '''
try: try:
cmd = available_commands[command.lower()] cmd = available_commands[command.lower()]
except KeyError: except KeyError:
@ -173,7 +176,7 @@ def run(scheduled_commands, serial_connection):
except KeyboardInterrupt: except KeyboardInterrupt:
loop.stop() loop.stop()
loop.close() loop.close()
class TimedCommands(object): class TimedCommands(object):
''' lightweight encapsulation of the functions in the module ''' ''' lightweight encapsulation of the functions in the module '''
@ -187,13 +190,14 @@ class TimedCommands(object):
''' parses a time table and establishes a serial connection ''' parses a time table and establishes a serial connection
timetable: timetable:
a file path to an excel file or
a textual representaion of time and commands like a textual representaion of time and commands like
00:12.0 close 00:12.0 close
00:14.0 open 00:14.0 open
00:16.0 close 00:16.0 close
00:18.0 open 00:18.0 open
available_commands: available_commands:
a dictionary containing the available human readable commands a dictionary containing the available human readable commands
as keys and the commands to send as values. as keys and the commands to send as values.
@ -215,7 +219,10 @@ class TimedCommands(object):
# make sure the available commands are a dictionary # make sure the available commands are a dictionary
cmd_dict = self._ensure_command_dict(available_commands) cmd_dict = self._ensure_command_dict(available_commands)
# parse the time table into something suitable # parse the time table into something suitable
self.commands = parse_time_table(timetable, cmd_dict) if '.xls' in timetable:
self.commands = parse_excel_file(timetable, cmd_dict)
else:
self.commands = parse_time_table(timetable, cmd_dict)
# establish the serial connection # establish the serial connection
port = port or find_arduino_port() port = port or find_arduino_port()
@ -232,7 +239,7 @@ class TimedCommands(object):
items is used as a human readable command and the first items is used as a human readable command and the first
character of this command will be sent over the wire character of this command will be sent over the wire
''' '''
try: try:
if isinstance(iterable, dict): if isinstance(iterable, dict):
pairs = list(iterable.items()) pairs = list(iterable.items())
@ -247,7 +254,7 @@ class TimedCommands(object):
except: except:
msg = 'available commands should be a list or dict of strings' msg = 'available commands should be a list or dict of strings'
raise TypeError(msg) raise TypeError(msg)
def run(self): def run(self):
''' run the scheduled commands ''' ''' run the scheduled commands '''
@ -256,8 +263,6 @@ class TimedCommands(object):
class TrapControl(TimedCommands): class TrapControl(TimedCommands):
''' A simple, stripped down version for the magnetic plug trap ''' ''' A simple, stripped down version for the magnetic plug trap '''
def __init__(self, timetable): def __init__(self, timetable):
super().__init__(timetable, ['open', 'close']) super().__init__(timetable, ['open', 'close'])

1
setup.py

@ -110,6 +110,7 @@ setup(
# https://packaging.python.org/en/latest/requirements.html # https://packaging.python.org/en/latest/requirements.html
install_requires=[ install_requires=[
'pyserial', 'pyserial',
'openpyxl',
], ],
# List additional groups of dependencies here (e.g. development # List additional groups of dependencies here (e.g. development

Loading…
Cancel
Save