send boops
This commit is contained in:
parent
652cf38ffe
commit
97a160ae40
@ -1,13 +1,13 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from imap_tools import MailBox
|
from imap_tools import MailBox
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Server is the address of the imap server
|
|
||||||
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")
|
||||||
@ -17,22 +17,45 @@ def main():
|
|||||||
# 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)
|
||||||
print("downloading mailz")
|
print("downloading mailz")
|
||||||
messages = mb.fetch(limit=10, mark_seen=False,
|
message_reader = mb.fetch(mark_seen=False, bulk=True)
|
||||||
bulk=True)
|
|
||||||
|
|
||||||
dates = [m.date for m in messages]
|
messages = list(message_reader)
|
||||||
|
|
||||||
|
unread = list(filter(lambda x: '\\Seen' not in x.flags, 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.replace(tzinfo=None)
|
median_delta = datetime.now() - median_date
|
||||||
|
|
||||||
oldest_date = sorted(dates)[0]
|
oldest_date = sorted(dates)[0]
|
||||||
oldest_delta = datetime.now() - oldest_date.replace(tzinfo=None)
|
oldest_delta = datetime.now() - oldest_date
|
||||||
|
|
||||||
print(f"Median email: recevied {median_date}, {median_delta} ago")
|
count = len(dates)
|
||||||
|
count_unread = len(unread)
|
||||||
|
|
||||||
print(f"Oldest email: recevied {oldest_date}, {oldest_delta} ago")
|
output = f'''\
|
||||||
|
booping ur snoots :point_right:
|
||||||
|
|
||||||
from pdb import set_trace; set_trace()
|
total emails: **{count}**
|
||||||
|
unread: **{count_unread}**
|
||||||
|
median email: recevied **{median_date}**, {median_delta} ago
|
||||||
|
oldest email: recevied **{oldest_date}**, {oldest_delta} ago
|
||||||
|
'''
|
||||||
|
|
||||||
|
print("sendin boops")
|
||||||
|
r = requests.post(os.getenv("ROCKETCHAT_HOOK_URL"), json={
|
||||||
|
"alias": "mailboop",
|
||||||
|
"emoji": ":snake:",
|
||||||
|
"text": output,
|
||||||
|
# "attachments": [{
|
||||||
|
# "title": "Rocket.Chat",
|
||||||
|
# "title_link": "https://rocket.chat",
|
||||||
|
# "text": output,
|
||||||
|
# # "image_url": "/images/integration-attachment-example.png",
|
||||||
|
# "color": "#764FA5"
|
||||||
|
# }]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user