opentechcalendartools 0.1.1__tar.gz → 0.2.0__tar.gz
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.
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/PKG-INFO +2 -1
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools/cli.py +11 -2
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools/worker.py +30 -3
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools.egg-info/PKG-INFO +2 -1
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools.egg-info/requires.txt +1 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/setup.py +2 -1
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/LICENSE +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/README.md +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools/__init__.py +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools/__main__.py +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools.egg-info/SOURCES.txt +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools.egg-info/dependency_links.txt +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools.egg-info/top_level.txt +0 -0
- {opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opentechcalendartools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Home-page: https://github.com/TeacakeTech/opentechcalendar-tools
|
|
5
5
|
Author: Teacake Tech
|
|
6
6
|
Author-email: hello@teacaketech.scot
|
|
@@ -11,6 +11,7 @@ Requires-Python: >=3.12
|
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: datatig
|
|
13
13
|
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: requests-cache
|
|
14
15
|
Requires-Dist: icalendar
|
|
15
16
|
Requires-Dist: pyyaml
|
|
16
17
|
Provides-Extra: dev
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
|
+
import requests_cache
|
|
5
|
+
|
|
4
6
|
from .worker import Worker
|
|
5
7
|
|
|
6
8
|
|
|
@@ -28,13 +30,20 @@ def main():
|
|
|
28
30
|
|
|
29
31
|
args = parser.parse_args()
|
|
30
32
|
|
|
33
|
+
requests_session = None
|
|
34
|
+
requests_cache_directory = os.getenv(
|
|
35
|
+
"OPEN_TECH_CALENDAR_TOOLS_REQUEST_CACHE_DIRECTORY",
|
|
36
|
+
)
|
|
37
|
+
if requests_cache_directory:
|
|
38
|
+
requests_session = requests_cache.install_cache(requests_cache_directory)
|
|
39
|
+
|
|
40
|
+
worker = Worker(sqlite_database_filename, requests_session=requests_session)
|
|
41
|
+
|
|
31
42
|
if args.subparser_name == "listgroupstoimport":
|
|
32
43
|
# List groups to import
|
|
33
|
-
worker = Worker(sqlite_database_filename)
|
|
34
44
|
for group_id in worker.get_group_ids_to_import():
|
|
35
45
|
print(group_id)
|
|
36
46
|
|
|
37
47
|
elif args.subparser_name == "importgroup":
|
|
38
48
|
# Import Group
|
|
39
|
-
worker = Worker(sqlite_database_filename)
|
|
40
49
|
worker.import_group(args.group_id)
|
|
@@ -11,9 +11,14 @@ import yaml
|
|
|
11
11
|
|
|
12
12
|
class Worker:
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
WORKER_USER_AGENT = (
|
|
15
|
+
"Open Tech Calendar Tools https://opentechcalendar.co.uk/contact"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def __init__(self, sqlite_database_filename, requests_session=None):
|
|
15
19
|
self._sqlite_database_filename = sqlite_database_filename
|
|
16
20
|
self._data_dir = os.getcwd()
|
|
21
|
+
self._requests_session = requests_session or requests.Session()
|
|
17
22
|
|
|
18
23
|
def get_group_ids_to_import(self) -> list:
|
|
19
24
|
with sqlite3.connect(self._sqlite_database_filename) as connection:
|
|
@@ -35,7 +40,10 @@ class Worker:
|
|
|
35
40
|
)
|
|
36
41
|
|
|
37
42
|
def _download_file_to_temp(self, url) -> str:
|
|
38
|
-
r =
|
|
43
|
+
r = self._requests_session.get(
|
|
44
|
+
url,
|
|
45
|
+
headers={"User-Agent": Worker.WORKER_USER_AGENT},
|
|
46
|
+
)
|
|
39
47
|
r.raise_for_status()
|
|
40
48
|
new_filename_dets = tempfile.mkstemp(
|
|
41
49
|
suffix="opentechcalendartools_",
|
|
@@ -44,6 +52,20 @@ class Worker:
|
|
|
44
52
|
os.close(new_filename_dets[0])
|
|
45
53
|
return new_filename_dets[1]
|
|
46
54
|
|
|
55
|
+
def _should_import_event(
|
|
56
|
+
self, group: dict, title: str, description: str, end: datetime.datetime
|
|
57
|
+
) -> bool:
|
|
58
|
+
if end.timestamp() < datetime.datetime.now().timestamp():
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
if group["field_import_exclude"] and (
|
|
62
|
+
group["field_import_exclude"] in title
|
|
63
|
+
or group["field_import_exclude"] in description
|
|
64
|
+
):
|
|
65
|
+
return False
|
|
66
|
+
|
|
67
|
+
return True
|
|
68
|
+
|
|
47
69
|
def _import_group_type_ical(self, group, ical_filename):
|
|
48
70
|
os.makedirs(os.path.join(self._data_dir, "event", group["id"]), exist_ok=True)
|
|
49
71
|
with open(ical_filename) as fp:
|
|
@@ -84,7 +106,12 @@ class Worker:
|
|
|
84
106
|
raise Exception(
|
|
85
107
|
"End not in the format we expect {}".format(end_datetime)
|
|
86
108
|
)
|
|
87
|
-
if
|
|
109
|
+
if self._should_import_event(
|
|
110
|
+
group,
|
|
111
|
+
str(event.get("SUMMARY")),
|
|
112
|
+
str(event.get("DESCRIPTION")),
|
|
113
|
+
end_datetime,
|
|
114
|
+
):
|
|
88
115
|
# Create event data with various fields
|
|
89
116
|
event_data = {
|
|
90
117
|
"title": str(event.get("SUMMARY")),
|
{opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opentechcalendartools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Home-page: https://github.com/TeacakeTech/opentechcalendar-tools
|
|
5
5
|
Author: Teacake Tech
|
|
6
6
|
Author-email: hello@teacaketech.scot
|
|
@@ -11,6 +11,7 @@ Requires-Python: >=3.12
|
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: datatig
|
|
13
13
|
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: requests-cache
|
|
14
15
|
Requires-Dist: icalendar
|
|
15
16
|
Requires-Dist: pyyaml
|
|
16
17
|
Provides-Extra: dev
|
|
@@ -2,7 +2,7 @@ import setuptools
|
|
|
2
2
|
|
|
3
3
|
setuptools.setup(
|
|
4
4
|
name="opentechcalendartools",
|
|
5
|
-
version="0.
|
|
5
|
+
version="0.2.0",
|
|
6
6
|
description="",
|
|
7
7
|
url="https://github.com/TeacakeTech/opentechcalendar-tools",
|
|
8
8
|
project_urls={
|
|
@@ -16,6 +16,7 @@ setuptools.setup(
|
|
|
16
16
|
install_requires=[
|
|
17
17
|
"datatig",
|
|
18
18
|
"requests",
|
|
19
|
+
"requests-cache",
|
|
19
20
|
"icalendar",
|
|
20
21
|
"pyyaml",
|
|
21
22
|
],
|
|
File without changes
|
|
File without changes
|
{opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools/__init__.py
RENAMED
|
File without changes
|
{opentechcalendartools-0.1.1 → opentechcalendartools-0.2.0}/opentechcalendartools/__main__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|