예제 #1
0
        public static List<TaggableSource> GetEventBriteOrganizers(Calinfo calinfo, Dictionary<string, string> settings)
        {
            var organizers = new List<TaggableSource>();
            var name_and_pk = "eventbritesources";
            var collector = new Collector(calinfo, settings);
            string method = "event_search";
            string args = collector.MakeEventBriteArgs();
            int page_count = collector.GetEventBritePageCount(method, args);

            var results = from evt in collector.EventBriteIterator(page_count, method, args)
                          select new
                          {
                              id = evt.Descendants("organizer").Descendants("id").FirstOrDefault().Value,
                              name = evt.Descendants("organizer").Descendants("name").FirstOrDefault().Value,
                              city = evt.Descendants("venue").Descendants("city").FirstOrDefault().Value.ToLower()
                          };

            results = results.Distinct();

            Parallel.ForEach(source: results, body: (id_name_city) =>
            {
                if (id_name_city.city != calinfo.City)
                    return;
                var organizer_id = id_name_city.id;
                var name = id_name_city.name;
                var home_url = "http://www.eventbrite.com/org/" + organizer_id;
                var escaped_name = Uri.EscapeDataString(name);
                var ical_url = string.Format("http://elmcity.cloudapp.net/ics_from_eventbrite_organizer?organizer={0}&elmcity_id={1}", escaped_name, calinfo.id);
                var taggable = new TaggableSource(name, calinfo.id, home_url, ical_url, id_name_city.city);
                RememberTaggable(name_and_pk, organizer_id, taggable);
                organizers.Add(taggable);
            });

            return organizers;
        }
예제 #2
0
        public EventCollectorTest()
        {
            test_calinfo = new Calinfo(ElmcityUtils.Configurator.azure_compute_account);
            lookup_lat = test_calinfo.lat;
            lookup_lon = test_calinfo.lon;
            radius = Configurator.default_radius;
            test_upcoming_args = string.Format("location={0},{1}&radius={2}&min_date={3}", lookup_lat, lookup_lon, radius, min_date);
            settings = GenUtils.GetSettingsFromAzureTable();
            basic_ics = BlobStorage.MakeDefaultBlobStorage().GetBlob("admin", "basic.ics").HttpResponse.DataAsString();
            bs = BlobStorage.MakeDefaultBlobStorage();
            calinfo_berkeley = new Calinfo(berkeley_test_hub);
            calinfo_keene = new Calinfo(keene_test_hub);
            collector_berkeley = new Collector(calinfo_berkeley, settings);
            collector_keene = new Collector(calinfo_keene,settings);
            foreach (var example in ics_examples)
                UpdateYYYY(example, "ics");

            foreach (var example in eventful_examples)
                UpdateYYYY(example, "xml");

            foreach (var example in upcoming_examples)
                UpdateYYYY(example, "xml");

            foreach (var example in eventbrite_examples)
                UpdateYYYY(example, "xml");
        }
예제 #3
0
파일: Discovery.cs 프로젝트: judell/elmcity
        public static List<TaggableSource> GetEventfulVenues(Calinfo calinfo, int min_per_venue, Dictionary<string, string> settings)
        {
            var collector = new Collector(calinfo, settings);
            string args = collector.MakeEventfulArgs(calinfo.where, 100, "");
            string method = "venues/search";
            var xdoc = collector.CallEventfulApi(method, args);
            var str_page_count = XmlUtils.GetXeltValue(xdoc.Root, ElmcityUtils.Configurator.no_ns, "page_count");
            int page_count = Convert.ToInt16(str_page_count);

            var ns = ElmcityUtils.Configurator.no_ns;
            var results = from venue in collector.EventfulIterator(page_count, args, "venues/search", "venue")
                          select new
                          {
                              id = venue.Attribute("id").Value,
                              name = XmlUtils.GetXeltValue(venue, ns, "name"),
                              city_name = XmlUtils.GetXeltValue(venue, ns, "city_name").ToLower(),
                              count = Convert.ToInt32(XmlUtils.GetXeltValue(venue, ns, "event_count")),
                              home_url = XmlUtils.GetXeltValue(venue, ns, "url")
                          };

            var venues = new List<TaggableSource>();
            var name_and_pk = "eventfulsources";

            Parallel.ForEach(source: results, body: (venue) =>
            {
                //if (venue.city_name != calinfo.City)
                if ( ! calinfo.City.Contains(venue.city_name) )
                    return;
                if (venue.count < min_per_venue)
                    return;
                var home_url = Regex.Replace(venue.home_url, "\\?.+", "");
                var ical_url = home_url.Replace("eventful.com/", "eventful.com/ical/");
                var taggable = new TaggableSource(venue.name, calinfo.id, home_url, ical_url, venue.city_name);
                RememberTaggable(name_and_pk, venue.id, taggable);
                venues.Add(taggable);
            });
            return venues;
        }
예제 #4
0
 public void UpcomingCanCallApi()
 {
     string method = "event.search";
     var collector = new Collector(test_calinfo, settings);
     var xdoc = collector.CallUpcomingApi(method, test_upcoming_args);
     var stat = from element in xdoc.Descendants("rsp")
                select element.Attribute("stat").Value;
     Assert.That(stat.First().ToString() == "ok");
 }
예제 #5
0
 public void iCalSingleEventIsPast()
 {
     var ics = basic_ics;
     var pastdate = DateTime.Now - new TimeSpan(10, 0, 0, 0, 0);
     ics = ics.Replace("__SINGLE_DATE_START__", pastdate.ToString("yyyyMMdd"));
     ics = ics.Replace("__SINGLE_DATE_END__", pastdate.ToString("yyyyMMdd"));
     StringReader sr = new StringReader(ics);
     var ical = iCalendar.LoadFromStream(sr).First().Calendar;
     var evt = ical.Events[0];
     var collector = new Collector(test_calinfo, settings);
     Assert.IsFalse(Collector.IsCurrentOrFutureDTStartInTz(evt.Start.Date, test_calinfo.tzinfo));
 }
예제 #6
0
 public void iCalSingleEventIsFuture()
 {
     var ics = basic_ics;
     var futuredate = DateTime.Now + new TimeSpan(10, 0, 0, 0, 0);
     ics = ics.Replace("__SINGLE_DATE_START__", futuredate.ToString("yyyyMMdd"));
     ics = ics.Replace("__SINGLE_DATE_END__", futuredate.ToString("yyyyMMdd"));
     StringReader sr = new StringReader(ics);
     var ical = iCalendar.LoadFromStream(sr).First().Calendar;
     var evt = ical.Events[0];
     var ical_now = new iCalDateTime(DateTime.Now.ToUniversalTime());
     Assert.That(evt.GetOccurrences(ical_now).Count == 0);
     var collector = new Collector(test_calinfo, settings);
     Assert.IsTrue(Collector.IsCurrentOrFutureDTStartInTz(evt.Start.Date, test_calinfo.tzinfo));
 }
예제 #7
0
 public void iCalRecurringEventHasFutureOccurrences()
 {
     var ics = basic_ics;
     ics = ics.Replace("__SINGLE_DATE_START__", DateTime.Now.ToString("yyyyMMdd"));
     ics = ics.Replace("__SINGLE_DATE_END__", DateTime.Now.ToString("yyyyMMdd"));
     StringReader sr = new StringReader(ics);
     var ical = iCalendar.LoadFromStream(sr).First().Calendar;
     Assert.That(ical.Events.Count > 0);
     var evt = ical.Events[1];
     DateTime now = DateTime.Now;
     DateTime then = now.AddDays(90);
     IList<Occurrence> occurrences = evt.GetOccurrences(now, then);
     Assert.That(occurrences.Count > 1);
     var period = occurrences[1].Period;
     var collector = new Collector(test_calinfo, settings);
     Assert.That(Collector.IsCurrentOrFutureDTStartInTz(period.StartTime.Date, test_calinfo.tzinfo));
 }
