Black formatter

This commit is contained in:
3wc 2021-08-11 13:41:31 +02:00
parent 90da68359a
commit 4055530baf
1 changed files with 21 additions and 18 deletions

View File

@ -10,9 +10,9 @@ import requests
def main(): def main():
print("connecting to imap server") print("connecting to imap server")
mb = MailBox(os.getenv("MAIL_SERVER"), 993).login( mb = MailBox(os.getenv("MAIL_SERVER"), 993).login(
os.getenv("MAIL_USER"), os.getenv("MAIL_PASSWORD") os.getenv("MAIL_USER"), os.getenv("MAIL_PASSWORD")
) )
# Fetch all emails # Fetch all emails
# Don't mark them as seen # Don't mark them as seen
# Set bulk=True to read them all into memory in one fetch # Set bulk=True to read them all into memory in one fetch
# (as opposed to in streaming which is slower but uses less memory) # (as opposed to in streaming which is slower but uses less memory)
@ -21,41 +21,44 @@ def main():
messages = list(message_reader) messages = list(message_reader)
unread = list(filter(lambda x: '\\Seen' not in x.flags, messages)) unread = list(filter(lambda x: "\\Seen" not in x.flags, messages))
dates = [m.date.replace(tzinfo=None) for m in messages] dates = [m.date.replace(tzinfo=None) for m in messages]
median_date = sorted(dates)[len(dates) // 2] median_date = sorted(dates)[len(dates) // 2]
median_delta = datetime.now() - median_date median_delta = datetime.now() - median_date
oldest_date = sorted(dates)[0] oldest_date = sorted(dates)[0]
oldest_delta = datetime.now() - oldest_date oldest_delta = datetime.now() - oldest_date
count = len(dates) count = len(dates)
count_unread = len(unread) count_unread = len(unread)
output = f'''\ output = f"""\
booping ur snoots :point_right: booping ur snoots :point_right:
total emails: **{count}** total emails: **{count}**
unread: **{count_unread}** unread: **{count_unread}**
median email: recevied **{median_date}**, {median_delta} ago median email: recevied **{median_date}**, {median_delta} ago
oldest email: recevied **{oldest_date}**, {oldest_delta} ago oldest email: recevied **{oldest_date}**, {oldest_delta} ago
''' """
print("sendin boops") print("sendin boops")
r = requests.post(os.getenv("ROCKETCHAT_HOOK_URL"), json={ r = requests.post(
"alias": "mailboop", os.getenv("ROCKETCHAT_HOOK_URL"),
"emoji": ":snake:", json={
"text": output, "alias": "mailboop",
# "attachments": [{ "emoji": ":snake:",
# "title": "Rocket.Chat", "text": output,
# "title_link": "https://rocket.chat", # "attachments": [{
# "text": output, # "title": "Rocket.Chat",
# # "image_url": "/images/integration-attachment-example.png", # "title_link": "https://rocket.chat",
# "color": "#764FA5" # "text": output,
# }] # # "image_url": "/images/integration-attachment-example.png",
}) # "color": "#764FA5"
# }]
},
)
if __name__ == "__main__": if __name__ == "__main__":