Example #1
0
        public IActionResult Index([FromQuery] string k)
        {
            // Create the return object
            QueryResult queryResult = new QueryResult()
            {
                URL = null
            };

            // Return empty if no key specified in query string
            if (k == null || k == string.Empty)
            {
                return(View(queryResult));
            }

            // Make a connection to Cassandra and get a session
            CassandraConnection cassandraConnection = new CassandraConnection();
            ISession            csSession           = cassandraConnection.GetSession();

            URLLookup urlLookup = new URLLookup(csSession);

            // Get the actual long URL
            if (!urlLookup.LookupURL(k, out string url))
            {
                // Return NotFound page if key doesn't exist
                return(NotFound());
            }

            // Attache the URL to the result object
            queryResult.URL = url;

            // Return result
            return(View(queryResult));
        }
Example #2
0
        private void getJsonItems(string filename)
        {
            URLLookup uRLLookupChoreo = new URLLookup(session);

            // Set inputs
            uRLLookupChoreo.setAccessToken(accessToken);
            uRLLookupChoreo.setIDs(pageURL);

            // Execute Choreo
            URLLookupResultSet uRLLookupResults = uRLLookupChoreo.execute();

            // Print results
            //Console.WriteLine(uRLLookupResults.Response);
            string s_lookup = uRLLookupResults.Response;
            JObject json_lookup = JObject.Parse(s_lookup);

            string page_id = (string)json_lookup[pageURL]["id"];
            Console.WriteLine("page ID = " + page_id);

            GetObject getObjectChoreo = new GetObject(session);

            // Set inputs
            getObjectChoreo.setAccessToken(accessToken);
            getObjectChoreo.setFields("insights");
            getObjectChoreo.setObjectID(page_id);

            // Execute Choreo
            GetObjectResultSet getObjectResults = getObjectChoreo.execute();

            string search_it = getObjectResults.Response;
            JObject j_search_it = JObject.Parse(search_it);
            System.IO.StreamWriter file = new System.IO.StreamWriter(filename);

            int i = 0;
            string name_token = (string)j_search_it["insights"]["data"][0]["name"];

            while (name_token != null)
            {
                file.WriteLine("name: " + (string)j_search_it["insights"]["data"][i]["name"]);
                file.WriteLine("title: " + (string)j_search_it["insights"]["data"][i]["title"]);
                file.WriteLine("description: " + (string)j_search_it["insights"]["data"][i]["description"]);
                file.WriteLine("");
                i++;
                try
                {
                    name_token = (string)j_search_it["insights"]["data"][i]["name"];
                }
                catch
                {
                    name_token = null;
                }

            }
            file.Close();
        }
Example #3
0
        // find youtube videos on Facebook to determine how many times they have been shared
        public int GetFBYTVideoShares(string video_id)
        {
            URLLookup uRLLookupChoreo = new URLLookup(session);

            // Set inputs
            uRLLookupChoreo.setAccessToken(accessToken);
            string video_url = "https://www.youtube.com/watch?v=" + video_id;
            uRLLookupChoreo.setIDs(video_url);

            // Execute Choreo
            URLLookupResultSet uRLLookupResults = uRLLookupChoreo.execute();
            JObject json_response = JObject.Parse(uRLLookupResults.Response);
            string s_shares = "";
            try
            {
                s_shares = (string)json_response[video_url]["share"]["share_count"];
            }
            catch
            {
                s_shares = "0";
            }
            return int.Parse(s_shares);
        }