Exemplo n.º 1
0
        // The results from this method grows very fast,
        // between O(2n) to O(10n), so mostly speaking we don't need to worry about running out cache.
        private async Task grabKeywords(string defaultTerm = "test")
        {
            var crawler = new UrbanDictController();
            var result  = await crawler.QueryByTerm(defaultTerm);

            foreach (string keyword in result.Tags)
            {
                Console.WriteLine("[INFO] Grabbing keywords: " + keyword);
                if (keywordList.ContainsKey(keyword))
                {
                    keywordList.Add(keyword, false);
                }
                else
                {
                    Console.WriteLine("[INFO] Keyword " + keyword + " already cached.");
                }
            }
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Urban Dictionary DotNET Client");
            Console.WriteLine("By Jackson Ming Hu @ RMIT University 2016");
            Console.Write("Enter a word or phrase you would like to search: ");
            string queryStr = Console.ReadLine();

            UrbanDictController crawler = new UrbanDictController();
            var result = crawler.QueryByTerm(queryStr).Result;             // Add the ".Result" since we are not using async here.

            Console.WriteLine("\n\nYou've got " + result.ItemList.Count.ToString() + " results.\n");

            for (int i = 0; i < result.ItemList.Count; i++)
            {
                Console.WriteLine("*****************************************");
                Console.WriteLine("The #" + i.ToString() + " author is: " + result.ItemList[i].Author);
                Console.WriteLine("The #" + i.ToString() + " result is: \n\n" + result.ItemList[i].Definition);
                Console.WriteLine("*****************************************\n\n");
            }
        }
Exemplo n.º 3
0
        private async Task grabContent()
        {
            foreach (KeyValuePair <string, bool> queryPair in keywordList)
            {
                // Only grab the content if the list is valid (not yet been crawled)
                if (queryPair.Value)
                {
                    Console.WriteLine("[INFO] Grabbing contents for keyword: " + queryPair.Key);
                    var crawler = new UrbanDictController();
                    var result  = await crawler.QueryByTerm(queryPair.Key);

                    ubGrabber.ContentToXml(result, queryPair.Key);

                    // Refresh the value to "false"
                    //  to indicate the keyword item ifself has been crawled.
                    keywordList.Remove(queryPair.Key);
                    keywordList.Add(queryPair.Key, false);
                }
                else
                {
                    Console.WriteLine("[INFO] Content for keyword " + queryPair.Key + " has been crawled.");
                }
            }
        }