Skip to content

Commit

Permalink
support rts argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ddhp committed May 14, 2020
1 parent 62de659 commit 5ae8285
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion heartbeat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import argparse
import hashlib
import json
import time
Expand All @@ -10,8 +11,15 @@

DATETIME_FORMAT = '%m/%d %H:%M'

# Initiate the parser
parser = argparse.ArgumentParser()
# rts stands for "relative to script"
parser.add_argument('--rts', action='store_true', help='find heartbeat.yaml relative to heartbeat.py')
# Read arguments from the command line
args = parser.parse_args()

# without changing to string only works after python 3.5
f_path = str(Path(__file__).parent) + '/'
f_path = str(Path(__file__).parent) + '/' if args.rts else ''

def format(s):
return time.strftime(DATETIME_FORMAT, time.gmtime(s))
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Example:

# Installation

Run every minute via `crontab -e`:
Run every minute via `crontab -e`, set argument `rts`(relative to script) to true in order to find config file relative to the python script:

```
* * * * * /usr/local/bin/python3 /home/me/heartbeat.py
* * * * * /usr/local/bin/python3 /home/me/heartbeat.py --rts
```

0 comments on commit 5ae8285

Please sign in to comment.