opentechcalendartools 0.0.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import datetime
2
2
  import os
3
3
  import sqlite3
4
4
  import tempfile
5
+ import zoneinfo
5
6
 
6
7
  import icalendar
7
8
  import requests
@@ -29,10 +30,8 @@ class Worker:
29
30
  group = res.fetchone()
30
31
  if group["field_import_type"] == "ical":
31
32
  self._import_group_type_ical(
32
- group_id,
33
+ group,
33
34
  self._download_file_to_temp(group["field_import_url"]),
34
- group_country=group["field_country"],
35
- group_place=group["field_place"],
36
35
  )
37
36
 
38
37
  def _download_file_to_temp(self, url) -> str:
@@ -45,35 +44,122 @@ class Worker:
45
44
  os.close(new_filename_dets[0])
46
45
  return new_filename_dets[1]
47
46
 
48
- def _import_group_type_ical(
49
- self, group_id, ical_filename, group_country=None, group_place=None
50
- ):
51
- os.makedirs(os.path.join(self._data_dir, "event", group_id), exist_ok=True)
47
+ def _import_group_type_ical(self, group, ical_filename):
48
+ os.makedirs(os.path.join(self._data_dir, "event", group["id"]), exist_ok=True)
52
49
  with open(ical_filename) as fp:
53
50
  calendar = icalendar.Calendar.from_ical(fp.read())
54
51
  for event in calendar.events:
55
- start = event.get("DTSTART")
56
- end = event.get("DTEND")
57
- if end.dt.timestamp() > datetime.datetime.now().timestamp():
52
+ timezone_name = group["field_timezone"] or "UTC"
53
+ start_datetime = event.get("DTSTART").dt
54
+ end_datetime = event.get("DTEND").dt
55
+ if isinstance(start_datetime, datetime.datetime):
56
+ pass
57
+ elif isinstance(start_datetime, datetime.date):
58
+ start_datetime = datetime.datetime(
59
+ start_datetime.year,
60
+ start_datetime.month,
61
+ start_datetime.day,
62
+ 0,
63
+ 0,
64
+ 0,
65
+ tzinfo=zoneinfo.ZoneInfo(timezone_name),
66
+ )
67
+ else:
68
+ raise Exception(
69
+ "Start not in the format we expect {}".format(start_datetime)
70
+ )
71
+ if isinstance(end_datetime, datetime.datetime):
72
+ pass
73
+ elif isinstance(end_datetime, datetime.date):
74
+ end_datetime = datetime.datetime(
75
+ end_datetime.year,
76
+ end_datetime.month,
77
+ end_datetime.day,
78
+ 23,
79
+ 59,
80
+ 59,
81
+ tzinfo=zoneinfo.ZoneInfo(timezone_name),
82
+ )
83
+ else:
84
+ raise Exception(
85
+ "End not in the format we expect {}".format(end_datetime)
86
+ )
87
+ if end_datetime.timestamp() > datetime.datetime.now().timestamp():
88
+ # Create event data with various fields
58
89
  event_data = {
59
90
  "title": str(event.get("SUMMARY")),
60
- "group": group_id,
61
- "start_at": str(start.dt),
62
- "end_at": str(end.dt),
91
+ "group": group["id"],
92
+ "timezone": timezone_name,
93
+ "start_at": str(start_datetime),
94
+ "end_at": str(end_datetime),
63
95
  "url": str(event.get("URL")),
64
96
  "cancelled": (event.get("STATUS") == "CANCELLED"),
65
97
  "imported": True,
98
+ "community_participation": {
99
+ "at_event": "unknown",
100
+ "at_event_audience_text": "unknown",
101
+ "at_event_audience_audio": "unknown",
102
+ },
103
+ "in_person": "unknown",
66
104
  }
