commit
da6b8ad0bf
8 changed files with 162 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
[[source]] |
||||||
|
name = "pypi" |
||||||
|
url = "https://pypi.org/simple" |
||||||
|
verify_ssl = true |
||||||
|
|
||||||
|
[dev-packages] |
||||||
|
|
||||||
|
[packages] |
||||||
|
requests = "*" |
||||||
|
|
||||||
|
[requires] |
||||||
|
python_version = "3.8" |
@ -0,0 +1,57 @@ |
|||||||
|
{ |
||||||
|
"_meta": { |
||||||
|
"hash": { |
||||||
|
"sha256": "acbc8c4e7f2f98f1059b2a93d581ef43f4aa0c9741e64e6253adff8e35fbd99e" |
||||||
|
}, |
||||||
|
"pipfile-spec": 6, |
||||||
|
"requires": { |
||||||
|
"python_version": "3.8" |
||||||
|
}, |
||||||
|
"sources": [ |
||||||
|
{ |
||||||
|
"name": "pypi", |
||||||
|
"url": "https://pypi.org/simple", |
||||||
|
"verify_ssl": true |
||||||
|
} |
||||||
|
] |
||||||
|
}, |
||||||
|
"default": { |
||||||
|
"certifi": { |
||||||
|
"hashes": [ |
||||||
|
"sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3", |
||||||
|
"sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41" |
||||||
|
], |
||||||
|
"version": "==2020.6.20" |
||||||
|
}, |
||||||
|
"chardet": { |
||||||
|
"hashes": [ |
||||||
|
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", |
||||||
|
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" |
||||||
|
], |
||||||
|
"version": "==3.0.4" |
||||||
|
}, |
||||||
|
"idna": { |
||||||
|
"hashes": [ |
||||||
|
"sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6", |
||||||
|
"sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0" |
||||||
|
], |
||||||
|
"version": "==2.10" |
||||||
|
}, |
||||||
|
"requests": { |
||||||
|
"hashes": [ |
||||||
|
"sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b", |
||||||
|
"sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898" |
||||||
|
], |
||||||
|
"index": "pypi", |
||||||
|
"version": "==2.24.0" |
||||||
|
}, |
||||||
|
"urllib3": { |
||||||
|
"hashes": [ |
||||||
|
"sha256:8d7eaa5a82a1cac232164990f04874c594c9453ec55eef02eab885aa02fc17a2", |
||||||
|
"sha256:f5321fbe4bf3fefa0efd0bfe7fb14e90909eb62a48ccda331726b4319897dd5e" |
||||||
|
], |
||||||
|
"version": "==1.25.11" |
||||||
|
} |
||||||
|
}, |
||||||
|
"develop": {} |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
{ |
||||||
|
"bearer": "insert bearer token from twitter" |
||||||
|
} |
||||||
|
|
@ -0,0 +1 @@ |
|||||||
|
from .mail import mail |
@ -0,0 +1,41 @@ |
|||||||
|
from email.mime.text import MIMEText |
||||||
|
from json import load as j_load |
||||||
|
from pathlib import Path |
||||||
|
from platform import system |
||||||
|
from smtplib import SMTP_SSL, SMTPHeloError, SMTPAuthenticationError, SMTPException |
||||||
|
from ssl import create_default_context |
||||||
|
|
||||||
|
|
||||||
|
class mail: |
||||||
|
|
||||||
|
def __init__(self, what: str): |
||||||
|
|
||||||
|
if system().lower() == "windows": |
||||||
|
path = Path("mail_credentials.json") |
||||||
|
else: |
||||||
|
path = Path("/etc/twpng/mail_credentials.json") |
||||||
|
|
||||||
|
with path.open("r") as fp: |
||||||
|
credentials = j_load(fp) |
||||||
|
|
||||||
|
message = MIMEText(what, _charset='utf8') |
||||||
|
message['Subject'] = "twpng error report" |
||||||
|
message['From'] = credentials['email-sendfrom'] |
||||||
|
message['To'] = credentials['email-sendto'] |
||||||
|
|
||||||
|
try: |
||||||
|
with SMTP_SSL(host=credentials['smtp-server'], |
||||||
|
port=credentials['smtp-port'], |
||||||
|
context=create_default_context()) as server: |
||||||
|
server.login(user=credentials['email-user'], password=credentials['email-password']) |
||||||
|
server.sendmail(to_addrs=credentials['email-sendto'], |
||||||
|
msg=message.as_string(), |
||||||
|
from_addr=credentials['email-sendfrom']) |
||||||
|
|
||||||
|
except SMTPHeloError as helo: |
||||||
|
print(f"SMTPHeloError: {helo}") |
||||||
|
except SMTPAuthenticationError as auth_error: |
||||||
|
print(f"Authentication Error: {auth_error}") |
||||||
|
except SMTPException as e: |
||||||
|
print(f"SMTPException: {e}") |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
{ |
||||||
|
"smtp-server": "mail.example.com", |
||||||
|
"smtp-port": 465, |
||||||
|
"email-user": "username", |
||||||
|
"email-sendfrom": "sendingmail@example.com", |
||||||
|
"email-password": "passw0rd", |
||||||
|
"email-sendto": "receiver@example.com" |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
import requests |
||||||
|
from pathlib import Path |
||||||
|
from platform import system |
||||||
|
from json import load as j_load |
||||||
|
from mail import mail |
||||||
|
|
||||||
|
get_last_id_url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=GothSeidank&count=1&trim_user=1" |
||||||
|
# get_tweet_url = "https://api.twitter.com/2/tweets/1324994969590001666" |
||||||
|
|
||||||
|
|
||||||
|
if system().lower() == "windows": |
||||||
|
path = Path("bearer.json") |
||||||
|
else: |
||||||
|
path = Path("/etc/twpng/bearer.json") |
||||||
|
|
||||||
|
try: |
||||||
|
with path.open('r') as fp: |
||||||
|
credentials = j_load(fp) |
||||||
|
except FileNotFoundError: |
||||||
|
mail("Could not find bearer token file! Script was discontinued.") |
||||||
|
exit(1) |
||||||
|
|
||||||
|
try: |
||||||
|
header = { |
||||||
|
"Authorization": f"Bearer {credentials['bearer']}" |
||||||
|
} |
||||||
|
|
||||||
|
r = requests.get(url=get_last_id_url, headers=header) |
||||||
|
r.raise_for_status() |
||||||
|
|
||||||
|
except Exception as e: |
||||||
|
message = f"The api call to twitter failed and requests said:\n'{e}'. Script was discontinued." |
||||||
|
mail(message) |
||||||
|
exit(1) |
||||||
|
|
||||||
|
|
Loading…
Reference in new issue