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
|
/settings/keys.py
|
||||||
/tracker.session
|
/tracker.session
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
trackerLogs.txt
|
||||||
|
|
|
@ -11,6 +11,7 @@ Example output:
|
||||||
=2018-01-19 @ 01:46:39: User went offline after being online for short time.
|
=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.
|
= 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
|
How to run
|
||||||
----------
|
----------
|
||||||
|
|
|
@ -46,33 +46,45 @@ contact_id = argv[1]
|
||||||
client = TelegramClient('tracker', API_ID, API_HASH)
|
client = TelegramClient('tracker', API_ID, API_HASH)
|
||||||
client.start()
|
client.start()
|
||||||
|
|
||||||
|
# File IO
|
||||||
|
dataFile = open('shuTimes.txt', 'a+')
|
||||||
|
|
||||||
online = None
|
online = None
|
||||||
last_offline = None
|
last_offline = None
|
||||||
while True:
|
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'):
|
# Workaround for the regression in Telethon that breaks get_entity('me'):
|
||||||
# https://github.com/LonamiWebs/Telethon/issues/1024
|
# https://github.com/LonamiWebs/Telethon/issues/1024
|
||||||
contact = client.get_me()
|
contact = client.get_me()
|
||||||
else:
|
else:
|
||||||
contact = client.get_entity(contact_id)
|
contact = client.get_entity(contact_id)
|
||||||
|
|
||||||
if isinstance(contact.status, UserStatusOffline):
|
if isinstance(contact.status, UserStatusOffline):
|
||||||
if online != False:
|
if online != False:
|
||||||
online = False
|
online = False
|
||||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.', file=dataFile)
|
||||||
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:
|
|
||||||
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
||||||
last_offline = contact.status.was_online
|
elif last_offline != contact.status.was_online:
|
||||||
elif isinstance(contact.status, UserStatusOnline):
|
if last_offline is not None:
|
||||||
if online != True:
|
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline after being online for short time.', file=dataFile)
|
||||||
online = True
|
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline after being online for short time.')
|
||||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went online.')
|
else:
|
||||||
else:
|
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.', file=dataFile)
|
||||||
if online != False:
|
print(f'={utc2localtime(contact.status.was_online).strftime(DATETIME_FORMAT)}: User went offline.')
|
||||||
online = False
|
last_offline = contact.status.was_online
|
||||||
print(f'~{datetime.now().strftime(DATETIME_FORMAT)}: User went offline.')
|
elif isinstance(contact.status, UserStatusOnline):
|
||||||
last_offline = None
|
if online != True:
|
||||||
sleep(15)
|
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