private static bool VideoExists(string videoUrl) { var url = $"http://www.youtube.com/oembed?url={videoUrl}&format=json"; var json = WebTools.GetJObjectResponse(url); return(json != null && json.HasValues); }
public static List <Dictionary <string, dynamic> > GetPosts() { string url = $"{RootUrl}/{UserId}/media?access_token={AccessToken}&fields=permalink,caption,media_url"; var response = WebTools.GetJObjectResponse(url); try { if (response != null && response.HasValues && response["data"].Any()) { return(response["data"].ToObject <List <Dictionary <string, dynamic> > >()); } else { return(new List <Dictionary <string, dynamic> >() { }); } } catch (Exception e) { BotTools.LogToSessionLogFile(e.ToString()); return(new List <Dictionary <string, dynamic> >() { }); } }
public static Dictionary <string, dynamic> GetIntent(string text) { string baseUrl = "https://api.wit.ai/message?v=20200730&q="; string encodedText = HttpUtility.UrlEncode(text); var url = baseUrl + encodedText; var headers = new WebHeaderCollection() { $"Authorization: Bearer {appToken}" }; JObject response = WebTools.GetJObjectResponse(url, headers: headers); Console.WriteLine(response); try { if (response.HasValues && response["intents"].Any()) { var responseDict = response.ToObject <Dictionary <string, dynamic> >(); var mainIntent = responseDict["intents"].First; string description = mainIntent["name"].ToString(); double confidence = double.Parse(mainIntent["confidence"].ToString(), System.Globalization.CultureInfo.InvariantCulture); return(new Dictionary <string, dynamic>() { ["description"] = description, ["confidence"] = confidence }); } else { return(new Dictionary <string, dynamic>()); } } catch (Exception e) { BotTools.LogToSessionLogFile(e.ToString()); return(new Dictionary <string, dynamic>()); } }
public static void FetchInventoryData() { try { // Fetch NA item data var inventoryData = new Dictionary <string, Dictionary <string, dynamic> >() { ["na"] = new Dictionary <string, dynamic>(), ["eu"] = new Dictionary <string, dynamic>() }; List <string> naCharacterNames = GetCharacters("na").ToObject <List <string> >(); foreach (var characterName in naCharacterNames) { string encodedCharacterName = characterName.Replace(" ", "%20"); JObject upperInventoryData = WebTools.GetJObjectResponse($"{BaseURL}/characters/{encodedCharacterName}/inventory", DefaultHeaders("na")); if (upperInventoryData != null && upperInventoryData.HasValues) { JToken bags = upperInventoryData["bags"]; inventoryData["na"][characterName] = new List <Dictionary <string, dynamic> >(); foreach (JToken bag in bags) { if (bag.HasValues) { JToken bagContents = bag["inventory"]; foreach (JToken item in bagContents) { inventoryData["na"][characterName].Add(item.ToObject <Dictionary <string, dynamic> >()); } } } } } JArray naSharedBankData = WebTools.GetJArrayResponse($"{BaseURL}/account/bank", DefaultHeaders("na")); JArray naSharedInventoryData = WebTools.GetJArrayResponse($"{BaseURL}/account/inventory", DefaultHeaders("na")); JArray naMaterialsData = WebTools.GetJArrayResponse($"{BaseURL}/account/materials", DefaultHeaders("na")); JArray naWalletData = WebTools.GetJArrayResponse($"{BaseURL}/account/wallet", DefaultHeaders("na")); inventoryData["na"]["Shared Bank"] = naSharedBankData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["na"]["Shared Inventory"] = naSharedInventoryData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["na"]["Materials"] = naMaterialsData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["na"]["Wallet"] = naWalletData.ToObject <List <Dictionary <string, dynamic> > >(); // Fetch EU item data List <string> euCharacterNames = GetCharacters("eu").ToObject <List <string> >(); foreach (var characterName in euCharacterNames) { string encodedCharacterName = characterName.Replace(" ", "%20"); JObject upperInventoryData = WebTools.GetJObjectResponse($"{BaseURL}/characters/{encodedCharacterName}/inventory", DefaultHeaders("eu")); if (upperInventoryData != null && upperInventoryData.HasValues) { JToken bags = upperInventoryData["bags"]; inventoryData["eu"][characterName] = new List <Dictionary <string, dynamic> >(); foreach (JToken bag in bags) { if (bag.HasValues) { JToken bagContents = bag["inventory"]; foreach (JToken item in bagContents) { inventoryData["eu"][characterName].Add(item.ToObject <Dictionary <string, dynamic> >()); } } } } } JArray euSharedBankData = WebTools.GetJArrayResponse($"{BaseURL}/account/bank", DefaultHeaders("eu")); JArray euSharedInventoryData = WebTools.GetJArrayResponse($"{BaseURL}/account/inventory", DefaultHeaders("eu")); JArray euMaterialsData = WebTools.GetJArrayResponse($"{BaseURL}/account/materials", DefaultHeaders("eu")); JArray euWalletData = WebTools.GetJArrayResponse($"{BaseURL}/account/wallet", DefaultHeaders("eu")); inventoryData["eu"]["Shared Bank"] = euSharedBankData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["eu"]["Shared Inventory"] = euSharedInventoryData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["eu"]["Materials"] = euMaterialsData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["eu"]["Wallet"] = euWalletData.ToObject <List <Dictionary <string, dynamic> > >(); BotTools.WriteToJson(inventoryData, "resources\\inventory_data"); } catch (NullReferenceException e) { BotTools.LogToSessionLogFile(e.ToString()); } }