Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion servercom/implementations/circuitpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,16 @@ def post(self, point: DataPoint) -> bool:
'/data',
point.dumps(),
content_type = 'application/json',
headers=['User-Agent: Dude']
headers=['User-Agent: CircuitPython, dude!']
).code == 201

def email(self, msg: Email) -> bool:
return self.request(
'POST',
'/email',
msg.dumps(),
content_type = 'application/json',
headers=['User-Agent: CircuitPython, dude!']
).code == 201

def __exit__(self):
Expand Down
17 changes: 16 additions & 1 deletion servercom/implementations/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pass

from collections import namedtuple

from json import dumps

# Constants:
DEGREE_SIGN = u"\xb0"
Expand Down Expand Up @@ -44,3 +44,18 @@ class ConnectionConfig:
API_PORT: int = 8081

CUBESERVER_DEFAULT_CONFIG = ConnectionConfig()

class Email:
"""Holds an email to be sent to the team"""

def __init__(self, subject, message) -> None:
self.subject = subject
self.message = message

def dumps(self) -> str:
return dumps(
{
'subject': self.subject,
'message': self.message
}
)
11 changes: 9 additions & 2 deletions servercom/implementations/cpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,16 @@ def post(self, point: DataPoint) -> bool:
'/data',
point.dumps(),
content_type = 'application/json',
headers=['User-Agent: Dude']
headers=['User-Agent: CPython, dude!']
).code == 201
def email(self, msg: Email) -> bool:
return self.request(
'POST',
'/email',
msg.dumps(),
content_type = 'application/json',
headers=['User-Agent: CPython, dude!']
).code == 201

def __exit__(self):
if self.v:
print("Closing the server connection-")
Expand Down