// GET: Requeriments/Details/5 //EFE: Detalles del Requerimiento seleccionado. public ActionResult Details(int?idProjectFKPK, int?idModuleFKPK, int?idRequerimentPK) { if (idProjectFKPK == null || idModuleFKPK == null || idRequerimentPK == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.isLogged = false; var employeeController = new EmployeesController(); foreach (var employee in employeeController.EmployeeFromTeamSelectList(idProjectFKPK, null)) //Obtenemos a los miembros del equipo { if (employee.Value == Session["userID"].ToString()) //Si un miembro del equipo esta logueado { ViewBag.isLogged = true; break; } } Requeriment requeriment = db.Requeriment.Find(idProjectFKPK, idModuleFKPK, idRequerimentPK); if (requeriment == null) { return(HttpNotFound()); } return(View(requeriment)); }
public static List <User> GetUsersByLocation(Requeriment requeriment) { Message.Info(string.Format("Calling to public instagram Api for getting the last publications of location '{0}'. [()]. ", requeriment.QuerySearch)); //GET THE LOCATION ID RequestService serviceRequestLocation = new RequestService(); string requestUrlIdLocation = string.Format("https://www.instagram.com/web/search/topsearch/?context=blended&query={0}", requeriment.QuerySearch); dynamic jsonLocation = serviceRequestLocation.GetJsonDataFromAPI(requestUrlIdLocation); string idLocation = jsonLocation["places"][0]["place"]["location"]["pk"]; string locationName = jsonLocation["places"][0]["place"]["location"]["name"]; Message.Info(string.Format("Name location '{0}'. [()]. ", locationName)); Message.Info(string.Format("Id location '{0}'. [()]. ", idLocation)); //FORM THE REQUEST URL string requestUrl = string.Format("https://www.instagram.com/explore/locations/{0}/?__a=1", idLocation); List <User> usersList = new List <User>(); try { usersList = GetUsersByHashtagAndLocation(requeriment, requestUrl, idLocation); } catch (Exception e) { } return(usersList); }
public ActionResult Edit([Bind(Include = "idProjectFKPK,idModuleFKPK,idRequerimentPK,idEmployeeFK,objective,estimatedDuration,realDuration,status,startingDate,endDate,complexity")] Requeriment requeriment) { if (ModelState.IsValid) { if (requeriment.startingDate < requeriment.endDate) { int OidModuleFKPK = Convert.ToInt32(Request["idModuleFKPK"]); if (OidModuleFKPK != requeriment.idModuleFKPK) { var reqToDelete = db.Requeriment.Where(r => r.idModuleFKPK == OidModuleFKPK && r.idProjectFKPK == requeriment.idProjectFKPK && r.idRequerimentPK == requeriment.idRequerimentPK).FirstOrDefault(); db.Requeriment.Remove(reqToDelete); db.Requeriment.Add(requeriment); } else { db.Entry(requeriment).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("startingDate", "La fecha de inicio no puede ser despues de la fecha de finalización."); } } ViewBag.idModuleFKPK = new SelectList(db.Module.Where(x => x.idProjectFKPK == requeriment.idProjectFKPK), "idModulePK", "name", requeriment.idModuleFKPK); var employeeController = new EmployeesController(); ViewBag.idEmployeeFK = employeeController.EmployeeFromTeamSelectList(requeriment.idProjectFKPK, Convert.ToInt32(requeriment.idEmployeeFK)); ViewBag.complexity = SelectListComplexity(requeriment.complexity); ViewBag.status = SelectListStatus(requeriment.status); return(View(requeriment)); }
public ActionResult DeleteConfirmed(int?idProjectFKPK, int?idModuleFKPK, int?idRequerimentPK) { Requeriment requeriment = db.Requeriment.Find(idProjectFKPK, idModuleFKPK, idRequerimentPK); db.Requeriment.Remove(requeriment); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Requeriments/Delete/5 //EFE: Elimina el requerimiento seleccionado. public ActionResult Delete(int?idProjectFKPK, int?idModuleFKPK, int?idRequerimentPK) { if (idProjectFKPK == null || idModuleFKPK == null || idRequerimentPK == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Requeriment requeriment = db.Requeriment.Find(idProjectFKPK, idModuleFKPK, idRequerimentPK); if (requeriment == null) { return(HttpNotFound()); } return(View(requeriment)); }
public static List <User> GetUsersByHashtag(Requeriment requeriment) { string requestUrl = string.Format("https://www.instagram.com/explore/tags/{0}/?__a=1", requeriment.QuerySearch); List <User> usersList = new List <User>(); try { usersList = GetUsersByHashtagAndLocation(requeriment, requestUrl); } catch (Exception e) { } return(usersList); }
// GET: Requeriments/Create //EFE: Crea un requerimieno ya asociado a un módulo y proyecto public ActionResult Create(int?idProjectFKPK, int?idModuleFKPK) { if (idProjectFKPK == null || idModuleFKPK == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var moduleController = new ModulesController(); var employeeController = new EmployeesController(); Module module = moduleController.GetModule(idProjectFKPK, idModuleFKPK); Requeriment requeriment = new Requeriment { Module = module, idModuleFKPK = module.idModulePK, idProjectFKPK = module.idProjectFKPK }; ViewBag.idEmployeeFK = employeeController.EmployeeFromTeamSelectList((int)idProjectFKPK, null); ViewBag.complexity = SelectListComplexity(null); ViewBag.status = SelectListStatus(null); return(View(requeriment)); }
// GET: Requeriments/Edit/5 //EFE: Edita un requerimiento seleccionado public ActionResult Edit(int?idProjectFKPK, int?idModuleFKPK, int?idRequerimentPK) { if (idProjectFKPK == null || idModuleFKPK == null || idRequerimentPK == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Requeriment requeriment = db.Requeriment.Find(idProjectFKPK, idModuleFKPK, idRequerimentPK); if (requeriment == null) { return(HttpNotFound()); } var employeeController = new EmployeesController(); ViewBag.idEmployeeFK = employeeController.EmployeeFromTeamSelectList(requeriment.idProjectFKPK, Convert.ToInt32(requeriment.idEmployeeFK)); ViewBag.idModuleFKPK = new SelectList(db.Module.Where(x => x.idProjectFKPK == idProjectFKPK), "idModulePK", "name", requeriment.idModuleFKPK); ViewBag.complexity = SelectListComplexity(requeriment.complexity); ViewBag.status = SelectListStatus(requeriment.status); return(View(requeriment)); }
public ActionResult Create([Bind(Include = "idProjectFKPK,idModuleFKPK,idRequerimentPK,idEmployeeFK,estimatedDuration,realDuration,status,startingDate,endDate,complexity,objective")] Requeriment requeriment) { if (ModelState.IsValid) { if (requeriment.startingDate < requeriment.endDate) { db.Requeriment.Add(requeriment); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("startingDate", "La fecha de inicio no puede ser despues de la fecha de finalización."); } } var employeeController = new EmployeesController(); ViewBag.idEmployeeFK = employeeController.EmployeeFromTeamSelectList(requeriment.idProjectFKPK, Convert.ToInt32(requeriment.idEmployeeFK)); ViewBag.complexity = SelectListComplexity(requeriment.complexity); ViewBag.status = SelectListStatus(requeriment.status); return(View(requeriment)); }
public static void ExecuteAnalysis() { Message.Info("--------------"); Message.Info("Start analysis"); Message.Info("--------------"); try { int numberUsersToAnalyce = 7777; //string querySearchLarge = "Madrid, Spain";//12002362 //string querySearchLarge = "Pozuelo de Alarcón, Madrid";//101331 //string querySearchLarge = "Madrid, España";//62588 //string querySearchLarge = "Plaza Mayor, Madrid";//256867 //string querySearchLarge = "Puerta del Sol Madrid";//988566 //string querySearchLarge = "Alcobendas, Spain";//109674 //string querySearchLarge = "La Moraleja";//34261 //string querySearchLarge = "San Sebastián de los Reyes";//102697 //string querySearchLarge = "Centro Comercial Plaza Norte 2";//18935 //string querySearchLarge = "Moncloa-Aravaca";//2199 //string querySearchLarge = "Gran Vía, Madrid, España";//93997 //string querySearchLarge = "Tres Cantos, Madrid, Spain";// //string querySearchLarge = "Majadahonda, Madrid, Spain";//126502 //string querySearchLarge = "Hortaleza, Madrid, Spain";//14793 // string querySearchLarge = "Aravaca, Madrid, Spain";//21118//***** // string querySearchLarge = "Ciudad Universitaria";//1813 //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// //string querySearchLarge = ;// #region Declarations string databaseName = "azureFaceInstagram"; List <User> usersList = new List <User>(); var watch = System.Diagnostics.Stopwatch.StartNew(); Requeriment requeriments = new Requeriment(); Random rnd = new Random(); #endregion //todo parameterize in app-config or mvc and get all block to another method, //todo especify others accounts #region Search parameters var minFollows = "0"; var minFollowers = "0"; var maxFollows = "99999999"; var maxFollowers = "9999999"; var maxEngagement = "99.9"; var minEngagement = "0"; string searchType = "Location"; string hashtagsRequired = ""; List <string> searchQueryList = querySearchLarge.Split(',').ToList(); string querySearch = searchQueryList[rnd.Next(0, searchQueryList.Count() - 1)]; Message.Info(string.Format("Location founded ({0}). [()]", querySearch)); var tttttt = 0; #endregion #region Set parameters to Requeriment object requeriments.MinNumberFollows = Int32.Parse(minFollows); requeriments.MaxNumberFollows = Int32.Parse(maxFollows); requeriments.MinNumberFollowers = Int32.Parse(minFollowers); requeriments.MaxNumberFollowers = Int32.Parse(maxFollowers); requeriments.NumberUsersToAnalyce = numberUsersToAnalyce; requeriments.MaxEngagement = Double.Parse(maxEngagement); requeriments.MinEngagement = Double.Parse(minEngagement); requeriments.HashtagsRequired = hashtagsRequired.Split(',').ToList(); requeriments.QuerySearch = querySearch; requeriments.SearchType = searchType; #endregion CRUDMongo.CreateRequeriment(requeriments, databaseName); if (requeriments.SearchType == "Location") { requeriments.IsLocationSearch = true; Message.Info("- Trying to get Location users. [()]"); usersList = APITools.GetUsersByLocation(requeriments); #region Preparing the return user list List <User> UsersToShow = new List <User>(); foreach (var user in usersList) { if (user.IsGirl && !user.IsBusinessAccount) { UsersToShow.Add(user); } } #endregion HtmlGenerationTools.GenerateHtmlFileForShowUsers(UsersToShow, requeriments); Message.Info(string.Format("{0} users showed in html file. [()]", UsersToShow.Count())); CRUDMongo.CreateUser(usersList, "location", databaseName); Message.Info(string.Format("{0} users inserted in database. [()]", usersList.Count())); } else if (requeriments.SearchType == "Hashtag") { requeriments.IsHashtagSearch = true; usersList = APITools.GetUsersByHashtag(requeriments); CRUDMongo.CreateUser(usersList, "hashtag", databaseName); } else if (requeriments.SearchType == "UserName") { requeriments.IsUserNameSearch = true; CRUDMongo.CreateUser(usersList, "userName", databaseName); } #region Printing to log file Message.Info("---------------Finish process--------------------"); #endregion } catch (Exception e) { #region Printing to log file Message.Info(string.Format("Exception ocurred. Message: {0}", e.Message)); #endregion } }
public static void GenerateHtmlFileForShowUsers(List <User> userList, Requeriment requeriments) { DateTime date = DateTime.Now; string currentDate = date.ToString("yyyy-dd-M-HH-mm-ss"); string path = string.Format(@"C:\file_{0}_{1}.html", requeriments.QuerySearch.Replace(" ", "_"), currentDate); if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("<html>"); sw.WriteLine("<script>"); sw.WriteLine(""); sw.WriteLine("</script>"); sw.WriteLine("<head>"); //sw.WriteLine("<link rel='stylesheet' type='text/css' href='../css/styles.css'>"); sw.WriteLine("<head>"); sw.WriteLine("<body style='text-align:center'>"); sw.WriteLine("<h3>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("<b>Location:</b> " + requeriments.QuerySearch); sw.WriteLine("<br>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("<b>Users analized: </b>" + requeriments.NumberUsersToAnalyce); sw.WriteLine("<br>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("<b>Users number: </b>" + userList.Count()); sw.WriteLine("<br>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("</h3>"); int countUsers = 0; foreach (var user in userList) { if (true) { countUsers += 1; try { sw.WriteLine("<div class='user'>"); sw.WriteLine("<>"); sw.WriteLine("<>"); sw.WriteLine("--------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("--------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("</h4>"); sw.WriteLine("<a style='display: inline;border-radius: 50%;' href='" + user.ProfilePicture + "' target=''><img src='" + user.ProfilePicture + "' alt='' style='display:inline;border-radius: 50%;' height='200' width='200'></a>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("<b>Username</b>: " + user.Name); sw.WriteLine("<br>"); sw.WriteLine("<b>Followers</b>: " + user.FollowersNumber); sw.WriteLine("<br>"); sw.WriteLine("<b>Following</b>: " + user.FollowsNumber); sw.WriteLine("<br>"); sw.WriteLine("<b>Engagemen</b>:" + user.Engagement); sw.WriteLine("</h4>"); sw.WriteLine("<br>"); sw.WriteLine("<b>User location</b>: " + user.Location); sw.WriteLine("<br>"); sw.WriteLine("Age</b>: " + user.Age); sw.WriteLine("<br>"); sw.WriteLine("<b>Description</b>: <br>" + user.Description); sw.WriteLine("<br>"); sw.WriteLine("</h4>"); sw.WriteLine(""); sw.WriteLine("<div class='hiddenBlock'>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); int countPubs = 0; foreach (var pub in user.Publications) { sw.WriteLine("<a style='display: inline; margin: 0 5px;' href='" + pub.Url + "' target=''><img src='" + pub.ImageUrl + "' alt='' style='display:inline' height='400' width='400'></a>"); sw.WriteLine("<br>"); countPubs++; if (countPubs >= 6) { break; } } sw.WriteLine("</div>"); sw.WriteLine("<br>"); sw.WriteLine("--------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("<a href='" + user.Url + "' target='_blank'>" + user.Name + "</a>"); sw.WriteLine("<br>"); sw.WriteLine("--------------------------------------------------------------------------------------------------"); sw.WriteLine("--------------------------------------------------------------------------------------------------"); sw.WriteLine("</div>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("<hr>"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); } catch (Exception e) { Console.WriteLine(e.Message); } } } sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("<br>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("<br>"); sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------"); sw.WriteLine("</body>"); sw.WriteLine("</html>"); } } }
public static List <User> GetUsersByHashtagAndLocation(Requeriment requeriment, string requestUrl, string idLocation = "0") { Message.Info("---------Starting Instagram method [GetUsersByHashtagAndLocation()]----------"); var MaxUsersNumberToAnalize = requeriment.NumberUsersToAnalyce; #region Declarations Random rnd = new Random(); List <string> usersAnalized = new List <string>(); RequestService serviceRequest = new RequestService(); List <User> usersList = new List <User>(); List <User> FinalUserList = new List <User>(); bool doNewRequest = true; int countUsers = 0; int countPublications = 0; int usersDescarted = 0; const string uriBase = "https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect"; const string requestParameters = "?returnFaceAttributes=age,gender"; const string uri = uriBase + requestParameters; #endregion List <string> usernamesAnalizedHistorical = new List <string>(); string userNameAnalizedTextFileRoute = @"C:\GirlsInstagram\userNameAnalyzedFaceApi.txt"; #region Getting followers name from file string followersNameText = File.ReadAllText(userNameAnalizedTextFileRoute); usernamesAnalizedHistorical = followersNameText.Split(',').ToList(); #endregion #region Getting users from database //List<User> usersExistingInDataBase = CRUDMongo.GetUsers(999999, databaseName); List <User> usersExistingInDataBase = new List <User>(); #endregion dynamic jsonData = serviceRequest.GetJsonDataFromAPI(requestUrl); string publicationsNumberOfLocation = jsonData["graphql"]["location"]["edge_location_to_media"]["count"]; Message.Info(string.Format("Publications number of current location: {0}----------------. [GetUsersByHashtagAndLocation()]", publicationsNumberOfLocation)); if (jsonData == null) { throw new Exception("Error, the json data is null. [GetUsersByHashtagAndLocation()]"); } while (doNewRequest) { dynamic jsonMentions; bool hasNextPage; Message.Info("Getting data of the 'publications' json response. [GetUsersByHashtagAndLocation()]. "); #region Get data of the 'publications' json response if (requeriment.IsHashtagSearch) { var VolumeSearchElement = jsonData["graphql"]["hashtag"]["edge_hashtag_to_media"]["count"]; var SearchElement = jsonData["graphql"]["hashtag"]["name"]; hasNextPage = jsonData["graphql"]["hashtag"]["edge_hashtag_to_media"]["page_info"]["has_next_page"]; dynamic jsonTopMentions = jsonData["graphql"]["hashtag"]["edge_hashtag_to_top_posts"]; jsonMentions = jsonData["graphql"]["hashtag"]["edge_hashtag_to_media"]["edges"]; } else if (requeriment.IsLocationSearch) { var SearchElement = jsonData["graphql"]["location"]["name"]; var VolumeSearchElement = jsonData["graphql"]["location"]["edge_location_to_media"]["count"]; hasNextPage = jsonData["graphql"]["location"]["edge_location_to_media"]["page_info"]["has_next_page"]; dynamic jsonTopMentions = jsonData["graphql"]["location"]["edge_location_to_top_posts"]; jsonMentions = jsonData["graphql"]["location"]["edge_location_to_media"]["edges"]; if (!hasNextPage) { int vbsdfgbsdbs = 0; } } else { var SearchElement = requeriment.QuerySearch; var VolumeSearchElement = jsonData["users"].Count.ToString(); jsonMentions = jsonData["users"]; hasNextPage = false; } #endregion Message.Info("Looping data of the 'publications/users' from json response. [GetUsersByHashtagAndLocation()]"); foreach (var jsonMention in jsonMentions) { countPublications += 1; try { bool isValidUser = true; Thread.Sleep(rnd.Next(66, 104)); if (isValidUser) { #region Assign the jsonMedia depending of the search type dynamic jsonMedia; if (requeriment.IsHashtagSearch || requeriment.IsLocationSearch) { //GET OTHER JSON WITH MORE INFO OF THE PUBLICATION string prefixUrlRequest = "__a=1"; string requestUrlMedia = string.Format("https://www.instagram.com/p/{0}/?{1}", jsonMention["node"]["shortcode"], prefixUrlRequest); jsonMedia = serviceRequest.GetJsonDataFromAPI(requestUrlMedia); Thread.Sleep(rnd.Next(44, 99)); } else { jsonMedia = jsonMention; } #endregion Thread.Sleep(rnd.Next(44, 86)); if (jsonMedia != null) { //Message.Info("- Trying to getting data of the current user. [GetUsers()]"); #region Getting data of the user and extruct info about him string nicknameUser; string profilePicture; if (requeriment.IsHashtagSearch || requeriment.IsLocationSearch) { nicknameUser = jsonMedia["graphql"]["shortcode_media"]["owner"]["username"]; profilePicture = jsonMedia["graphql"]["shortcode_media"]["owner"]["profile_pic_url"]; } else { nicknameUser = jsonMedia["user"]["username"]; profilePicture = jsonMedia["user"]["profile_pic_url"]; } #endregion if (!usernamesAnalizedHistorical.Contains(nicknameUser)) { if (!usersAnalized.Contains(nicknameUser)) { countUsers++; Message.Info(""); Message.Info(string.Format("{0} . -------------Analizing instagram user: {1}----------------. [GetUsersByHashtagAndLocation()]", countUsers, nicknameUser)); string urlRequestUser = string.Format("https://www.instagram.com/{0}/", nicknameUser); var sourceHtmlText = serviceRequest.GetSourceHtmlCodeOfUrl(urlRequestUser); dynamic jsonContentUser = null; int indexCommaPoint = 0; try { int initIndex = sourceHtmlText.IndexOf("window._sharedData = "); string auxiliarText = sourceHtmlText.Substring(initIndex); indexCommaPoint = auxiliarText.IndexOf(";"); while (auxiliarText[indexCommaPoint + 1] != '<') { Message.Info("- Cleaning the description user for get the good json for parse. [GetUsersByHashtagAndLocation()]"); var newAuxString = new StringBuilder(auxiliarText); newAuxString[indexCommaPoint] = ' '; auxiliarText = newAuxString.ToString(); indexCommaPoint = auxiliarText.IndexOf(";"); } auxiliarText = auxiliarText.Substring(0, indexCommaPoint); string stringJsonContentUserFormatted = auxiliarText.Replace("window._sharedData = ", "").Replace(";", ""); jsonContentUser = JsonConvert.DeserializeObject(stringJsonContentUserFormatted); } catch (Exception e) { //indexCommaPoint = sourceHtmlText.Substring(indexCommaPoint).IndexOf(";"); throw new Exception(e.Message); } Thread.Sleep(rnd.Next(87, 227)); Message.Info("- Getting data to check is user not exceed the requeriments(followers/s number). [GetUsersByHashtagAndLocation()]"); #region Getting data of user var jsonAuthor = jsonContentUser["entry_data"]["ProfilePage"][0]; int follows = jsonAuthor["graphql"]["user"]["edge_follow"]["count"]; int followers = jsonAuthor["graphql"]["user"]["edge_followed_by"]["count"]; var isBusinessNode = jsonAuthor["graphql"]["user"]["is_business_account"]; #endregion if (!Boolean.Parse(isBusinessNode.ToString())) { Message.Info("- Trying to complete the user data with the extra information. [GetUsersByHashtagAndLocation()]"); //Creating a user and adding to userList GetUser(jsonAuthor, requeriment, usersList, nicknameUser, followers, follows); //var UsersAnalizedNumber = usersList.Count(); usersAnalized.Add(nicknameUser); var user = usersList[usersList.Count() - 1]; //todo: if user is girl add attribute string imgUrl = user.Publications[0].ImageUrl; dynamic jsonUserImageData = serviceRequest.GetJsonDataFromAPIAzureVisionApi(uri, imgUrl); if (jsonUserImageData != null) { bool isGirlControl = false; int countPeople = 0; foreach (var person in jsonUserImageData) { countPeople++; try { var gender = person["faceAttributes"]["gender"]; var age = person["faceAttributes"]["age"]; if (gender == "female" && (age < 33 && age > 19)) { isGirlControl = true; Message.Info("- Girl founded. [()]"); user.Age = age; user.Gender = gender; break; } else { } } catch (Exception e) { } } if (isGirlControl) { if (countPeople > 1) { dynamic jsonUserProfileImageData = serviceRequest.GetJsonDataFromAPIAzureVisionApi(uri, user.ProfilePicture); if (jsonUserProfileImageData != null) { try { var genderp = jsonUserProfileImageData[0]["faceAttributes"]["gender"]; var agep = jsonUserProfileImageData[0]["faceAttributes"]["age"]; if (genderp == "female" && (agep < 33 && agep > 19)) { user.IsGirl = true; Message.Info("- Girl founded confirmed with image profile. [()]"); } else { Message.Info("- User descarted confirmed with image profile. [()]"); } } catch (Exception e) { } } else { Message.Info("- Error Face API trying to get data of image. [()]"); user.IsGirl = true; } } else { user.IsGirl = true; } } else { Message.Info("- User descarted. [()]"); } } else { Message.Info("- The json azure api returned is null. [()]"); } } else { Message.Info("- The current instagram user is commercial account. [()]"); } } else { usersAnalized.Remove(nicknameUser); usersDescarted++; #region Printing in log file Message.Info(""); Message.Info(string.Format("-------------Analizing instagram user: {0}----------------. [GetUsersByHashtagAndLocation()]", nicknameUser)); Message.Info(string.Format("- User descarted because already analyced in current process ({0} users descarted).", usersDescarted)); #endregion } } else { Message.Info(""); Message.Info(string.Format("-------------Analizing instagram user: {0}----------------. [GetUsersByHashtagAndLocation()]", nicknameUser)); Message.Info(string.Format("- Users already analyced in another process. Users descarted: {0}. [()]", usersDescarted)); usersAnalized.Remove(nicknameUser); usersDescarted++; } #region Checking if all users have already been followed if (usersAnalized.Count() >= requeriment.NumberUsersToAnalyce) { hasNextPage = false; Message.Info(string.Format("- Users obtained completed: {0}. [()]", usersAnalized.Count())); break; } #endregion } else { #region Printing in log file Message.Info(string.Format("{0}. This instagram publication data json null . [()]", countPublications)); #endregion } } else { #region Printing in log file Message.Info(string.Format("{0}. The user is discarted by he dont use any of required hashtags when search by location.", countPublications)); #endregion } #region Contol if has been exceded the publication number limit if (countPublications > 5555555) { hasNextPage = false; var ExtraMessage = string.Format("The publications number limit has been exedeed. Number users analized: {0}", usersList.Count); Message.Info(ExtraMessage); doNewRequest = false; Message.Info(string.Format("- Users obtained: {0}. [()]", usersAnalized.Count())); break; } else if (MaxUsersNumberToAnalize <= countPublications) { Message.Info(""); Message.Info(String.Format("Max Users/publications Number To Analize reached.{0} users. [GetUsersByHashtagAndLocation()]", MaxUsersNumberToAnalize)); doNewRequest = false; Message.Info(string.Format("- Users obtained: {0}. [()]", usersAnalized.Count())); break; } #endregion } catch (Exception e) { #region Printing in log file Message.Error(string.Format("Error ocurred trying a jsonMention, Message: {0}", e.Message)); #endregion } } #region Geting the new JSON data if exist next page if (hasNextPage) { Message.Info("- Geting the new JSON data if exist next page. [GetUsersByHashtagAndLocation()]"); jsonData = GetNextPageJsonPublications(jsonData, requeriment.QuerySearch, requestUrl, requeriment.IsHashtagSearch, idLocation); Thread.Sleep(rnd.Next(11, 132)); } else { Message.Info("- Not exist next page. [GetUsersByHashtagAndLocation()]"); Message.Info(string.Format("The publications analyced. Number users analized: {0}", countPublications)); doNewRequest = false; } #endregion } usersList = usersList.GroupBy(x => x.Name).Select(x => x.First()).ToList(); #region Preparing the return user list foreach (var user in usersList) { usernamesAnalizedHistorical.Add(user.Name); } #endregion #region Writing in a file Message.Info(""); Message.Info(string.Format("Save the all username historycal, {0} users.", usernamesAnalizedHistorical.Count())); Message.Info(""); string usernamesText = String.Join(",", usernamesAnalizedHistorical); string userNameFollowersTextFileRoute = userNameAnalizedTextFileRoute; System.IO.File.WriteAllText(userNameFollowersTextFileRoute, string.Empty); System.IO.File.WriteAllText(userNameFollowersTextFileRoute, usernamesText); #endregion return(usersList); }
public static User GetUser(dynamic jsonAuthor, Requeriment requeriment, List <User> usersList, string nicknameUser, int followers, int follows) { var isBusinessNode = jsonAuthor["graphql"]["user"]["is_business_account"]; User user = new User() { OriginId = jsonAuthor["graphql"]["user"]["id"], ProfilePicture = jsonAuthor["graphql"]["user"]["profile_pic_url"], IsHashtagSearch = true, querySearch = requeriment.QuerySearch, Name = nicknameUser, FollowersNumber = followers, FollowsNumber = follows, PublicationsNumber = jsonAuthor["graphql"]["user"]["edge_owner_to_timeline_media"]["count"], Url = "https://www.instagram.com/" + nicknameUser, Description = jsonAuthor["graphql"]["user"]["biography"], ExternalUrl = jsonAuthor["graphql"]["user"]["external_url"], //dateFollowing = DateTime.Now, DateFoundAnalized = DateTime.Now, IsBusinessAccount = Boolean.Parse(isBusinessNode.ToString()) }; //assign register date of user the date of the first publication dynamic publicationNodes = jsonAuthor["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"]; int count = publicationNodes.Count; dynamic firstPublicationJson = jsonAuthor["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][count - 1]; var date = firstPublicationJson["node"]["taken_at_timestamp"]; user.Date = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Convert.ToDouble(date)); var nodesPublications = jsonAuthor["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"]; int summationLikes = 0; int summationComments = 0; int countPublications = 0; Dictionary <string, int> HashtagVolume = new Dictionary <string, int>(); //CREATE THE FIRST 12 PUBLICATIONS OF EACH USER foreach (var jsonPublication in nodesPublications) { countPublications++; Publication publication = GetPublication(jsonPublication, HashtagVolume); //not add the likes and comments of the first publication for not affect to averages and engagement if (countPublications != 1) { summationComments += publication.CommentsNumber; summationLikes += publication.LikesNumber; } user.Publications.Add(publication); } //assign the popular location to user user.Location = user.Publications.Select(p => p.Location).Max(); //rest one because the first publication of user not is not add to summation user.LikesPerPublication = Math.Round((double)summationLikes / (double)countPublications - 1.0, 2); user.CommentsPerPublication = Math.Round((double)summationComments / (double)countPublications - 1.0, 2); if (user.CommentsPerPublication < 0) { user.CommentsPerPublication += 1; } //calculate the engagement user.Engagement = Math.Round((double)(user.LikesPerPublication + user.CommentsPerPublication) / user.FollowersNumber * 100, 2); if (user.Engagement > requeriment.MinEngagement && user.Engagement < requeriment.MaxEngagement) { usersList.Add(user); } else { //InstagramMessage.Info(""); //InstagramMessage.Info("User discarded, he does not satisfy the engagement requirement."); //InstagramMessage.Info(""); } //GET THE FIRST 10 HASHTAG MORE USED FOR THE USER user.HashtagVolume = HashtagVolume.OrderByDescending(h => h.Value).Take(10).ToDictionary(x => x.Key, x => x.Value); return(user); }