static void Main(string[] args) { String apiKey = TogglToExcel.Properties.Resources.APIKey; var projectService = new Toggl.Services.ProjectService(apiKey); var timeService = new Toggl.Services.TimeEntryService(apiKey); var rte = new TimeEntryParams { StartDate = new DateTime(2015,11,9) , EndDate = DateTime.Now}; var projectHash = GetProjectHash(timeService.List(rte), projectService.List()); WriteHashToConsole(projectHash); WriteToExcel(projectHash); End(); }
static void Main(string[] args) { String apiKey = TogglToExcel.Properties.Resources.APIKey; var projectService = new Toggl.Services.ProjectService(apiKey); var timeService = new Toggl.Services.TimeEntryService(apiKey); var rte = new TimeEntryParams { StartDate = new DateTime(2015, 11, 9), EndDate = DateTime.Now }; var projectHash = GetProjectHash(timeService.List(rte), projectService.List()); WriteHashToConsole(projectHash); WriteToExcel(projectHash); End(); }
static void Backup(Options options) { var timeEntryService = new Toggl.Services.TimeEntryService(options.ApiKey); var prams = new TimeEntryParams { StartDate = options.StartDate, EndDate = options.EndDate, }; Console.WriteLine("Options"); Console.WriteLine(JsonConvert.SerializeObject(options, Formatting.Indented)); var output = new List <TimeEntry>(); var cont = true; while (cont) { List <TimeEntry> entries; try { entries = timeEntryService.List(prams); } catch (WebException e) { Console.WriteLine($"{e.Message}. Make sure your API key is correct"); return; } output.AddRange(entries); if (entries.Count == 1000) { Console.WriteLine("More than 1k"); TimeEntry lastEntry = entries.Last(); Console.WriteLine($"Last entry {lastEntry.Stop}"); var newdate = DateTime.Parse(lastEntry.Stop); prams.StartDate = newdate; } else { cont = false; } } var distinct = output.Distinct(new TimeEntryComparer()); Console.WriteLine($"Found {distinct.Count()} entires"); File.WriteAllText($"{Directory.GetCurrentDirectory()}/{options.OutputFileName}", JsonConvert.SerializeObject(distinct, Formatting.Indented)); }
/// <summary> /// Get Time Entry from Toggl.com /// </summary> private void GetTimeEntry() { try { // Get Time Entries in the last 8 hours var rte = new Toggl.QueryObjects.TimeEntryParams(); rte.StartDate = DateTime.Now.AddHours(-8); rte.EndDate = DateTime.Now; Toggl.Services.TimeEntryService timeEntrySrv = new Toggl.Services.TimeEntryService(Settings.Default.ApiKey); var entries = timeEntrySrv.List(rte); // Check current Time Entry if (entries.Count() > 0) { TimeEntry currentEntry = entries.Last(); if (currentEntry.Duration < 0) { Description = ConvertString(currentEntry.Description); EntryTime = Convert.ToDateTime(currentEntry.Start); _isNoTimeEntry = false; } else if (!_isNoTimeEntry) { Description = "No Time Entry"; EntryTime = DateTime.Now; _isNoTimeEntry = true; } } else if (!_isNoTimeEntry) { Description = "No Time Entry"; EntryTime = DateTime.Now; } _refreshTime = DateTime.Now; } catch { Console.WriteLine("Failed to get time entry"); } }