Compare commits
No commits in common. "9c08687f25ee77c1af3c2249fbc333a5d174451c" and "23cd165d2d43f60cd784ed15312c2b8dfa0ddb93" have entirely different histories.
9c08687f25
...
23cd165d2d
@ -1,13 +1,9 @@
|
||||
import os
|
||||
import imaplib
|
||||
import json
|
||||
from time import strftime
|
||||
import influxdb_client
|
||||
from influxdb_client.client.write_api import SYNCHRONOUS
|
||||
from dotenv import load_dotenv, dotenv_values
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
config = dotenv_values(".env")
|
||||
|
||||
EMAIL_ACCOUNTS = json.loads(os.environ.get("MAIL_ACCOUNTS"))
|
||||
EMAIL_PASSWORDS = json.loads(os.environ.get("MAIL_PASSWORDS"))
|
||||
@ -15,14 +11,6 @@ EMAIL_PASSWORDS = json.loads(os.environ.get("MAIL_PASSWORDS"))
|
||||
# to convert lists to dictionary
|
||||
accounts = dict(zip(EMAIL_ACCOUNTS, EMAIL_PASSWORDS))
|
||||
print(accounts)
|
||||
|
||||
# Influx DB
|
||||
client = influxdb_client.InfluxDBClient(
|
||||
url=config['DB_URL'],
|
||||
token=config['DB_TOKEN'],
|
||||
org=config['DB_ORG']
|
||||
)
|
||||
|
||||
################ IMAP SSL ##############################
|
||||
|
||||
for account in accounts:
|
||||
@ -42,8 +30,8 @@ for account in accounts:
|
||||
resp_code, messages = imap_ssl.search(None, 'UnSeen')
|
||||
if resp_code == 'OK':
|
||||
if len(messages[0].split()) > 0:
|
||||
# print('True')
|
||||
# print(messages[0].split())
|
||||
#print('True')
|
||||
#print(messages[0].split())
|
||||
unread_messages = len(messages[0].split())
|
||||
else:
|
||||
print('False')
|
||||
@ -54,12 +42,4 @@ for account in accounts:
|
||||
imap_ssl.close()
|
||||
if unread_messages:
|
||||
message = f"{account} has {unread_messages} messages."
|
||||
date = strftime("%Y-%m-%d")
|
||||
time = strftime("%H:%M:%S")
|
||||
timestamp = date + "T" + time + "Z"
|
||||
write_api = client.write_api(write_options=SYNCHRONOUS)
|
||||
point = influxdb_client.Point("unread_emails").time(timestamp).tag("account", account)\
|
||||
.field("count", unread_messages)
|
||||
write_api.write(bucket="personal_data",
|
||||
org=config['DB_ORG'], record=point)
|
||||
print(message)
|
||||
|
@ -1,11 +0,0 @@
|
||||
autopep8==2.0.1
|
||||
certifi==2022.12.7
|
||||
influxdb-client==1.35.0
|
||||
pycodestyle==2.10.0
|
||||
python-dateutil==2.8.2
|
||||
python-dotenv==0.21.0
|
||||
reactivex==4.0.4
|
||||
six==1.16.0
|
||||
tomli==2.0.1
|
||||
typing_extensions==4.4.0
|
||||
urllib3==1.26.13
|
Loading…
Reference in New Issue
Block a user