Add timestamps to message output
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a6ccb45f83
commit
11a777cb76
43
slackmail.py
43
slackmail.py
|
@ -3,6 +3,7 @@
|
|||
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from urllib import request
|
||||
|
||||
|
||||
|
@ -46,36 +47,40 @@ if call_method_auth("auth.test")["ok"] == False:
|
|||
|
||||
def list_channel_ids():
|
||||
call = call_method_auth("channels.list")
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
for channel in call["channels"]:
|
||||
yield channel["id"]
|
||||
if call["ok"] == True:
|
||||
for channel in call["channels"]:
|
||||
yield channel["id"]
|
||||
|
||||
def find_channel_info(id):
|
||||
call = call_method_auth("channels.info", { "channel" : id })
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
return call["channel"]
|
||||
if call["ok"] == True:
|
||||
return call["channel"]
|
||||
|
||||
def read_channel(id, ts):
|
||||
args = { "channel" : id, "oldest" : ts }
|
||||
call = call_method_auth("channels.history", args)
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
messages = call["messages"]
|
||||
messages.reverse()
|
||||
for message in messages:
|
||||
yield message
|
||||
if call["ok"] == True:
|
||||
messages = call["messages"]
|
||||
messages.reverse()
|
||||
for message in messages:
|
||||
yield message
|
||||
|
||||
def _print_message(user, message):
|
||||
dt = datetime.fromtimestamp(float(message["ts"]))
|
||||
text = message["text"].encode("utf-8").decode("latin-1")
|
||||
print("%s %s: %s" % (str(dt), user, text))
|
||||
|
||||
def print_message(message):
|
||||
call = call_method_auth("users.info", {"user" : message["user"]})
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
|
||||
name = "%s %s" % (call["user"]["profile"].get("first_name", ""), call["user"]["profile"].get("last_name", ""))
|
||||
text = message["text"].encode("utf-8").decode("latin-1")
|
||||
print("%s: %s" % (name, message["text"].encode("utf-8").decode("latin-1")))
|
||||
|
||||
name = message["user"]
|
||||
else:
|
||||
first = call["user"]["profile"].get("first_name", "")
|
||||
last = call["user"]["profile"].get("last_name", "")
|
||||
name = "%s %s" % (first, last)
|
||||
if first == "" and last == "":
|
||||
name = call["user"]["name"]
|
||||
_print_message(name, message)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user