You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.9 KiB
47 lines
1.9 KiB
import contentful
|
|
import markdown
|
|
import os
|
|
|
|
class ContentfulService:
|
|
def __init__(self, space_id, access_token):
|
|
self.client = contentful.Client(space_id, access_token)
|
|
|
|
def get_general_info(self):
|
|
entries = self.client.entries({'content_type': 'general'})
|
|
if not entries:
|
|
return None
|
|
entry = entries[0]
|
|
general_date = entry.fields().get('general_date')
|
|
general_end_date = entry.fields().get('general_end_date')
|
|
general_text = entry.fields().get('general_text')
|
|
general_text_event = entry.fields().get('general_event_text')
|
|
general_text_conference = entry.fields().get('general_conference_text')
|
|
formatted_date = general_date.strftime('%#d %b %Y') if general_date else None
|
|
formatted_end_date = general_end_date.strftime('%#d %b %Y') if general_end_date else None
|
|
info = {
|
|
'startDate': formatted_date,
|
|
'endDate': formatted_end_date,
|
|
'text': markdown.markdown(general_text) if general_text else '',
|
|
'textConference': markdown.markdown(general_text_conference) if general_text_conference else '',
|
|
'textEvent':markdown.markdown(general_text_event) if general_text_event else ''
|
|
}
|
|
return info
|
|
|
|
def get_location_info(self):
|
|
entries = self.client.entries({'content_type': 'locations'})
|
|
location_list = []
|
|
for e in entries:
|
|
name = getattr(e, 'name')
|
|
directions = getattr(e, 'directions')
|
|
url = getattr(e, 'url')
|
|
image_asset = getattr(e, 'image')
|
|
image_url = image_asset.url() if image_asset else ''
|
|
content = {
|
|
'name': name,
|
|
'directions' : directions,
|
|
'url' : url,
|
|
'image' : image_url
|
|
}
|
|
location_list.append(content)
|
|
return location_list
|
|
|