ChaterJee 0.2.8__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ChaterJee/ChaterJee.py CHANGED
@@ -12,6 +12,7 @@ from telegram.ext import Updater, ApplicationBuilder, ContextTypes, CommandHandl
12
12
  from telegram.constants import ParseMode
13
13
  import os.path
14
14
  import threading
15
+ import subprocess
15
16
  from subprocess import PIPE, Popen
16
17
  from pathlib import Path
17
18
 
@@ -168,39 +169,26 @@ class ChatLogs:
168
169
  last_line = f.read().decode('utf-8')
169
170
  return last_line.strip()
170
171
 
171
- def get_last_line(filepath):
172
- with open(filepath, 'rb') as f:
173
- # Go to the end of file
174
- f.seek(0, 2)
175
- end = f.tell()
176
- pos = end - 1
177
- last_non_empty_pos = None
178
-
179
- # Step backwards to find last non-empty line
180
- while pos >= 0:
181
- f.seek(pos)
182
- char = f.read(1)
183
-
184
- # If we find a newline, check if we've collected non-whitespace since last newline
185
- if char == b'\n':
186
- if last_non_empty_pos is not None:
187
- break
188
- # Skip empty lines at the end
189
- end = pos
190
- elif not char.isspace():
191
- # Track position of last non-whitespace character
192
- last_non_empty_pos = pos
193
-
194
- pos -= 1
172
+ def get_last_line(self, filepath):
173
+ if not os.path.exists(filepath):
174
+ return None
195
175
 
196
- # If file is empty or only contains whitespace
197
- if last_non_empty_pos is None:
176
+ try:
177
+ command_chain = f"tail -n 1000 '{filepath}' | grep -Ev '^\s*$' | tail -n 1"
178
+ process = subprocess.run(command_chain, shell=True, capture_output=True, text=True, check=True)
179
+
180
+ output = process.stdout.strip()
181
+ if output:
182
+ return output
183
+ else:
198
184
  return None
199
185
 
200
- # Read the last non-empty line
201
- f.seek(last_non_empty_pos + 1 if last_non_empty_pos != end else 0)
202
- last_line = f.read(end - f.tell()).decode('utf-8')
203
- return last_line.strip()
186
+ except subprocess.CalledProcessError as e:
187
+ return None
188
+ except FileNotFoundError:
189
+ return None
190
+ except Exception as e:
191
+ return None
204
192
 
205
193
  async def cancel(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
206
194
  self.smsID.append(update.message.message_id)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ChaterJee
3
- Version: 0.2.8
3
+ Version: 0.3.0
4
4
  Summary: Communicate your project updates via Telegram Bot!
5
5
  Author: Pallab Dutta
6
6
  Author-email: pallab9997@gmail.com
@@ -0,0 +1,6 @@
1
+ ChaterJee/ChaterJee.py,sha256=68S4irt8YrysxKPCjUpjvx7FTt9vjZRNIGDUQXzKpEo,13674
2
+ ChaterJee/__init__.py,sha256=tZmkZY2XbzJ8rHDh8nOmb1W73kPecPv3xcEiCPwkZf4,98
3
+ chaterjee-0.3.0.dist-info/METADATA,sha256=IBDBB1q8sSQm9c-qyq74GUfkSgckiDt8bRVE3qNmjsQ,5872
4
+ chaterjee-0.3.0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
5
+ chaterjee-0.3.0.dist-info/top_level.txt,sha256=Z1UAYoaNybpDiKjqa1yFpti_q0FNECVItb3-9yAh3gM,10
6
+ chaterjee-0.3.0.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- ChaterJee/ChaterJee.py,sha256=sFcIZhnVihbRxaiIlvh7JBgjIkQ7xOe2wcirTmjmH7g,14204
2
- ChaterJee/__init__.py,sha256=tZmkZY2XbzJ8rHDh8nOmb1W73kPecPv3xcEiCPwkZf4,98
3
- chaterjee-0.2.8.dist-info/METADATA,sha256=CKER-5tBAhMOj9pUDOBA4vKqQnb1OPYwER_1qzf5LyM,5872
4
- chaterjee-0.2.8.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
5
- chaterjee-0.2.8.dist-info/top_level.txt,sha256=Z1UAYoaNybpDiKjqa1yFpti_q0FNECVItb3-9yAh3gM,10
6
- chaterjee-0.2.8.dist-info/RECORD,,