Example #1
0
        public void CollectFacebook(ZonedEventStore es, bool test)
        {
            using (facebook_ical)
            {
                var args = string.Format("q={0}&since=yesterday&limit=1000", this.calinfo.where);
                var method = "search";

                var msg = string.Format("{0}: loading facebook events", this.id);
                GenUtils.LogMsg("info", msg, null);

                var uniques = new Dictionary<string, FacebookEvent>();  // dedupe by title + start
                foreach (var fb_event in FacebookIterator(method, args))
                    uniques.AddOrUpdateDictionary<string, FacebookEvent>(fb_event.name + fb_event.dt.ToString(), fb_event);

                foreach (FacebookEvent fb_event in uniques.Values)
                {
                    var dtstart_with_zone = new DateTimeWithZone(fb_event.dt, this.calinfo.tzinfo);

                    if (dtstart_with_zone.UniversalTime < Utils.MidnightInTz(this.calinfo.tzinfo).UniversalTime)
                        continue;

                    AddFacebookEvent(es, fb_event, dtstart_with_zone);
                }

                fbstats.whenchecked = DateTime.Now.ToUniversalTime();

                SerializeStatsAndIntermediateOutputs(es, facebook_ical, fbstats, SourceType.facebook);
            }
        }
Example #2
0
        private void IncludeFutureEvent(List<DDay.iCal.Event> events_to_include, Dictionary<DDay.iCal.Event, RecurrenceType> event_recurrence_types, DDay.iCal.Event evt, DateTime midnight_in_tz, DateTime then, bool skip_date_only)
        {
            try
            {
                /*if (evt.RecurrenceRules.Count > 0)                    // check for unbounded recurrence
                    foreach (var rrule in evt.RecurrenceRules)
                        if (rrule.Until < DateTime.UtcNow)            // i.e. FREQ=DAILY but not FREQ=DAILY;UNTIL=20120101
                             return; */

                var occurrences = evt.GetOccurrences(midnight_in_tz, then);
                foreach (Occurrence occurrence in occurrences)
                {
                    try
                    {
                        var recurrence_type = occurrence.Source.RecurrenceRules.Count == 0 ? RecurrenceType.NonRecurring : RecurrenceType.Recurring;

                        if (recurrence_type == RecurrenceType.Recurring && skip_date_only && evt.DTStart.HasTime == false) // workaround for https://github.com/dougrday/icalvalid/issues/7 and 8
                            continue;                                                                                      // note: this is now a fallback because MassageFeedText tries to patch date-only UNTIL, adding T000000

                        if (IsCurrentOrFutureDTStartInTz(occurrence.Period.StartTime.UTC, this.calinfo.tzinfo))
                        {
                            var instance = PeriodizeRecurringEvent(evt, occurrence.Period);
                            events_to_include.Add(instance);
                            event_recurrence_types.AddOrUpdateDictionary<DDay.iCal.Event, Collector.RecurrenceType>(instance, recurrence_type);
                        }
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            GenUtils.PriorityLogMsg("exception", "IncludeFutureEvent (per occurrence)", evt.Summary + ", " + e.Message + e.StackTrace);
                        }
                        catch { continue; }
                    }
                }
            }

            catch (Exception e)
            {
                try
                {
                    GenUtils.PriorityLogMsg("exception", "IncludeFutureEvent (GetOccurrences) detail: " + evt.Summary, e.Message + e.StackTrace);
                }
                catch { return; }
            }
        }
Example #3
0
        public void CollectEventful(ZonedEventStore es, bool test)
        {
            this.LoadTags();

            using (eventful_ical)
            {
                string location = this.calinfo.where;
                var page_size = test ? test_pagesize : 100;
                string method = "events/search";

                var uniques = new Dictionary<string, XElement>(); // dedupe by title + start

                if (this.mock_eventful)							// normally get tags from compiled object
                    this.tags = new List<string>() { eventful_cat_map.Keys.First() }; // but for testing, just use one that will pass the filter

                foreach (var tag in this.tags)        // do tagwise search of eventful
                {
                    if ( eventful_cat_map.Keys.ToList().HasItem(tag) == false )
                        continue;

                    var msg = string.Format("{0}: loading eventful events for {1} ", this.id, tag);
                    GenUtils.LogMsg("info", msg, null);

                    string args = MakeEventfulArgs(location, page_size, this.eventful_cat_map[tag]);
                    var xdoc = CallEventfulApi(method, args);
                    var str_page_count = XmlUtils.GetXeltValue(xdoc.Root, ElmcityUtils.Configurator.no_ns, "page_count");
                    int page_count = test ? test_pagecount : Convert.ToInt16(str_page_count);

                    foreach (XElement evt in EventfulIterator(page_count, args, "events/search", "event"))
                    {
                        evt.Add(new XElement("category", tag));
                        var lat = XmlUtils.GetXeltValue(evt, ElmcityUtils.Configurator.no_ns, "latitude");
                        var lon = XmlUtils.GetXeltValue(evt, ElmcityUtils.Configurator.no_ns, "longitude");

                        if (lat != null && lon != null)  // check if eventful's radius filter failed us
                        {
                            var distance = Utils.GeoCodeCalc.CalcDistance(lat, lon, this.calinfo.lat, this.calinfo.lon);
                            if (distance > this.calinfo.radius)   // if so
                                continue;                         // skip this one
                        }

                        var ns = ElmcityUtils.Configurator.no_ns;

                        uniques.AddOrUpdateDictionary<string, XElement>(
                            XmlUtils.GetXeltValue(evt, ns, "title") +
                            XmlUtils.GetXeltValue(evt, ns, "start_time") +
                            XmlUtils.GetXeltValue(evt, ns, "category"),
                          evt);
                    }
                }

                Dictionary<string, int> event_count_by_venue = new Dictionary<string, int>();
                int event_num = 0;

                foreach (XElement evt in uniques.Values)
                {
                    event_num += 1;
                    if (event_num > Configurator.eventful_max_events)
                        break;

                    var ns = ElmcityUtils.Configurator.no_ns;
                    var title = XmlUtils.GetXeltValue(evt, ns, "title");
                    var start_time = XmlUtils.GetXeltValue(evt, ns, "start_time");
                    var venue_name = XmlUtils.GetXeltValue(evt, ns, "venue_name");
                    var url = XmlUtils.GetXeltValue(evt, ns, "url");

                    IncrementEventCountByVenue(event_count_by_venue, venue_name);
                    AddEventfulEvent(es, venue_name, evt);
                }

                estats.venuecount = event_count_by_venue.Keys.Count;
                estats.whenchecked = DateTime.Now.ToUniversalTime();

                SerializeStatsAndIntermediateOutputs(es, eventful_ical, estats, SourceType.eventful);

                //bs.PutBlob(this.id, SourceType.eventful.ToString() + "_cats.txt", String.Join(",", this.eventful_tags.ToList()));

            }
        }
Example #4
0
        public void CollectUpcoming(ZonedEventStore es, bool test)
        {
            using (upcoming_ical)
            {
                var page_size = test ? test_pagesize : 100;
                var args = MakeUpcomingApiArgs(UpcomingSearchStyle.latlon);
                var method = "event.search";
                var xdoc = CallUpcomingApi(method, args);
                int page_count = 1;
                try
                {
                    var result_count = GetUpcomingResultCount(xdoc);

                    if (result_count == 0) // try the other search style (upcoming seems flaky that way)
                    {
                        args = MakeUpcomingApiArgs(UpcomingSearchStyle.latlon);
                        xdoc = CallUpcomingApi(method, args);
                        GetUpcomingResultCount(xdoc);
                    }

                    page_count = result_count / page_size;
                }
                catch
                {
                    GenUtils.LogMsg("warning", "CollectUpcoming", "resultcount unavailable");
                    return;
                }

                if (test == true && page_count > test_pagecount) page_count = test_pagecount;
                if (page_count == 0) page_count = 1;

                var msg = string.Format("{0}: loading {1} upcoming events", this.id, page_count * page_size);
                GenUtils.LogMsg("info", msg, null);

                Dictionary<string, int> event_count_by_venue = new Dictionary<string, int>();
                int event_num = 0;

                var uniques = new Dictionary<string, XElement>();  // dedupe by name + start
                foreach (var evt in UpcomingIterator(page_count, method))
                    uniques.AddOrUpdateDictionary<string, XElement>(evt.Attribute("name").ToString() + evt.Attribute("start_date").ToString(), evt);

                foreach (XElement evt in uniques.Values)
                {
                    event_num += 1;
                    if (event_num > Configurator.upcoming_max_events)
                        break;

                    var dtstart = DateTimeWithZoneFromUpcomingXEvent(evt);

                    if (dtstart.UniversalTime < Utils.MidnightInTz(this.calinfo.tzinfo).UniversalTime)
                        continue;

                    var venue_name = evt.Attribute("venue_name").Value;
                    IncrementEventCountByVenue(event_count_by_venue, venue_name);

                    AddUpcomingEvent(es, venue_name, evt);
                }

                ustats.venuecount = event_count_by_venue.Keys.Count;
                ustats.whenchecked = DateTime.Now.ToUniversalTime();

                SerializeStatsAndIntermediateOutputs(es, upcoming_ical, ustats, SourceType.upcoming);
            }
        }