'Provides a subscribeable URL for iCal subscriptions'

def calendar(self):

    utc = dateutil.tz.gettz(u'GMT')
    sickrage.srCore.srLogger.info((u'Receiving    iCal    request    from    %s' % self.request.remote_ip))
    ical = u'BEGIN:VCALENDAR\r\n'
    ical += u'VERSION:2.0\r\n'
    ical += u'X-WR-CALNAME:SiCKRAGE\r\n'
    ical += u'X-WR-CALDESC:SiCKRAGE\r\n'
    ical += u'PRODID://Sick-Beard    Upcoming    Episodes//\r\n'
    past_date = (datetime.date.today() + datetime.timedelta(weeks=(-52))).toordinal()
    future_date = (datetime.date.today() + datetime.timedelta(weeks=52)).toordinal()
    for show in [x[u'doc'] for x in sickrage.srCore.mainDB.db.all(u'tv_shows', with_doc=True) if ((x[u'doc'][u'status'].lower() in [u'continuing', u'returning    series']) and (x[u'doc'][u'paused'] != 1))]:
        for episode in [x[u'doc'] for x in sickrage.srCore.mainDB.db.get_many(u'tv_episodes', int(show[u'indexer_id']), with_doc=True) if (past_date <= x[u'doc'][u'airdate'] < future_date)]:
            air_date_time = tz_updater.parse_date_time(episode[u'airdate'], show[u'airs'], show[u'network']).astimezone(utc)
            air_date_time_end = (air_date_time + datetime.timedelta(minutes=tryInt(show[u'runtime'], 60)))
            ical += u'BEGIN:VEVENT\r\n'
            ical += ((((u'DTSTART:' + air_date_time.strftime(u'%Y%m%d')) + u'T') + air_date_time.strftime(u'%H%M%S')) + u'Z\r\n')
            ical += ((((u'DTEND:' + air_date_time_end.strftime(u'%Y%m%d')) + u'T') + air_date_time_end.strftime(u'%H%M%S')) + u'Z\r\n')
            if sickrage.srCore.srConfig.CALENDAR_ICONS:
                ical += u'X-GOOGLE-CALENDAR-CONTENT-ICON:https://www.sickrage.ca/favicon.ico\r\n'
                ical += u'X-GOOGLE-CALENDAR-CONTENT-DISPLAY:CHIP\r\n'
            ical += u'SUMMARY:    {0}    -    {1}x{2}    -    {3}\r\n'.format(show[u'show_name'], episode[u'season'], episode[u'episode'], episode[u'name'])
            ical += ((((((((u'UID:SiCKRAGE-' + str(datetime.date.today().isoformat())) + u'-') + show[u'show_name'].replace(u'    ', u'-')) + u'-E') + str(episode[u'episode'])) + u'S') + str(episode[u'season'])) + u'\r\n')
            if episode[u'description']:
                ical += u'DESCRIPTION:    {0}    on    {1}    \\n\\n    {2}\r\n'.format((show[u'airs'] or u'(Unknown    airs)'), (show[u'network'] or u'Unknown    network'), episode[u'description'].splitlines()[0])
            else:
                ical += ((((u'DESCRIPTION:' + (show[u'airs'] or u'(Unknown    airs)')) + u'    on    ') + (show[u'network'] or u'Unknown    network')) + u'\r\n')
            ical += u'END:VEVENT\r\n'
    ical += u'END:VCALENDAR'
    return ical