예제 #8
0
 public void EventfulQueryYieldsValidFirstEvent()
 {
     var collector = new Collector(test_calinfo, settings);
     var events = (IEnumerable<XElement>)collector.EventfulIterator(1, test_eventful_args, "events/search", "event");
     var es = new ZonedEventStore(test_calinfo, SourceType.ical);
     collector.AddEventfulEvent(es, test_venue, events.First());
     Assert.That(es.events[0].title != "");
 }
예제 #9
0
        public static List<TaggableSource> GetUpcomingVenues(Calinfo calinfo, Dictionary<string, string> settings)
        {
            var collector = new Collector(calinfo, settings);

            var args = collector.MakeUpcomingApiArgs(Collector.UpcomingSearchStyle.latlon);
            var method = "event.search";
            var xdoc = collector.CallUpcomingApi(method, args);
            int page_count = 1;
            var result_count = Collector.GetUpcomingResultCount(xdoc);

            page_count = (result_count / 100 == 0) ? 1 : result_count / 100;

            var events = collector.UpcomingIterator(page_count, "event.search");

            var venues = new List<TaggableSource>();
            var name_and_pk = "upcomingsources";

            Parallel.ForEach(source: events, body: (xelt) =>
            {
                var city = xelt.Attribute("venue_city");
                if (city.Value.ToLower() != calinfo.City)
                    return;
                var id = xelt.Attribute("venue_id").Value;
                var state = xelt.Attribute("venue_state_code");

                var name = xelt.Attribute("venue_name");
                // http://upcoming.yahoo.com/venue/863238/NH/Keene/The-Colonial-Theatre/
                var home_url = string.Format("http://upcoming.yahoo.com/venue/{0}/{1}/{2}/{3}/",
                    id,
                    state.Value,
                    city.Value,
                    name.Value.Replace(" ", "-")
                    );
                var ical_url = "http://upcoming.yahoo.com/calendar/v2/venue/" + id;
                var taggable = new TaggableSource(name.Value, calinfo.id, home_url, ical_url, city.Value);
                venues.Add(taggable);
                RememberTaggable(name_and_pk, id, taggable);
            });
            return venues;
        }
예제 #10
0
 public void EventfulQueryYieldsNonzeroEvents()
 {
     var collector = new Collector(test_calinfo, settings);
     var events = (IEnumerable<XElement>)collector.EventfulIterator(1, test_eventful_args, "events/search", "event");
     Assert.That(events.Count() > 0);
 }
예제 #11
0
        public void EventbriteQueryReturnsPageCountOrMinusOne()
        {
            var collector = new Collector(test_calinfo, settings);

            string method = "event_search";
            string args = collector.MakeEventBriteArgs(2, null);
            int count = collector.GetEventBritePageCount(method, args);
            Assert.That(count == -1 || count >= 1);
            if (count >= 1 && settings["eventbrite_quota_reached"] == "True")
            {
                GenUtils.PriorityLogMsg("info", "GetEventBritePageCount", "resetting quota marker");
                var dict = new Dictionary<string, object>() { { "value", false } };
                TableStorage.UpmergeDictToTableStore(dict, "settings", "settings", "eventbrite_quota_reached");
            }
        }
예제 #12
0
        public ActionResult view_calendar(string feedurl, string id)
        {
            var r = new ContentResult();
            r.ContentType = "text/html";

            if (id != String.Empty && Utils.CachedFeedObjExists(id, feedurl))
                return view_cached_calendar(feedurl, id);

            DDay.iCal.iCalendar ical;
            var source = ""; // unneeded for this single-cal purpose
            try
            {
                ical = Utils.iCalFromFeedUrl(feedurl, settings);
            }
            catch (Exception e)
            {
                r.Content = string.Format(@"Sorry, unable to parse {0} as an iCalendar feed. The error was: {1}", feedurl, e.Message + e.StackTrace);
                return r;
            }

            var events_to_include = new List<DDay.iCal.Event>();
            var event_recurrence_types = new Dictionary<DDay.iCal.Event, Collector.RecurrenceType>();
            var calinfo = new Calinfo(id);
            var collector = new Collector(calinfo, settings);
            try
            {
                DateTime utc_midnight_in_tz = Utils.MidnightInTz(calinfo.tzinfo).UniversalTime;
                DateTime then = utc_midnight_in_tz.AddDays(calinfo.icalendar_horizon_days);
                collector.FeedGather(utc_midnight_in_tz, then, 0, ical, source, events_to_include, event_recurrence_types, false);
                var es_zoned = new ZonedEventStore(calinfo, SourceType.ical);
                var fr = new FeedRegistry(id);
                foreach (var evt in events_to_include)
                    collector.AddIcalEvent(evt, fr, es_zoned, feedurl, source);
                var es_zoneless = new ZonelessEventStore(calinfo);
                r = view_calendar_helper(id, r, es_zoned, es_zoneless);
            }
            catch (Exception e)
            {
                r.Content = "Unable to view calendar. " + e.Message + e.StackTrace;
                return r;
            }
            return r;
        }
