mirror of
https://github.com/gentoo-root/telegram-tracker
synced 2025-08-20 05:13:47 -07:00
tracker: Add a file output
Also update the README and the gitignore
This commit is contained in:
parent
f9b76e45f2
commit
03348d571f
3 changed files with 37 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
/settings/keys.py
|
||||
/tracker.session
|
||||
__pycache__/
|
||||
trackerLogs.txt
|
||||
|
|
|
@ -11,6 +11,7 @@ Example output:
|
|||
=2018-01-19 @ 01:46:39: User went offline after being online for short time.
|
||||
|
||||
= means that the time is exact as returned by the Telegram server, and ~ means that the time is measured locally and can be inexact.
|
||||
By default the times are saved to a file called `trackerLogs.txt` along with being printed to `STDOUT`.
|
||||
|
||||
How to run
|
||||
----------
|
||||
|
|
|
@ -46,33 +46,45 @@ contact_id = argv[1]
|
|||
client = TelegramClient('tracker', API_ID, API_HASH)
|
||||
client.start()
|
||||
|
||||
# File IO
|
||||
dataFile = open('shuTimes.txt', 'a+')
|
||||
|
||||
online = None
|
||||
last_offline = None
|
||||
while True:
|
||||
if contact_id in ['me', 'self']:
|
||||
try:
|
||||
dataFile = open('trackerLogs.txt', 'a+', encoding = 'utf-8')
|
||||
if contact_id in ['me', 'self']:
|
||||
# Workaround for the regression in Telethon that breaks get_entity('me'):
|
||||
# https://github.com/LonamiWebs/Telethon/issues/1024
|
||||
contact = client.get_me()
|
||||
else:
|
||||
contact = client.get_entity(contact_id)
|
||||
contact = client.get_me()
|
||||
else:
|
||||
contact = client.get_entity(contact_id)
|
||||
|
||||
if isinstance(contact.status, UserStatusOffline):
|
||||
if online != False:
|
||||
online = False
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
||||
elif last_offline != contact.status.was_online:
|
||||
if last_offline is not None:
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline after being online for short time.')
|
||||
else:
|
||||
if isinstance(contact.status, UserStatusOffline):
|
||||
if online != False:
|
||||
online = False
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.', file=dataFile)
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
||||
last_offline = contact.status.was_online
|
||||
elif isinstance(contact.status, UserStatusOnline):
|
||||
if online != True:
|
||||
online = True
|
||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went online.')
|
||||
else:
|
||||
if online != False:
|
||||
online = False
|
||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went offline.')
|
||||
last_offline = None
|
||||
sleep(15)
|
||||
elif last_offline != contact.status.was_online:
|
||||
if last_offline is not None:
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline after being online for short time.', file=dataFile)
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline after being online for short time.')
|
||||
else:
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.', file=dataFile)
|
||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
||||
last_offline = contact.status.was_online
|
||||
elif isinstance(contact.status, UserStatusOnline):
|
||||
if online != True:
|
||||
online = True
|
||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went online.', file=dataFile)
|
||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went online.')
|
||||
else:
|
||||
if online != False:
|
||||
online = False
|
||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went offline.', file=dataFile)
|
||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went offline.')
|
||||
last_offline = None
|
||||
sleep(15)
|
||||
finally:
|
||||
dataFile.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue