Skip to content

Commit

Permalink
Change the timezone on the datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
vdusart committed Oct 7, 2022
1 parent 9129409 commit b2afffc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion models/Datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def __init__(self, date, time):
self.minute = "00"

def to_str(self):
return f'{self.year}-{self.month}-{self.day} {self.hour}:{self.minute}:00'
return f'{self.year}-{self.month}-{self.day} {self.hour}:{self.minute}:00+02:00'
1 change: 1 addition & 0 deletions models/ParsedLesson.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def to_ical_event(self):
valid_end_time = self.end_time if self.end_time is not None else "23h59"

e.begin = Datetime(self.date, valid_start_time).to_str()

e.end = Datetime(self.date, valid_end_time).to_str()

return e
Expand Down
7 changes: 6 additions & 1 deletion scrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from Parser import Parser
from models.db import Timetables
from utils.base import Base, Session, engine
from upload import upload_files

Base.metadata.create_all(engine)
session = Session()
Expand All @@ -16,6 +17,7 @@

timetables = session.query(Timetables).all()
for timetable in timetables:
print(f"[+] Getting timetable: {timetable.name}")
url = f"https://docs.google.com/spreadsheets/d/{timetable.spreadsheet_id}/export?format=csv&gid={timetable.gid}"
r = requests.get(url)

Expand All @@ -28,5 +30,8 @@

with open(f'./{folder_name}/{timetable.name}.ics'.replace(" ", ""), 'w') as f:
lines = c.serialize_iter()
lines = lines[:-2] + ["REFRESH-INTERVAL;VALUE=DURATION:P1H\n"] + lines[-1:]
lines = lines[:-1] + ["REFRESH-INTERVAL;VALUE=DURATION:P1H\n"] + lines[-1:]
f.writelines(lines)
print(f"[+] Saving calendar in file ./{folder_name}/{timetable.name.replace(' ', '')}.ics")

upload_files()
16 changes: 9 additions & 7 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
bucket = conn.get_bucket(os.environ.get('BUCKET_NAME'))
bucket.set_acl('public-read')

directory = os.environ.get('ICS_FOLDER_NAME')
calendars = [f for f in os.listdir(directory) if isfile(join(directory, f))]

for calendar in calendars:
key = Key(bucket)
key.key = calendar
key.set_contents_from_filename(f'{directory}/{calendar}')
key.set_acl('public-read')
def upload_files():
directory = os.environ.get('ICS_FOLDER_NAME')
calendars = [f for f in os.listdir(directory) if isfile(join(directory, f))]

for calendar in calendars:
key = Key(bucket)
key.key = calendar
key.set_contents_from_filename(f'{directory}/{calendar}')
key.set_acl('public-read')

0 comments on commit b2afffc

Please sign in to comment.