static async Task Main(string[] args) { string username = GetUserInput("O*NET Web Services username"); string password = GetUserInput("O*NET Web Services password"); OnetWebService onet_ws = new OnetWebService(username, password); JObject vinfo = await onet_ws.Call("about"); CheckForError(vinfo); Console.WriteLine("Connected to O*NET Web Services version " + (string)vinfo["api_version"]); Console.WriteLine(""); string kwquery = GetUserInput("Keyword search query"); OnetWebService.QueryParams query = new OnetWebService.QueryParams() { { "keyword", kwquery }, { "end", "5" }, }; JObject kwresults = await onet_ws.Call("online/search", query); CheckForError(kwresults); if (!kwresults.ContainsKey("occupation") || !kwresults["occupation"].HasValues) { Console.WriteLine("No relevant occupations were found."); Console.WriteLine(""); } else { Console.WriteLine($"Most relevant occupations for \"{kwquery}\":"); foreach (JObject occ in kwresults["occupation"]) { Console.WriteLine(" " + occ["code"] + " - " + occ["title"]); } Console.WriteLine(""); } }
static async Task Main(string[] args) { // read JSON input JObject input = JObject.Load(new JsonTextReader(Console.In)); // initialize Web Services and results objects JObject config = input.Value <JObject>("config"); OnetWebService onet_ws = new OnetWebService(config["username"].ToString(), config["password"].ToString()); int max_results = 1; if (config.ContainsKey("max_results")) { max_results = Math.Max(1, config["max_results"].ToObject <int>()); } JObject output = new JObject(); output["output"] = new JArray(); // call keyword search for each input query foreach (JToken qtoken in input["queries"]) { string q = qtoken.ToString(); JArray res = new JArray(); OnetWebService.QueryParams query = new OnetWebService.QueryParams() { { "keyword", q }, { "end", max_results.ToString() }, }; JObject kwresults = await onet_ws.Call("online/search", query); if (kwresults.ContainsKey("occupation") && kwresults["occupation"].HasValues) { foreach (JObject occ in kwresults["occupation"]) { JObject ores = new JObject(); ores["code"] = new JValue(occ["code"].ToString()); ores["title"] = new JValue(occ["title"].ToString()); res.Add(ores); } } JObject qres = new JObject(); qres["query"] = new JValue(q); qres["results"] = res; output.Value <JArray>("output").Add(qres); } Console.WriteLine(output.ToString()); }