public static List<TaggableSource> GetMeetupGroups2(Calinfo calinfo, int delay, Dictionary<string, string> settings)
{
var meetup_key = settings["meetup_api_key"];
var template = "https://api.meetup.com/2/open_events?key={0}&lat={1}&lon={2}&radius={3}";
var url = String.Format(template,
meetup_key,
calinfo.lat,
calinfo.lon,
calinfo.radius);
var json = HttpUtils.SlowFetchUrl(new Uri(url), delay).DataAsString();
var dict = JsonConvert.DeserializeObject<Dictionary<String, object>>(json);
var results = (JArray)dict["results"];
var ids_and_cities = from result in results
select new
{
id = result["group"]["id"].Value<string>(),
city = GetMeetupCity(result)
};
var unique_ids_and_cities = ids_and_cities.Distinct();
var taggable_sources = new List<TaggableSource>();
Parallel.ForEach(source: unique_ids_and_cities, body: (id_and_city) =>
{
if (id_and_city.city != calinfo.City)
return;
string name_and_pk = "meetupsources";
try
{
template = "https://api.meetup.com/2/groups?key={0}&group_id={1}";
url = String.Format(template,
meetup_key,
id_and_city.id);
json = HttpUtils.SlowFetchUrl(new Uri(url), delay).DataAsString();
dict = JsonConvert.DeserializeObject<Dictionary<String, object>>(json);
results = (JArray)dict["results"];
var result = results.First();
var name = result["name"].Value<string>();
var urlname = result["urlname"].Value<string>();
var home_url = "http://www.meetup.com/" + urlname;
var ical_url = string.Format("http://www.meetup.com/{0}/events/ical/{1}/",
urlname,
Uri.EscapeDataString(name));
ical_url = ical_url.Replace("%20", "+"); // otherwise meetup weirdly reports a 505 error
var taggable = new TaggableSource(
name,
calinfo.id,
home_url,
ical_url,
id_and_city.city);
taggable_sources.Add(taggable);
RememberTaggable(name_and_pk, id_and_city.id, taggable);
}
catch (Exception e)
{
GenUtils.PriorityLogMsg("exception", "FindMeetupGroups", e.Message + e.StackTrace);
}
});
return taggable_sources;
}