public bool ParseEvent(string EventUrl, List <EventInformation> EventList) { Match match; string EventContents; EventContents = PageDownloader.GetPageContents(EventUrl); match = Regex.Match(EventContents, @"<script type=""application/ld\+json"">(.*?)</script>", RegexOptions.Singleline); if (match.Success) { // For some reason the match has the <script> / </script> tags in it so we strip those out. string json = match.Groups[0].Value.Substring(35); json = json.Remove(json.Length - 10); EventDataJson twEventInfo = JsonConvert.DeserializeObject <EventDataJson>(json); EventInformation eventInfo = new EventInformation() { Title = twEventInfo.name, Location = twEventInfo.location.name, Description = EventUrl }; eventInfo.SetStartDate(twEventInfo.startDate); EventList.Add(eventInfo); return(true); } Console.WriteLine("ERROR: Couldn't parse event at {0}", EventUrl); return(false); }
public bool ParseEvent(string EventURL, List <EventInformation> EventList) { string EventContents; if (!IsAxsUrl(EventURL)) { return(false); } EventContents = PageDownloader.GetPageContents(EventURL); EventInformation EventInfo = new EventInformation(); EventInfo.SetStartDate(GetStartDate(EventContents)); EventInfo.Title = GetTitle(EventContents); EventInfo.Description = EventURL; EventInfo.Location = GetLocation(EventContents); return(true); }
public bool ParseEvent(string EventURL, List <EventInformation> EventList) { string EventContents; Match match; EventContents = PageDownloader.GetPageContents(EventURL); match = Regex.Match(EventContents, @"<div id=""maplocation"" style=""line-height:100%;"">(.*?) at (.*?), (.*?)<div id=""address"" style=""font-size:12px;margin-top:3px;"">(.*?)\("); // match = Regex.Match(EventContents, @"<script type=""application/ld\+json"">(.*?)</script>", RegexOptions.Singleline); if (match.Success) { string EventTitle; // TODO -- This is ugly but seems to mostly work. We still need a fuzzy/NLP date parser as DateTime.Parse is pretty dumb/rigid. DateTime StartTime = DateTime.Parse($"{match.Groups[1].Value} {DateTime.Now.Year} {match.Groups[2].Value}"); Match match2 = Regex.Match(EventContents, @"<link rel=""alternate"" type=""application/rss\+xml"" title=""(.*?)"""); if (match2.Success) { EventTitle = match2.Groups[1].Value; } else { EventTitle = "Error! Couldn't determine title!"; } EventInformation eventInfo = new EventInformation() { Title = EventTitle, Location = $"{match.Groups[3].Value} ({match.Groups[4].Value})", Description = EventURL }; eventInfo.SetStartDate(StartTime.ToString()); EventList.Add(eventInfo); return(true); } return(false); }
private static bool ParseFacebookEventListing(string URL, string EventContents, out EventInformation EventInfo) { string StartDate; string EndDate; EventInfo = new EventInformation(); EventInfo.Location = GetEventLocation(EventContents); EventInfo.Title = GetEventTitle(EventContents); if (string.IsNullOrEmpty(EventInfo.Title)) { return(false); } EventInfo.Description = "Source: " + URL + "\n"; if (!GetEventDates(EventContents, out StartDate, out EndDate)) { return(false); } EventInfo.SetStartDate(StartDate); if (string.IsNullOrEmpty(EndDate)) { // // If we don't have an explicit end date time just add an hour. // EventInfo.SetEndDate((DateTime.Parse(StartDate)).Add(new TimeSpan(1, 0, 0)).ToString()); } else { EventInfo.SetEndDate(EndDate); } return(true); }
static void Main(string[] args) { UserCredential credential; string CalendarID = "primary"; EventInformation EventInfo = new EventInformation(); string EventUrl = null; bool ParseOnly = false; // If this is true we parse the event URL and display its info but don't add it to the calendar. List <string> NakedParameters = null; bool FlagsPassed = false; // If we don't see any arguments then we act like the classic "cal" command // TODO -- https://www.twilio.com/blog/2018/05/user-secrets-in-a-net-core-console-app.html using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) // TODO -- Make this a resource { string credPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json"); // TODO credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; } // Create Google Calendar API service. var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); // TODO -- Check for required arguments // TODO -- Do some sanity checking (end >= start, end not specified if all-day, ...) // TODO -- A date string like "2018-01-28" will get round-tripped (through DateTime.Parse()) as having an explicit time of 12AM OptionSet options = new OptionSet(); options.Add("?|h|help", value => { PrintUsage(); }); options.Add("c|calendar=", value => { CalendarID = FindCalendarByName(service, value); if (CalendarID == null) { PrintUsage("Couldn't find specified calendar!"); } FlagsPassed = true; }); options.Add("d|description=", value => { EventInfo.Description = value; FlagsPassed = true; }); options.Add("e|end=", value => { EventInfo.SetEndDate(value); FlagsPassed = true; }); options.Add("p|parse-only", value => { ParseOnly = true; FlagsPassed = true; }); options.Add("r|reminder=", value => { EventInfo.AddReminder(value); FlagsPassed = true; }); options.Add("s|start=", value => { EventInfo.SetStartDate(value); FlagsPassed = true; }); options.Add("t|title=", value => { EventInfo.Title = value; FlagsPassed = true; }); options.Add("u|url=", value => { EventUrl = value; FlagsPassed = true; }); options.Add("w|where=", value => { EventInfo.Location = value; FlagsPassed = true; }); NakedParameters = options.Parse(args); if (FlagsPassed) { if (!String.IsNullOrEmpty(EventUrl)) { HandleEventURL(service, CalendarID, EventUrl, ParseOnly); } else { // // The event start and title are required, everything else is optional. // if (EventInfo.GetEventTimes().Count == 0) { PrintUsage("Start date is required!"); } else if (String.IsNullOrEmpty(EventInfo.Title)) { PrintUsage("A title is required!"); } AddCalendarEvent(service, CalendarID, EventInfo); } } else { if (NakedParameters.Count == 0) { ShowCalendar(); } else if (NakedParameters.Count == 1) { ShowCalendar(Int32.Parse(NakedParameters[0])); } else if (NakedParameters.Count == 2) { ShowCalendar(Int32.Parse(NakedParameters[0]), Int32.Parse(NakedParameters[1])); } else { PrintUsage(); } } }