Beispiel #1
0
        public static List <MedItem> getMedItems(string query)
        {
            string             url           = string.Format("https://www.1mg.com/search/all?name={0}", query);
            var                web           = new HtmlWeb();
            var                doc           = web.Load(url);
            List <MedItem>     meds          = new List <MedItem>();
            HtmlNodeCollection MedicineName  = doc.DocumentNode.SelectNodes("//*[contains(concat( ' ', @class, ' ' ),concat( ' ', 'style__pro-title___3zxNC', ' ' ))]");
            HtmlNodeCollection MedicineType  = doc.DocumentNode.SelectNodes("//*[contains(concat( ' ', @class, ' ' ), concat( ' ', 'style__pack-size___254Cd', ' ' ))]");
            HtmlNodeCollection MedicinePrice = doc.DocumentNode.SelectNodes("//*[contains(concat( ' ', @class, ' ' ), concat( ' ', 'style__price-tag___B2csA', ' ' ))]");
            HtmlNodeCollection MedicineUrl   = doc.DocumentNode.SelectNodes("//*[(@id = 'category-container')]//a");
            HtmlNodeCollection MedicineImage = doc.DocumentNode.SelectNodes("//img[contains(@class,'style__image___Ny-Sa')]");
            string             baseLink      = "https://www.1mg.com";

            for (int i = 0; i < MedicineName.Count; i++)
            {
                string name     = MedicineName[i].InnerText;
                string medType  = MedicineType[i].InnerText;
                string medPrice = MedicinePrice[i].InnerText;
                Uri    medUrl   = new Uri(baseLink + MedicineUrl[i].GetAttributeValue("href", ""));
                //Uri ImageMedUrl = new Uri(MedicineImage[i].GetAttributeValue("src", "https://image.flaticon.com/icons/svg/172/172835.svg"));
                MedItem item = new MedItem(name, medType, medPrice, medUrl);
                Console.WriteLine(item.ToString());
                meds.Add(item);
            }
            Console.WriteLine(meds.Count.ToString());
            return(meds);
        }
Beispiel #2
0
        private void GetResults_Click(object sender, EventArgs e)
        {
            if (!(userInputBox.Text == null && userInputBox.Text.Equals("")))
            {
                var    client  = new RestClient("https://api.lexigram.io/v1/extract/entities");
                string API_KEY = Environment.GetEnvironmentVariable("MED_BOT_KEY", EnvironmentVariableTarget.Machine);
                var    request = new RestRequest(Method.POST);
                request.AddHeader("content-type", "application/json");
                request.AddHeader("authorization", string.Format("Bearer {0}", API_KEY));
                MedRequestObject reqBody = new MedRequestObject(userInputBox.Text);
                request.AddJsonBody(reqBody);
                IRestResponse response     = client.Execute(request);
                JObject       jsonResp     = JObject.Parse(response.Content);
                JArray        matchesArray = (JArray)jsonResp.GetValue("matches");

                ArrayList medicines = new ArrayList();
                foreach (JObject temp in matchesArray)
                {
                    bool isDrug = false;
                    foreach (JToken typeToken in temp.GetValue("types"))
                    {
                        isDrug = typeToken.ToString().Equals("DRUGS");
                    }
                    if (isDrug)
                    {
                        string  medicine    = "";
                        JObject explanation = (JObject)temp.GetValue("explanation");
                        foreach (JObject token in explanation.GetValue("matchedTokens"))
                        {
                            medicine += token.GetValue("token") + " ";
                        }
                        if (!(medicine == "" && medicines.Contains(medicine)))
                        {
                            medicines.Add(medicine);
                            Console.WriteLine(medicine);
                        }
                        Console.WriteLine("Medicine name " + medicines.Count.ToString());
                    }
                }
                foreach (string medName in medicines)
                {
                    List <MedItem> medies = MedItem.getMedItems(medName);
                    Console.WriteLine(medies.Count.ToString());
                    this.totalMedItems = this.totalMedItems.Union(medies);
                }

                updateListView();
                userInputBox.Text = null;
            }
        }