Skip to content

Commit

Permalink
Merge Dev into Master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tizzu committed Mar 20, 2020
2 parents a0b3b1f + b865e67 commit 65c1989
Show file tree
Hide file tree
Showing 15 changed files with 1,526 additions and 438 deletions.
Binary file removed assets/CHECK_INTERNET_CONNECTION.png
Binary file not shown.
Binary file removed assets/DAY_SEPARATOR.png
Binary file not shown.
Binary file removed assets/DURING_PHONE_CALL.png
Binary file not shown.
Binary file removed assets/DURING_PHONE_CALL_CENTERED.png
Binary file not shown.
Binary file removed assets/GENERIC_SMS.png
Binary file not shown.
Binary file removed assets/NO_EVENTS.png
Binary file not shown.
Binary file removed assets/RESULT_DELETED.png
Binary file not shown.
Binary file modified assets/RESULT_DISMISSED.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/RESULT_MUTE.png
Binary file not shown.
Binary file removed assets/RESULT_SENT.png
Binary file not shown.
Binary file removed assets/WATCH_DISCONNECTED.png
Binary file not shown.
81 changes: 50 additions & 31 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def randomString(stringLength=20):


# Populate the fields inside the JSON and send it to the server
def sendToTimeline(title, subtitle, body, time, icon):
def sendToTimeline(title, subtitle, body, time, icon, duration=-1):
# Uncomment if feature is implemented - Pin editing
# if pinID == "":
pinID = randomString()
pinID = "RMPC-" + randomString()
# Uncomment if feature is implemented - Pin editing
# else : pinID = oldPin

Expand All @@ -34,18 +34,22 @@ def sendToTimeline(title, subtitle, body, time, icon):
'X-User-Token': token}
# This variable will become a JSON string, ready to be sent to the servers
# the "time" field is built like this since it gives the local time with timezone 0 (instead of +01:00 or similar
data = {
"id": pinID,
"time": str(time.date().year()) + "-" + leadingZero(time.date().month()) + "-" + leadingZero(
time.date().day()) + "T" + leadingZero(time.time().hour()) + ":" + leadingZero(time.time().minute()) + ":00Z",
"layout": {
"type": "genericPin",
"title": title,
"subtitle": subtitle,
"body": body,
"tinyIcon": "system://images/" + icon
}
}
data = {}
data["id"] = pinID
data["time"] = str(time.date().year()) + "-" + leadingZero(time.date().month()) + "-" + leadingZero(
time.date().day()) + "T" + leadingZero(time.time().hour()) + ":" + leadingZero(time.time().minute()) + ":00Z"
layout = {}
if duration != -1:
data["duration"] = duration
layout["type"] = "calendarPin"
else:
layout["type"] = "genericPin"
layout["title"] = title
layout["subtitle"] = subtitle
layout["body"] = body
layout["tinyIcon"] = "system://images/" + icon

data["layout"] = layout
response = requests.put(url, data=json.dumps(data), headers=header)
if response.status_code == 200:
alert = QMessageBox()
Expand All @@ -57,11 +61,23 @@ def sendToTimeline(title, subtitle, body, time, icon):
print(response)
alert = QMessageBox()
alert.setWindowTitle('Rebble Memos')
alert.setText('Something went wrong, Try again. \n Error code:' + str(response.status_code))
reason = ""
if response.status_code == 400:
reason = "INVALID_JSON"
elif response.status_code == 403:
reason = "INVALID_API_KEY"
elif response.status_code == 410:
reason = "INVALID_USER_TOKEN"
elif response.status_code == 429:
reason = "RATE_LIMIT_EXCEEDED"
elif response.status_code == 500:
reason = "SERVICE_UNAVAILABLE"
alert.setText('Something went wrong, Try again. \n Error: ' + reason)
alert.exec_()


# Since I didn't find anything about adding a leading zero via library functions/parameters I've made a quick number
#to String converted where needed (Hours, Minutes, Days, Months)
# to String converted where needed (Hours, Minutes, Days, Months)
def leadingZero(number):
if 0 <= number <= 9:
return "0" + str(number)
Expand All @@ -72,25 +88,28 @@ def leadingZero(number):
# If you need to test your pin data without bothering the servers you can substitute sendToTimeline() inside memos.py with
# test(), so whe you click on the "Send to Timeline" button a dialog box will appear with the data submitted
# This function will also generate a JSON string in the terminal, so you can test the pin on an emulator
def test(title, subtitle, body, time, icon):
data2 = {
"id": "pinID",
"time": "" + str(time.date().year()) + "-" + leadingZero(time.date().month()) + "-" + leadingZero(
time.date().day()) + "T" + leadingZero(time.time().hour()) + ":" + leadingZero(
time.time().minute()) + ":00Z",
"layout": {
"type": "genericPin",
"title": title,
"subtitle": subtitle,
"body": body,
"tinyIcon": "system://images/" + icon
}
}
def test(title, subtitle, body, time, icon, duration=-1):
data2 = {}
data2["id"] = pinID
data2["time"] = "" + str(time.date().year()) + "-" + leadingZero(time.date().month()) + "-" + leadingZero(
time.date().day()) + "T" + leadingZero(time.time().hour()) + ":" + leadingZero(time.time().minute()) + ":00Z"
layout = {}
if duration != -1:
data2["duration"] = duration
layout["type"] = "calendarPin"
else:
layout["type"] = "genericPin"
layout["title"] = title
layout["subtitle"] = subtitle
layout["body"] = body
layout["tinyIcon"] = "system://images/" + icon

data2["layout"] = layout
print(json.dumps(data2))
alert = QMessageBox()
alert.setWindowTitle('Rebble Memos')
alert.setText("Title: " + title + "\nSubtitle: " + subtitle + "\nBody: " + body + "\nTime/Date: " + str(
time.date().year()) + "-" + leadingZero(time.date().month()) + "-" + leadingZero(
time.date().day()) + "T" + leadingZero(time.time().hour()) + ":" + leadingZero(
time.time().minute()) + ":00Z" + "\nIcon: " + icon)
time.time().minute()) + ":00Z" + "\nIcon: " + icon + "\nDuration: " + str(duration))
alert.exec_()

0 comments on commit 65c1989

Please sign in to comment.