예제 #13
0
        public void MaybeApplyCatmapAddsExpectedCats()
        {
            var test_feedurl = "test_feedurl";
            var collector_keene = new Collector(new Calinfo("elmcity"), settings);
            collector_keene.per_feed_catmaps[test_feedurl] = new Dictionary<string, string>()
                {
                    { "a", "l,M,n,O,p" },   // this will map
                    { "z", "q" }            // this won't
                };

            var feed_metadict = new Dictionary<string, string>() { { "feedurl", test_feedurl } };

            var evt = new DDay.iCal.Event();

            evt.Categories.Add("a");  // set event categories
            evt.Categories.Add("b");
            evt.Categories.Add("b");  // this dupe should go away

            var list = collector_keene.MaybeApplyCatmap(evt.Categories.ToList(), feed_metadict, "testKeene", "Keene Test Hub");
            list.Sort(String.CompareOrdinal);
            Assert.IsTrue(list.SequenceEqual(new List<string>() { "a", "b", "l", "m", "n", "o", "p" }));
        }
예제 #14
0
 public void ExpandedCategoryListMergesWithHubTaxonomy()
 {
     var collector_keene = new Collector(new Calinfo("elmcity"), settings);
     collector_keene.tags = new List<string>() { "x", "y", "z" };                    // set hub taxonomy
     var list = new List<string>() { "a", "b", "x", "http://foo", "", "y", "z" };
     var qualified_list = Collector.RemoveDisqualifyingCats(list);
     var final_list = new List<string>();
     collector_keene.MaybeAddSquigglies(qualified_list, final_list);
     Assert.IsTrue(final_list.SequenceEqual(new List<string>() { "{a}", "{b}", "x", "y", "z" } ) );  // adds to hub taxonomy marked in squigglies
 }
예제 #15
0
 private static ZonelessEventStore ProcessIcalExample(string example, string source, Calinfo calinfo, FeedRegistry fr, Collector collector)
 {
     DeleteZonedObjects(calinfo.id);
     var feedurl = BlobStorage.MakeAzureBlobUri("admin", example + ".ics", false).ToString();
     fr.AddFeed(feedurl, source);
     var es = new ZonedEventStore(calinfo, SourceType.ical);
     collector.CollectIcal(fr, es, false);
     EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings);
     var zes = new ZonelessEventStore(calinfo).Deserialize();
     return zes;
 }
예제 #16
0
 private static ZonelessEventStore ProcessUpcomingExample(string example, string source, Calinfo calinfo, Collector collector)
 {
     DeleteZonedObjects(calinfo.id);
     var es = new ZonedEventStore(calinfo, SourceType.upcoming);
     collector.CollectUpcoming(es, test: true);
     EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings);
     var zes = new ZonelessEventStore(calinfo).Deserialize();
     return zes;
 }
예제 #17
0
 public void EventfulQueryYieldsNonzeroVenues()
 {
     string method = "venues/search";
     var collector = new Collector(test_calinfo, settings);
     var xdoc = collector.CallEventfulApi(method, test_eventful_args);
     var venues = from venue in xdoc.Descendants("venue") select venue;
     Assert.That(venues.Count() > 0);
 }