Esempio n. 1
0
        public async Task <TwitterFollowPageModel> GetFollowerAsync(string username, string cursor = "-1")
        {
            var url     = AddressLocator.Follower(username, cursor);
            var htmlDoc = await HtmlLoader.TryLoadAndParsePageAsync(url, GetRandomProxy(), false, false);

            if (htmlDoc != null)
            {
                if (HtmlExtracter.TryParseFollower(htmlDoc, out var followerPage))
                {
                    followerPage.BelongUserName = username;
                    return(followerPage);
                }
            }
            return(null);
        }
Esempio n. 2
0
        public async Task <TwitterTweetPageModel> GetUserTweetsAsync(TwitterOption option, Dictionary <string, string> paramDict)
        {
            var url = $"{AddressLocator.Web}/search/timeline";

            url = AddressLocator.SanitizeQuery(url, paramDict);
            var htmlSource = await HtmlLoader.TryLoadPageAsync(url, GetRandomProxy(), true, false);

            if (!string.IsNullOrEmpty(htmlSource))
            {
                if (RawTweetPage.TryParse(htmlSource, out var rawPage))
                {
                    var           parser  = new HtmlParser();
                    IHtmlDocument htmlDoc = null;
                    try
                    {
                        htmlDoc = await parser.ParseDocumentAsync(rawPage.ItemsHtml);
                    }
                    catch (Exception)
                    {
                    }

                    if (htmlDoc != null)
                    {
                        if (HtmlExtracter.TryParseTweet(option, htmlDoc, out var pageModel))
                        {
                            pageModel.NextPageParams = new Dictionary <string, string>(paramDict);
                            pageModel.HasNext        = rawPage.HasMoreItems;
                            pageModel.SetMaxPosition(rawPage.MinPosition);
                            pageModel.Options = option;
                            return(pageModel);
                        }
                    }
                }
            }


            return(null);
        }
Esempio n. 3
0
        private async void submitQueryListener(object sender, SearchView.QueryTextSubmitEventArgs e)
        {
            MainActivity act        = (MainActivity)this.Activity;
            SearchView   searchView = (SearchView)act.FindViewById(Resource.Id.searchView1);
            string       input      = e.Query;

            searchView.SetIconifiedByDefault(true);
            searchView.OnActionViewCollapsed();
            searchView.Focusable = false;

            //Ping database by name
            string data = GetData();

            JArray        jsonArray    = JArray.Parse(data);
            List <string> searched_Loc = new List <string>();
            List <string> similar_Loc  = new List <string>();

            string debugMe    = "";
            string tempinput  = input;
            string inputBlock = tempinput;

            tempinput = RemoveSpecialCharacters(tempinput);
            tempinput = tempinput.Replace(" ", System.String.Empty);

            AddressLocator        tempAddress;
            List <AddressLocator> mAddresses = new List <AddressLocator>();

            for (int i = 0; i < jsonArray.Count; i++)
            {
                JToken json = jsonArray[i];
                string temp = (string)json["name"];
                temp = RemoveSpecialCharacters(temp);
                temp = temp.Replace(" ", System.String.Empty);
                if (((string)json["name"]).Equals(input, StringComparison.InvariantCultureIgnoreCase) || temp.Equals(tempinput, StringComparison.InvariantCultureIgnoreCase))
                {
                    //Location stuff - make sure user location permissions were give
                    if (act.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) == (int)Android.Content.PM.Permission.Granted)
                    {
                        Geocoder        coder   = new Geocoder(act);
                        IList <Address> address = new List <Address>();


                        address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                        float lon = (float)address.ElementAt(0).Longitude;
                        float lat = (float)address.ElementAt(0).Latitude;

                        tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                        mAddresses.Add(tempAddress);


                        userLocationObtained = true;
                    }
                    else // if not, grab list like before.
                    {
                        searched_Loc.Add(((string)json["name"]) + ": " + ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]));
                    }
                }
            }

            if (userLocationObtained)
            {
                //calculate distances
                CalculateAddressDistance(mAddresses);
                //sort distances
                mAddresses.Sort();

                for (int x = 0; x < mAddresses.Count; x++)
                {
                    searched_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                }
            }

            for (int j = 0; j < searched_Loc.Count; j++)
            {
                debugMe += searched_Loc[j];
                debugMe += "\n";
            }

            if (searched_Loc.Count == 0)
            {
                for (int i = 0; i < jsonArray.Count; i++)
                {
                    JToken json      = jsonArray[i];
                    bool   wordMatch = false;
                    string temp      = (string)json["name"];

                    string[] outputBlock = temp.Split(" ");

                    temp = RemoveSpecialCharacters(temp);
                    temp = temp.Replace(" ", System.String.Empty);

                    wordMatch = InputsMatch(inputBlock.ToLower(), outputBlock);

                    if ((tempinput.StartsWith(temp.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) || wordMatch) && !userLocationObtained)
                    {
                        similar_Loc.Add(((string)json["name"]) + ": " + ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]));
                    }
                    else if ((tempinput.StartsWith(temp.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) || wordMatch) && userLocationObtained)
                    {
                        Geocoder        coder   = new Geocoder(act);
                        IList <Address> address = new List <Address>();


                        address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                        float lon = (float)address.ElementAt(0).Longitude;
                        float lat = (float)address.ElementAt(0).Latitude;

                        tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                        mAddresses.Add(tempAddress);
                    }
                }
                if (userLocationObtained)
                {
                    //calculate distances
                    CalculateAddressDistance(mAddresses);
                    //sort distances
                    mAddresses.Sort();

                    for (int x = 0; x < mAddresses.Count; x++)
                    {
                        similar_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                    }
                }
            }

            mTv = act.FindViewById <ListView>(Resource.Id.searchResults);
            ArrayAdapter <string> arrayAdapter;

            if (searched_Loc.Count == 0 && similar_Loc.Count == 0)
            {
                Toast.MakeText(MainActivity.activity, "There were no results for that Location.", ToastLength.Long).Show();
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, similar_Loc);
            }
            else if (searched_Loc.Count == 0)
            {
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, similar_Loc);
            }
            else
            {
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, searched_Loc);
            }

            mTv.Adapter = arrayAdapter;
            mTv.SetFooterDividersEnabled(true);
            mTv.SetHeaderDividersEnabled(true);
        }
