Compare commits
No commits in common. "main" and "97a160ae40ce16613230e42b084040018896f5a4" have entirely different histories.
main
...
97a160ae40
|
@ -1,5 +0,0 @@
|
||||||
export MAIL_SERVER=mail.gandi.net
|
|
||||||
export MAIL_USER=helo@autonomic.zone
|
|
||||||
export MAIL_PASSWORD=$(pass autonomic/logins/helo@autonomic.zone/password)
|
|
||||||
|
|
||||||
export ROCKETCHAT_HOOK_URL=<fill in from rocketchat admin>
|
|
|
@ -2,12 +2,4 @@
|
||||||
|
|
||||||
Check email (IMAP) and boop snoots (Rocketchat).
|
Check email (IMAP) and boop snoots (Rocketchat).
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
```
|
|
||||||
git clone ssh://git@git.autonomic.zone:2222/3wordchant/mailboop.git
|
|
||||||
pip install -r requirements-dev.txt
|
|
||||||
cp .envrc.sample .envrc
|
|
||||||
envrc allow
|
|
||||||
python -m mailboop
|
|
||||||
```
|
|
||||||
|
|
|
@ -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,44 +21,41 @@ 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(
|
r = requests.post(os.getenv("ROCKETCHAT_HOOK_URL"), json={
|
||||||
os.getenv("ROCKETCHAT_HOOK_URL"),
|
"alias": "mailboop",
|
||||||
json={
|
"emoji": ":snake:",
|
||||||
"alias": "mailboop",
|
"text": output,
|
||||||
"emoji": ":snake:",
|
# "attachments": [{
|
||||||
"text": output,
|
# "title": "Rocket.Chat",
|
||||||
# "attachments": [{
|
# "title_link": "https://rocket.chat",
|
||||||
# "title": "Rocket.Chat",
|
# "text": output,
|
||||||
# "title_link": "https://rocket.chat",
|
# # "image_url": "/images/integration-attachment-example.png",
|
||||||
# "text": output,
|
# "color": "#764FA5"
|
||||||
# # "image_url": "/images/integration-attachment-example.png",
|
# }]
|
||||||
# "color": "#764FA5"
|
})
|
||||||
# }]
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
rocketchat-API==1.16.0
|
||||||
imap-tools==0.45.0
|
imap-tools==0.45.0
|
||||||
requests==2.26.0
|
|
||||||
|
|
Reference in New Issue