Compare commits
2 commits
41d6c4be84
...
72db970265
Author | SHA1 | Date | |
---|---|---|---|
72db970265 | |||
7b671e950a |
4 changed files with 14 additions and 14 deletions
|
@ -39,7 +39,7 @@ class Source(abc.ABC):
|
||||||
limit=None,
|
limit=None,
|
||||||
) -> typing.Iterable[dict]:
|
) -> typing.Iterable[dict]:
|
||||||
until = until if until else datetime.timedelta(days=365)
|
until = until if until else datetime.timedelta(days=365)
|
||||||
now = start if start else datetime.datetime.utcnow().astimezone()
|
now = start if start else datetime.datetime.now(datetime.timezone.utc)
|
||||||
now_365 = now + until
|
now_365 = now + until
|
||||||
for e in self.get_events(
|
for e in self.get_events(
|
||||||
start=start,
|
start=start,
|
||||||
|
@ -50,17 +50,18 @@ class Source(abc.ABC):
|
||||||
yield e
|
yield e
|
||||||
continue
|
continue
|
||||||
r = e.pop('recurrence')
|
r = e.pop('recurrence')
|
||||||
|
dtstart = datetime.datetime.fromisoformat(
|
||||||
|
e['start']['dateTime']
|
||||||
|
if 'dateTime' in e['start'] else
|
||||||
|
e['start']['date']
|
||||||
|
).replace(tzinfo=datetime.timezone.utc)
|
||||||
r = dateutil.rrule.rrulestr(
|
r = dateutil.rrule.rrulestr(
|
||||||
'\n'.join(r),
|
'\n'.join(r),
|
||||||
unfold=True,
|
unfold=True,
|
||||||
ignoretz=True,
|
ignoretz=False,
|
||||||
dtstart=datetime.datetime.fromisoformat(
|
dtstart=dtstart,
|
||||||
e['start']['dateTime']
|
|
||||||
if 'dateTime' in e['start'] else
|
|
||||||
e['start']['date']
|
|
||||||
).replace(tzinfo=None)
|
|
||||||
)
|
)
|
||||||
for t_ in r.between(now.replace(tzinfo=None), now_365.replace(tzinfo=None)):
|
for t_ in r.between(now, now_365):
|
||||||
e_ = copy.deepcopy(e)
|
e_ = copy.deepcopy(e)
|
||||||
if 'dateTime' in e['start']:
|
if 'dateTime' in e['start']:
|
||||||
e_['start']['dateTime'] = datetime.datetime.combine(t_.date(), datetime.datetime.fromisoformat(e['start']['dateTime']).time()).isoformat()
|
e_['start']['dateTime'] = datetime.datetime.combine(t_.date(), datetime.datetime.fromisoformat(e['start']['dateTime']).time()).isoformat()
|
||||||
|
|
|
@ -6,7 +6,6 @@ import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from google.auth.transport.requests import Request
|
from google.auth.transport.requests import Request
|
||||||
#from google.oauth2.credentials import Credentials
|
|
||||||
from google.oauth2.service_account import Credentials
|
from google.oauth2.service_account import Credentials
|
||||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
|
@ -53,7 +52,7 @@ class Google(Source, Adapter):
|
||||||
|
|
||||||
def get_events(self, start: datetime.datetime | None=None, until: datetime.timedelta | None=None, limit=None):
|
def get_events(self, start: datetime.datetime | None=None, until: datetime.timedelta | None=None, limit=None):
|
||||||
until = until if until else datetime.timedelta(days=365)
|
until = until if until else datetime.timedelta(days=365)
|
||||||
now = start if start else datetime.datetime.utcnow().astimezone()
|
now = start if start else datetime.datetime.now(datetime.timezone.utc)
|
||||||
now_365 = now + until
|
now_365 = now + until
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Wordpress(Sink, Adapter):
|
||||||
def _datestr_to_date(self, s, tz=None):
|
def _datestr_to_date(self, s, tz=None):
|
||||||
if s.endswith('Z'):
|
if s.endswith('Z'):
|
||||||
s = s[:-1]
|
s = s[:-1]
|
||||||
return datetime.datetime.fromisoformat(s).astimezone().date()
|
return datetime.datetime.fromisoformat(s).date()
|
||||||
|
|
||||||
def _generate_data_single(self, event, item_id=2):
|
def _generate_data_single(self, event, item_id=2):
|
||||||
start = event['start']
|
start = event['start']
|
||||||
|
@ -138,7 +138,7 @@ class Wordpress(Sink, Adapter):
|
||||||
start: datetime.datetime | None=None,
|
start: datetime.datetime | None=None,
|
||||||
until: datetime.timedelta | None=None
|
until: datetime.timedelta | None=None
|
||||||
):
|
):
|
||||||
start = start if start else datetime.datetime.utcnow().astimezone()
|
start = start if start else datetime.datetime.now(datetime.timezone.utc)
|
||||||
until = until if until else datetime.timedelta(days=365)
|
until = until if until else datetime.timedelta(days=365)
|
||||||
|
|
||||||
final_dict = {}
|
final_dict = {}
|
||||||
|
@ -160,7 +160,7 @@ class Wordpress(Sink, Adapter):
|
||||||
nonce = soup.find_all('input', {'id': 'wpbs_token'})[0]
|
nonce = soup.find_all('input', {'id': 'wpbs_token'})[0]
|
||||||
return nonce['value']
|
return nonce['value']
|
||||||
|
|
||||||
def post_events(self, events, start: datetime.datetime | None=None, until: datetime.timedelta | None=None):
|
def post_events(self, events, start: datetime.datetime | None=None, until: datetime.timedelta | None=None) -> bool:
|
||||||
metadata = self.calendar_metadata.to_dict()
|
metadata = self.calendar_metadata.to_dict()
|
||||||
data = self._generate_data(events, start=start, until=until)
|
data = self._generate_data(events, start=start, until=until)
|
||||||
update_request = self.session.post(
|
update_request = self.session.post(
|
||||||
|
@ -176,5 +176,6 @@ class Wordpress(Sink, Adapter):
|
||||||
r = 'wpbs_message=calendar_update_success' in update_request.text
|
r = 'wpbs_message=calendar_update_success' in update_request.text
|
||||||
if not r:
|
if not r:
|
||||||
raise Exception(f'failed to post events, got answer {update_request.text}')
|
raise Exception(f'failed to post events, got answer {update_request.text}')
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
1
main.py
1
main.py
|
@ -11,7 +11,6 @@ from schema import Schema, And, Or, Use, Optional, Regex
|
||||||
import click
|
import click
|
||||||
|
|
||||||
import adapters
|
import adapters
|
||||||
from adapters import *
|
|
||||||
|
|
||||||
logging.VERBOSE = (logging.DEBUG + logging.INFO) // 2
|
logging.VERBOSE = (logging.DEBUG + logging.INFO) // 2
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue