Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def MakeTimes(dates):
"""Send a message when the command /GetTimes is issued."""
"""update.message.reply_text('Times!')"""
i = 0
timeSpanBeginDate = ""
calendar_event = None
icalString = []
cal = Calendar()
cal['summary'] = 'Playstation 4 Playtime'
while i < len(dates):
if (i == 0):
print("First element")
timeSpanBeginDate = dates[i]
elif (isBeginOfTimespan(dates[i - 1], dates[i])):
print("Timespan Begin ")
calendar_event = None
timeSpanBeginDate = dates[i]
elif (i + 1 == len(dates)):
print("Last Element")
calendar_event = getIcalDate(timeSpanBeginDate, dates[i])
elif (isBeginOfTimespan(dates[i], dates[i + 1])):
print("Timespan End ")
def parse(ical):
cal = Calendar.from_ical(ical)
map = {}
for event in cal.walk('vevent'):
date = event.get('dtstart')
summary = event.get('summary')
categories = event.get('categories')
if categories in ['Blue Day', 'Red Day', 'Anchor Day']:
print("{} {} {}".format(date.to_ical(), summary, categories))
map[date.to_ical()] = str(summary)
return map
def parties_ical(parties, summary="Upcoming Cryptoparties"):
"""
ical feed for all upcoming
TODO: it'd be nice if we could generate location-based feeds
i.e. give me an iCal feed of all events within 50km of [city]
"""
cal = icalendar.Calendar()
cal["summary"] = summary
for party in parties:
event = icalendar.Event()
event.add('uid', party.id)
event.add('dtstart', party.time)
event.add('summary', party.description)
event.add('location', party.street_address)
event.add('url', party.additional_info)
# TODO: add titles here
cal.add_component(event)
return Response(cal.to_ical(), mimetype="text/calendar")
def open_cal():
if os.path.isfile(filename):
if file_extension == 'ics':
print("Extracting events from file:", filename, "\n")
f = open(sys.argv[1], 'rb')
gcal = Calendar.from_ical(f.read())
for component in gcal.walk():
event = CalendarEvent("event")
if component.get('SUMMARY') == None: continue #skip blank items
event.summary = component.get('SUMMARY')
event.uid = component.get('UID')
if component.get('DESCRIPTION') == None: continue #skip blank items
event.description = component.get('DESCRIPTION')
event.location = component.get('LOCATION')
if hasattr(component.get('dtstart'), 'dt'):
event.start = component.get('dtstart').dt
if hasattr(component.get('dtend'), 'dt'):
event.end = component.get('dtend').dt
event.url = component.get('URL')
def construct_icalendar(context, events):
"""Returns an icalendar.Calendar object.
:param context: A content object, which is used for calendar details like
Title and Description. Usually a container, collection or
the event itself.
:param events: The list of event objects, which are included in this
calendar.
"""
cal = icalendar.Calendar()
cal.add('prodid', PRODID)
cal.add('version', VERSION)
cal_tz = default_timezone(context)
if cal_tz:
cal.add('x-wr-timezone', cal_tz)
tzmap = {}
if not getattr(events, '__getitem__', False):
events = [events]
for event in events:
if ICatalogBrain.providedBy(event) or\
IContentListingObject.providedBy(event):
event = event.getObject()
if not (IEvent.providedBy(event) or IOccurrence.providedBy(event)):
# Must be an event.
def process(self, email):
current_app.logger.info(f'attempting to process email {email["Subject"]}')
msg = None
info = None
result = False
for part in email.walk():
if part.get_content_type().startswith('multipart'):
for subpart in part.get_payload():
if subpart.get_content_type() == 'text/calendar':
try:
# some payloads are base64 encoded...
msg = base64.b64decode(subpart.get_payload())
msg = icalendar.Calendar.from_ical(msg)
except ValueError:
# ... and some aren't
msg = subpart.get_payload()
msg = icalendar.Calendar.from_ical(msg)
break
if not msg:
return False
for event in msg.subcomponents:
if event.name == 'VEVENT':
info = event
if not info:
return False
def createCalendarData(self, ownerId=None, ownerType=None, permissions=None, data=None):
if ownerId is None:
logWarning("NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR")
return None
if data is None: data = Calendar().to_ical()
result = self.DB_BRIDGE.getCalendarFromOwnerId(ownerId)
if result is None:
result = DBCalendarData()
result.setCalendarData(ownerId, ownerType, permissions, data)
result.saveToDB()
return result
def getICalObject(self):
return Calendar.from_ical(self.calendarData)
file_path = os.path.join(self.path, filename)
if os.path.isfile(file_path):
stat = os.lstat(file_path)
last_updated = datetime.fromtimestamp(stat.st_mtime, tz=utc)
if self.is_latest_content(last_updated, provider.get('last_updated')):
if NTBEventXMLFeedParser and isinstance(registered_parser, NTBEventXMLFeedParser):
logger.info('Ingesting xml events')
with open(file_path, 'rb') as f:
xml = ElementTree.parse(f)
parser = self.get_feed_parser(provider, xml.getroot())
item = parser.parse(xml.getroot(), provider)
elif isinstance(registered_parser, IcsTwoFeedParser):
logger.info('Ingesting ics events')
with open(file_path, 'rb') as f:
cal = Calendar.from_ical(f.read())
parser = self.get_feed_parser(provider, cal)
item = parser.parse(cal, provider)
else:
logger.info('Ingesting events with unknown parser')
parser = self.get_feed_parser(provider, file_path)
item = parser.parse(file_path, provider)
self.after_extracting(item, provider)
self.move_file(self.path, filename, provider=provider, success=True)
if isinstance(item, list):
yield item
else:
yield [item]
else:
self.move_file(self.path, filename, provider=provider, success=True)