summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-04-15 16:47:36 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-04-15 16:47:38 +0300
commit1e5a2df1a02b2205eaf211fbbdef819263ba9cc9 (patch)
treee85770f29d3d8eefa3ee1a66c84e0241824a30dc
parentdcf2cbdbeec56a8196b2b4d34848c85ab1530583 (diff)
keep track of file size
-rwxr-xr-xmain.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/main.py b/main.py
index 36cf5d9..3779688 100755
--- a/main.py
+++ b/main.py
@@ -10,7 +10,7 @@ from argparse import ArgumentParser
def readstate(file: str) -> dict:
if not os.path.exists(file):
- default_state = {'seek': 0}
+ default_state = {'seek': 0, 'size': 0}
writestate(file, default_state)
return default_state
@@ -41,15 +41,22 @@ def main():
# read file
state = readstate(args.state_file)
+ fsize = os.path.getsize(args.log_file)
+
+ if fsize < state['size']:
+ state['seek'] = 0
+
with open(args.log_file, 'r') as f:
- # jump to the latest readed position
- f.seek(state['seek'])
+ if state['seek']:
+ # jump to the latest readed position
+ f.seek(state['seek'])
# read till the end of the file
content = f.read()
# save new position
state['seek'] = f.tell()
+ state['size'] = fsize
writestate(args.state_file, state)
# if got something, send it to telegram