def create_ics(sender, instance, **kwargs): c = Calendar() alarm = [DisplayAlarm(trigger=timedelta(minutes=30))] e = Event() e.name = instance.title e.begin = instance.date e.end = instance.dateend e.alarms = alarm if instance.duration != None: e.duration = instance.duration if (instance.cost == 0 or instance.cost == None): cost = 'Бесплатно' e.description = str(instance.intro) + ' Стоимость: ' + str(cost) else: e.description = str(instance.intro) + ' Стоимость: ' + str(instance.cost)+ 'р.' e.location = instance.location if instance.timepad != None: e.url = instance.timepad c.events.add(e) instance.ics.delete(save=False) instance.ics.save(instance.title +'.ics', ContentFile(str(c)), save=True) #Формирование глобального файла со всеми мероприятиями global_ics = EventIndex.objects.all()[0] events = global_ics.get_children() c = Calendar() for event in events: if (event.specific.date < timezone.now()): pass else: e = Event() e.name = event.title e.begin = event.specific.date e.end = event.specific.dateend e.alarms = alarm if event.specific.duration != None: e.duration = event.specific.duration if (event.specific.cost == 0 or event.specific.cost == None): cost = 'Бесплатно' e.description = str(event.specific.intro.strip("<p>*</p>")) + ' Стоимость: ' + str(cost) else: e.description = str(event.specific.intro.strip("<p>*</p>")) + ' Стоимость: ' + str(event.specific.cost)+ 'р.' e.location = event.specific.location if event.specific.timepad != None: e.url = event.specific.timepad c.events.add(e) global_ics.calenadar_file.delete(save=False) global_ics.calenadar_file.save('global.ics', ContentFile(str(c)), save=True)
def save_ics_file(self, ics_file: str, n_events: int = 50) -> None: """ Saves n_events random events in the ics file with path ics_file :param ics_file (str): path of the ics file :param n_events (int): number of events to generate """ c = Calendar() for i in range(0, n_events): sys.stdout.write("\rCreating event %i of %i" % (i, n_events)) sys.stdout.flush() e = Event() e.name = self.get_rnd_title() (start, end, duration, created) = self.get_rnd_event_time() e.begin = start e.end = end e.duration = duration e.created = created e.description = self.get_rnd_description() e.url = self.get_rnd_url() e.location = self.get_rnd_address() c.events.add(e) with open(ics_file, 'w') as f: f.writelines(c) sys.stdout.write("\rDone") sys.stdout.flush()
def create_calendar_event(date, name, description): e = Event() e.name = name e.description = description e.begin = date e.end = date + timedelta(hours=24) e.url = EVENT_URL return e
def ics_event(self): e = Event() e.name = '{} {} Exam'.format(self.unit, self.subject) e.begin = self.start e.end = self.end e.location = self.venue e.url = URL e.description = 'Seat: {} \r\nConditions: {} \r\nDuration: {} minutes \r\nVenue: {}'.format( self.seat, self.conditions, self.duration, self.venue) return e
def main(req: func.HttpRequest) -> func.HttpResponse: try: api = Trading(appid=os.environ["EBAY_APPID"], devid=os.environ['EBAY_DEVID'], certid=os.environ['EBAY_CERTID'], token=os.environ['EBAY_TOKEN'], siteid=os.environ['EBAY_SITEID'], config_file=None) response = api.execute('GetMyeBayBuying', {'DetailLevel': 'ReturnAll'}) r = response.dict() r_named = namedtuple("object", r.keys())(*r.values()) watchlist = r_named.WatchList["ItemArray"]["Item"] c = Calendar() for item in watchlist: event = Event() event.uid = item["ItemID"] event.name = item["Title"] event.url = item["ListingDetails"]["ViewItemURL"] event.begin = item["ListingDetails"]["EndTime"] event.end = event.begin price = "N/A" if item["SellingStatus"] is not None: try: price = "{} {}".format( item["SellingStatus"]["ConvertedCurrentPrice"] ["_currencyID"], item["SellingStatus"]["CurrentPrice"]["value"]) except KeyError as e: price = "{} {}".format( item["SellingStatus"]["CurrentPrice"]["_currencyID"], item["SellingStatus"]["CurrentPrice"]["value"]) pass event.description = "{}\nPrice: {}\nURL: {}".format( event.name, price, event.url) c.events.add(event) s = ''.join(str(l) for l in c) return func.HttpResponse( s, mimetype="text/calendar", charset="utf-8", headers={ "Content-Disposition": "attachment; filename=\"ebay-watchlist.ics\"" }) except ConnectionError as e: return func.HttpResponse(str(e), status_code=400)
def _generate_calendar(self, checkins, year=None): """ Supplied with a list of checkin data from the API, generates an ics Calendar object and returns it. """ user_url = self._get_user_url() c = Calendar() #for checkin in list(checkins)["checkins"]["items"]: for checkin in checkins: try: venue_name = checkin["venue"]["name"] tz_offset = self._get_checkin_timezone(checkin) e = Event() e.name = "@ {}".format(venue_name) e.location = venue_name e.url = "{}/checkin/{}".format(user_url, checkin["id"]) e.uid = "{}@foursquare.com".format(checkin["id"]) e.begin = checkin["createdAt"] e.end = e.begin # Use the 'shout', if any, and the timezone offset in the # description. description = [] description.append("{}\n".format(e.url)) if "shout" in checkin and len(checkin["shout"]) > 0: description = [checkin["shout"]] description.append("Timezone offset: {}".format(tz_offset)) e.description = "\n".join(description) # Use the venue_name and the address, if any, for the location. location = venue_name if "location" in checkin["venue"]: loc = checkin["venue"]["location"] if "formattedAddress" in loc and len( loc["formattedAddress"]) > 0: address = ", ".join(loc["formattedAddress"]) location = "{}, {}".format(location, address) e.location = location if (year is not None): if (e.begin.year == year): c.events.add(e) else: c.events.add(e) except: print("Error processing {}".format(venue_name)) continue return c
def generate(self): ''' Generates the ics calendar invite ''' calendar = Calendar() calendar_event = CalendarEvent() calendar_event.begin = self._event.start calendar_event.end = self._event.end calendar_event.name = self._event.name calendar_event.description = self._description() calendar_event.url = self._url() calendar_event.location = self._location() calendar.events.add(calendar_event) return calendar
def get_ical_event(self, e): ical_event = Event() ical_event.name = self.get_facebook_event_property( e, 'name', '[Some Event]') ical_event.begin = self.get_facebook_event_property( e, 'start_time', '') ical_event.end = self.get_facebook_event_property(e, 'end_time', '') ical_event.uid = self.get_facebook_event_property(e, 'id', '') ical_event.url = 'https://www.facebook.com/events/%s' % self.get_facebook_event_property( e, 'id', '') ical_event.description = '%s\n\n%s' % ( ical_event.url, self.get_facebook_event_property(e, 'description', '')) return ical_event
def create_calendar(uri): c = Calendar(creator="rss2cal.py by raivivek") parsed_feed = feedparser.parse(uri) for entry in parsed_feed.entries: e = Event() e.name = entry.title e.begin = arrow.get(entry.ev_startdate) e.end = arrow.get(entry.ev_enddate) e.description = entry.description e.location = entry.ev_location e.url = entry.link e.categories = [entry.category] c.events.add(e) return c
def _generate_calendar(self, checkins): """Supplied with a list of checkin data from the API, generates an ics Calendar object and returns it. Keyword arguments: checkins -- A list of dicts, each one data about a single checkin. """ user = self._get_user() c = Calendar() for checkin in checkins: if "venue" not in checkin: # I had some checkins with no data other than # id, createdAt and source. continue venue_name = checkin["venue"]["name"] tz_offset = self._get_checkin_timezone(checkin) e = Event() e.name = "@ {}".format(venue_name) e.location = venue_name e.url = "{}/checkin/{}".format(user["canonicalUrl"], checkin["id"]) e.uid = "{}@foursquare.com".format(checkin["id"]) e.begin = checkin["createdAt"] # Use the 'shout', if any, and the timezone offset in the # description. description = [] if "shout" in checkin and len(checkin["shout"]) > 0: description = [checkin["shout"]] description.append("Timezone offset: {}".format(tz_offset)) e.description = "\n".join(description) # Use the venue_name and the address, if any, for the location. location = venue_name if "location" in checkin["venue"]: loc = checkin["venue"]["location"] if "formattedAddress" in loc and len(loc["formattedAddress"]) > 0: address = ", ".join(loc["formattedAddress"]) location = "{}, {}".format(location, address) e.location = location c.events.add(e) return c
def calendar_view(request, whatever): from ics import Calendar, Event actions, ctx = _get_actions(request, include_future=True, include_past=30) thecal = Calendar() thecal.creator = 'XR Mass Events' for action in actions: evt = Event() evt.uid = '{}@{}'.format(action.id, request.get_host()) evt.name = action.html_title evt.description = action.description evt.categories = action.tags.names() evt.last_modified = action.modified evt.url = request.build_absolute_uri(action.get_absolute_url()) evt.begin = action.when evt.duration = timedelta(hours=1) # evt.end = action.when + timedelta(hours=1) evt.location = action.location thecal.events.add(evt) response = HttpResponse(thecal, content_type='text/calendar') return response
def create_lecture_event(lecture): ''' Create the calendar event given the lecture. ''' try: course = [x for x in courses if int(x[FIELD_TEACHING_ID]) == \ lecture[LECTURE_COURSE_ID]][0] # assume there is only one except IndexError as ie: print("Something gone wrong, I can't find the course with this id: {}".format(lecture[LECTURE_COURSE_ID])) exit(2) e = Event() e.name = sub(SUBJECT_REGEX, '', course[FIELD_TEACHING_SUBJECT_DESCRIPTION].capitalize()) if course[FIELD_TEACHING_TEACHER_NAME]: e.description = "Tenuto da {}".format(course[FIELD_TEACHING_TEACHER_NAME].title()) e.begin = lecture[LECTURE_START] e.end = lecture[LECTURE_END] e.created = datetime.today().astimezone() if lecture[LECTURE_LOCATION]: e.location = lecture[LECTURE_LOCATION] if course[FIELD_TEACHING_URL]: e.url = course[FIELD_TEACHING_URL] return e
def createEvents(event_day, event_fight_card_url, event_location, event_month, event_name, event_org, event_year): print '+++++++++++++++++++++++++++++' e = Event() e.name = event_name newMonth = month_converter(event_month) newDay = day_converter(event_day) print newMonth, ' <---- this is my month value' print newDay, ' <---- this is my day value' e.begin = "%s-%s-%s 19:00" % (event_year, newMonth, newDay) e.end = "%s-%s-%s 23:59" % (event_year, newMonth, newDay) e.url = event_fight_card_url e.location = event_location MMACalendar.events.add(e) print MMACalendar.events return
def createEvents(event_day, event_fight_card_url, event_location, event_month, event_name, event_org, event_year): print('+++++++++++++++++++++++++++++') e = Event() e.name = event_name newMonth = month_converter(event_month) newDay = day_converter(event_day) newDayEnd = end_day_converter(event_day,newMonth) newMonthEnd = month_end_converter(event_day,newMonth) print(newMonth, ' <---- this is my month value') print(newDay, ' <---- this is my day value') print(newDayEnd, ' <---- this is my end day value') e.begin = "%s-%s-%s 22:00" % (event_year, newMonth, newDay) e.end = "%s-%s-%s 03:59" % (event_year, newMonthEnd, newDayEnd) e.url = event_fight_card_url e.location = event_location MMACalendar.events.add(e) print(MMACalendar.events) return;
def scrap_events_from(year, month): url = "http://www.weeia.p.lodz.pl/pliki_strony_kontroler/kalendarz.php?rok={}&miesiac={}&lang=1".format( year, month) event_selector = "#kalendarz td.active" title_selector = "div.calendar-text" day_and_url_selector = "a.active" response = urlopen(url) html = BeautifulSoup(response.read()) selected_elements = html.select(event_selector) calendar = Calendar() for e in selected_elements: event = Event() event.name = e.select(title_selector)[0].getText() day_and_url = e.select(day_and_url_selector)[0] event.begin = "{}-{}-{:02d}".format(year, month, int(day_and_url.getText())) event.url = day_and_url["href"] event.make_all_day() calendar.events.add(event) return str(calendar)
from ics import Calendar, Event c = Calendar() e = Event() e.name = "K-WORLD FESTA" e.begin = '2019-08-15 18:30:00' e.end = '2019-08-15 23:59:59' e.description = 'K-WORLD FESTA Opening Concert' e.location = 'KSPO DOME' e.url = 'https://www.kworldfesta.com/kspodome' #e.categories = '' #e.status = 'Group' c.events.add(e) c.events # {<Event 'K-World Festa' begin:2019-08-15 18:00:00 end:2019-08-15 21:00:00>} with open('DC.ics', 'w') as f: f.writelines(c) # And it's done!
def ical(request): # This should be a comma-separated list with values corresponding to # Committee's abbreviation_short field. abbreviations = request.GET.get( 'committee', '').split(',') if 'committee' in request.GET else [] committees = Committee.objects.filter( parliaments__parliament_num=CURRENT_PARLIAMENT_NUM) if len(abbreviations) > 0: committees = committees.filter(abbreviation_short__in=abbreviations) cal = Calendar() cal.creator = '-//Alþingi//NONSGML Fastanefndir Alþingis//IS' cal.scale = 'GREGORIAN' cal.method = 'PUBLISH' agendas = CommitteeAgenda.objects.select_related( 'committee').prefetch_related('committee_agenda_items').filter( parliament__parliament_num=CURRENT_PARLIAMENT_NUM, committee__in=committees).order_by('timing_start_planned') for agenda in agendas: # Short-hand. agenda_id = agenda.committee_agenda_xml_id description = 'Dagskrá:\n\n' for item in agenda.committee_agenda_items.select_related( 'issue__parliament'): description += '%d. %s\n' % (item.order, capfirst(item.name)) # Add URL of issue, if any. if item.issue is not None: description += '%s\n' % external_issue_url( item.issue.parliament.parliament_num, item.issue.issue_num) description += '\n' event = Event() event.uid = '*****@*****.**' % agenda_id event.name = capfirst(agenda.committee.name) event.description = description event.begin = agenda.timing_start_planned event.end = agenda.timing_end event.url = 'https://www.althingi.is/thingnefndir/dagskra-nefndarfunda/?nfaerslunr=%d' % agenda_id # Committee agendas are never planned at midnight (or damn well # hopefully not). So when a committee agenda is planned without a time # factor, or in other words, is timed at midnight, we'll assume that # the timing is actually not precisely determined and turn it into an # all-day event instead, using the timing text (determined below) to # elaborate instead. if event.begin.hour == 0 and event.begin.minute == 0 and event.begin.second == 0: event.make_all_day() if agenda.timing_text: # If agenda.timing_text is just a representation of what is # already known from the planned starting time, we'll want to # nullify it so that we don't clutter the name with it # unnecessarily. To do this, we have to re-construct the text that # is typically provided and compare it against agenda.timing_text. # If they match, we won't include it. If they don't match, then # what's provided in agenda.timing_text is presumably more # meaningful than simply a (badly) reformatted version of # agenda.timing_start_planned. timing = agenda.timing_start_planned day = timing.day month_name = ICELANDIC_MONTHS[timing.month] year = str(timing.year)[2:] time = timing.strftime('%-I:%M') am_pm = icelandic_am_pm(timing) # Known inconsistencies are whether there is a space in the # beginning, and whether there is one space or two between "kl." # and the time-of-day. We strip and replace to compensate. timing_text_test = '%d. %s %s, kl. %s %s' % (day, month_name, year, time, am_pm) if agenda.timing_text.strip().replace(' ', ' ') != timing_text_test: event.name += ' (%s)' % agenda.timing_text.strip() cal.events.add(event) ical_text = monkey_patch_ical( cal.__str__(), 'Fastanefndir Alþingis', 'Dagatal sem inniheldur boðaða fundi fastanefnda Alþingis ásamt dagskrá í lýsingu.', 'Reykjavik/Iceland', 'PT10M') if request.GET.get('plaintext', False): content_type = 'text/plain' else: content_type = 'text/calendar' return HttpResponse(ical_text, content_type='%s; charset=utf-8' % content_type)