I am trying to assign data from a TeamUp calendar to variables in python. My python knowledge is very limited.
Im using the TeamUp api and the python code...
import http.client
conn = http.client.HTTPSConnection("api.teamup.com")
headers = {
'Accept': "application/json",
'Teamup-Token': "XXXXXX"
}
conn.request("GET", "/ks88wezkvao5k8did2/events", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Using that code i then get the following printed in the console...
{'events': [{"id": "1432617207", "series_id": null, "remote_id": null, "subcalendar_id": 10797089,
"subcalendar_ids": [10797089], "all_day": true, "rrule": "", "title": "Theatre - Inc Meal", "who": "",
"location": "", "notes": "", "version": "083a706eb6f5", "readonly": true, "tz": null, "attachments": [],
"start_dt": "2023-05-08T00:00:00", "end_dt": "2023-05-08T23:59:00", "ristart_dt": null,
"rsstart_dt": null, "creation_dt": "2023-02-24T02:28:16+00:00", "update_dt": null, "delete_dt": null},
{"id": "1502070429", "series_id": null, "remote_id": null, "subcalendar_id": 10797089,
"subcalendar_ids": [10797089], "all_day": false, "rrule": "", "title": "Gavin", "who": "", "location": "",
"notes": "", "version": "0d8bf6d68f24", "readonly": false, "tz": null, "attachments": [],
"start_dt": "2023-05-08T08:30:00+01:00", "end_dt": "2023-05-08T12:30:00+01:00", "ristart_dt": null,
"rsstart_dt": null, "creation_dt": "2023-05-02T19:01:08+01:00", "update_dt": "2023-05-02T19:01:11+01:00",
"delete_dt": null}, {"id": "1501983305", "series_id": null, "remote_id": null, "subcalendar_id": 10797089,
"subcalendar_ids": [10797089], "all_day": false, "rrule": "",
"title": "Findley Close", "who": "", "location": "Findlay Cl Gillingham ME8 9HA",
"notes": "", "version": "a081d79a6812", "readonly": false, "tz": "Europe\/London",
"attachments": [], "start_dt": "2023-05-08T13:00:00+01:00",
"end_dt": "2023-05-08T14:00:00+01:00", "ristart_dt": null, "rsstart_dt": null,
"creation_dt": "2023-05-02T17:24:19+01:00", "update_dt": "2023-05-02T19:00:57+01:00",
"delete_dt": null},
{"id": "1501983352", "series_id": null, "remote_id": null, "subcalendar_id": 10797089,
"subcalendar_ids": [10797089], "all_day": false, "rrule": "", "title": "Gregory Close", "who": "",
"location": "Gregory Cl Gillingham ME8 9LJ", "notes": "", "version": "b2e45e9e88dd", "readonly": false,
"tz": "Europe\/London", "attachments": [], "start_dt": "2023-05-08T14:30:00+01:00",
"end_dt": "2023-05-08T15:30:00+01:00", "ristart_dt": null, "rsstart_dt": null,
"creation_dt": "2023-05-02T17:24:22+01:00", "update_dt": "2023-05-02T19:00:54+01:00", "delete_dt": null},
{"id": "1501983372", "series_id": null, "remote_id": null, "subcalendar_id": 10797089,
"subcalendar_ids": [10797089], "all_day": false, "rrule": "", "title": "Ferrier Close", "who": "",
"location": "Ferrier Cl Gillingham ME8 9JL", "notes": "", "version": "18fc1637e29e", "readonly": false,
"tz": "Europe\/London", "attachments": [], "start_dt": "2023-05-08T15:30:00+01:00",
"end_dt": "2023-05-08T16:30:00+01:00", "ristart_dt": null, "rsstart_dt": null,
"creation_dt": "2023-05-02T17:24:25+01:00", "update_dt": "2023-05-02T19:00:51+01:00", "delete_dt": null},
{"id": "1496199581", "series_id": null, "remote_id": null, "subcalendar_id": 10797089,
"subcalendar_ids": [10797089], "all_day": false, "rrule": "", "title": "Lottie Prudence", "who": "",
"location": "William Street", "notes": "", "version": "aa118772e8e5", "readonly": false,
"tz": "Europe\/London", "attachments": [], "start_dt": "2023-05-08T17:00:00+01:00",
"end_dt": "2023-05-08T18:00:00+01:00", "ristart_dt": null, "rsstart_dt": null,
"creation_dt": "2023-04-26T21:19:00+01:00", "update_dt": "2023-05-04T02:06:27+01:00", "delete_dt": null}],
'timestamp': 1683509960}
How can i assign the title
, start_dt
, end_dt
to variables.
I have tried to use the pyTeamUp package but wasnt able to figure out how to get the data. What i would like to be able to do is display a list of the calendar items for each sub calendar in an app built using kivy. Once i can store the data in variables, i can use it in kivy
Try this solution:
import http.client
import json
from datetime import datetime
conn = http.client.HTTPSConnection("api.teamup.com")
headers = {
'Accept': "application/json",
'Teamup-Token': "XXXXXX"
}
conn.request("GET", "/ks88wezkvao5k8did2/events", headers=headers)
res = conn.getresponse()
data = res.read()
response_dict = json.loads(data)
for event in response_dict.get("events", []):
title = event['title']
start = event['start_dt']
end = event['end_dt']
# Convert 08-05-2023 18:00:00 format
start_dt = datetime.fromisoformat(start).strftime("%d-%m-%Y %H:%M:%S")
end_dt = datetime.fromisoformat(end).strftime("%d-%m-%Y %H:%M:%S")
# Print the event information
print(f"Title: {title}, Start Date: {start_dt}, End Date: {end_dt}")