Esempio n. 4
0
        private void searchNearMe(object sender, EventArgs e)
        {
            MainActivity MAct = (MainActivity)MainActivity.activity;
            MainActivity act  = (MainActivity)this.Activity;
            string       data = GetData();

            Button nearButton = (Button)act.FindViewById(Resource.Id.nearMe);

            nearButton.Enabled = false;

            if (MAct.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted)
            {
                RequestPermissions(new string[] { Android.Manifest.Permission.AccessCoarseLocation, Android.Manifest.Permission.AccessFineLocation }, 0);
            }

            JArray                jsonArray    = JArray.Parse(data);
            List <string>         searched_Loc = new List <string>();
            List <AddressLocator> mAddresses   = new List <AddressLocator>();
            AddressLocator        tempAddress;



            for (int i = 0; i < jsonArray.Count; i++)
            {
                JToken json = jsonArray[i];
                if (act.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) == (int)Android.Content.PM.Permission.Granted)
                {
                    Geocoder        coder   = new Geocoder(act);
                    IList <Address> address = new List <Address>();


                    address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                    float lon = (float)address.ElementAt(0).Longitude;
                    float lat = (float)address.ElementAt(0).Latitude;

                    tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                    mAddresses.Add(tempAddress);


                    userLocationObtained = true;
                }
                else
                {
                    Toast.MakeText(MainActivity.activity, "Cannot Calculate User Location. Please allow for the application to use location permissions.", ToastLength.Long).Show();
                }
            }

            if (userLocationObtained)
            {
                //calculate distances
                CalculateAddressDistance(mAddresses);
                //sort distances
                mAddresses.Sort();

                for (int x = 0; x < mAddresses.Count; x++)
                {
                    if (mAddresses.ElementAt(x).Distance < 15.00)
                    {
                        searched_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                    }
                }
            }

            mTv = act.FindViewById <ListView>(Resource.Id.searchResults);
            ArrayAdapter <string> arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, searched_Loc);

            mTv.Adapter = arrayAdapter;
            mTv.SetFooterDividersEnabled(true);
            mTv.SetHeaderDividersEnabled(true);
            nearButton.Enabled = true;
        }