67
- if group_country:
68
- event_data["country"] = group_country
69
- if group_place:
70
- event_data["place"] = group_place
105
+ if group["field_country"]:
106
+ event_data["country"] = group["field_country"]
107
+ if group["field_place"]:
108
+ event_data["place"] = group["field_place"]
109
+ if group["field_code_of_conduct_url"]:
110
+ event_data["code_of_conduct_url"] = group[
111
+ "field_code_of_conduct_url"
112
+ ]
113
+ # In-person events
114
+ if group["field_in_person"] == "all":
115
+ event_data["in_person"] = "yes"
116
+ elif group["field_in_person"] == "none":
117
+ event_data["in_person"] = "no"
118
+ # Community Participation: Interact with event?
119
+ if group["field_community_participation_at_event"] == "all":
120
+ event_data["community_participation"]["at_event"] = "yes"
121
+ elif group["field_community_participation_at_event"] == "none":
122
+ event_data["community_participation"]["at_event"] = "no"
123
+ # Community Participation: Interact with other audience members at the event via text?
124
+ if (
125
+ group["field_community_participation_at_event_audience_text"]
126
+ == "all"
127
+ ):
128
+ event_data["community_participation"][
129
+ "at_event_audience_text"
130
+ ] = "yes"
131
+ elif (
132
+ group["field_community_participation_at_event_audience_text"]
133
+ == "none"
134
+ ):
135
+ event_data["community_participation"][
136
+ "at_event_audience_text"
137
+ ] = "no"
138
+ # Community Participation: Interact with other audience members at the event via audio?
139
+ if (
140
+ group["field_community_participation_at_event_audience_audio"]
141
+ == "all"
142
+ ):
143
+ event_data["community_participation"][
144
+ "at_event_audience_audio"
145
+ ] = "yes"
146
+ elif (
147
+ group["field_community_participation_at_event_audience_audio"]
148
+ == "none"
149
+ ):
150
+ event_data["community_participation"][
151
+ "at_event_audience_audio"
152
+ ] = "no"
153
+ # Id
71
154
  id = event.get("UID").split("@").pop(0)
155
+ # filename
72
156
  filename = os.path.join(
73
- self._data_dir, "event", group_id, id + ".md"
157
+ self._data_dir, "event", group["id"], id + ".md"
74
158
  )
159
+ # Finally write data
75
160
  with open(filename, "w") as fp:
76
161
  fp.write("---\n")
77
162
  fp.write(yaml.dump(event_data))
78
163
  fp.write("---\n\n\n")
79
164
  fp.write(event.get("DESCRIPTION"))
165
+ fp.write("\n")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opentechcalendartools
3
- Version: 0.0.0
3
+ Version: 0.1.1
4
4
  Home-page: https://github.com/TeacakeTech/opentechcalendar-tools
5
5
  Author: Teacake Tech
6
6
  Author-email: hello@teacaketech.scot
@@ -0,0 +1,9 @@
1
+ opentechcalendartools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ opentechcalendartools/__main__.py,sha256=k62u01s2PYzYpErY7unEc49JsxnOohcSOG_Gu9pFuYA,98
3
+ opentechcalendartools/cli.py,sha256=fR5XhuniYb15hOGzYmCHc2ORRxbhiB9KOEUZNtkiIx8,1201
4
+ opentechcalendartools/worker.py,sha256=W_rJCgwZXJeGx2HsjCROEfqDWRQDRjmmVQlVtRphoLM,7483
5
+ opentechcalendartools-0.1.1.dist-info/licenses/LICENSE,sha256=t3-svmFJHEV_slEWg4lRY-LK523IOA56WXz62uOzGFI,1499
6
+ opentechcalendartools-0.1.1.dist-info/METADATA,sha256=ugHs_NLZ8srvRPVZSX4yXwvS7ULOobm0DQRALw4WWYQ,881
7
+ opentechcalendartools-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ opentechcalendartools-0.1.1.dist-info/top_level.txt,sha256=cXAUphHY7mCrtEnq3V6i_QyeWcbBEM75SJYjrUtDZ8E,22
9
+ opentechcalendartools-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,9 +0,0 @@
1
- opentechcalendartools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- opentechcalendartools/__main__.py,sha256=k62u01s2PYzYpErY7unEc49JsxnOohcSOG_Gu9pFuYA,98
3
- opentechcalendartools/cli.py,sha256=fR5XhuniYb15hOGzYmCHc2ORRxbhiB9KOEUZNtkiIx8,1201
4
- opentechcalendartools/worker.py,sha256=0MD6QVW5BaXFX4aL6M7gf6VG2LuqBrzwa3QZuP076Lc,3215
5
- opentechcalendartools-0.0.0.dist-info/licenses/LICENSE,sha256=t3-svmFJHEV_slEWg4lRY-LK523IOA56WXz62uOzGFI,1499
6
- opentechcalendartools-0.0.0.dist-info/METADATA,sha256=iJ-pfMuATfpKCK1Vd0kydMPWN_Rk8OaE5U0-pBsG5Zs,881
7
- opentechcalendartools-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- opentechcalendartools-0.0.0.dist-info/top_level.txt,sha256=cXAUphHY7mCrtEnq3V6i_QyeWcbBEM75SJYjrUtDZ8E,22
9
- opentechcalendartools-0.0.0.dist-info/RECORD,,