Exemplo n.º 1
0
        public void updateData()
        {
            try
            {
                Nresponse n = getArticles();
                if (n.status == "OK")
                {
                    if (n.result.docs != null)
                    {
                        foreach (Doc d in n.result.docs)
                        {
                            //If we don't already have the article, get sentiment info and add to DB
                            using (Context db = new Context())
                            {
                                if (db.Sentiment.Where(x => x.docid == d.id).Count() == 0)
                                {
                                   getSentiment(d);
                                }
                            }
                        }
                    }
                    else
                        Console.WriteLine("No new articles - " + DateTime.Now);
                }
                else
                {
                    throw new Exception(client.ResponseHeaders["X-AlchemyAPI-Error-Msg"]);
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("Error calling web service: " + e.Message);
            }
        }
Exemplo n.º 2
0
 public data Get()
 {
     data r;
     using (Context db = new Context())
     {
         List<Sentiment> l = db.Sentiment.ToList();
         l.Sort((x, y) => x.timestamp.CompareTo(y.timestamp));
         r = CreateResponse(l);
     }
     Console.WriteLine("API request received - " + DateTime.Now);
     return r;
 }
Exemplo n.º 3
0
        private Sresponse getSentiment(DataJob.Doc d)
        {
            this.client = new WebClient();
            this.s = new Sresponse();
            s = JsonConvert.DeserializeObject<Sresponse>(client.DownloadString(sService + sQuery + d.source.enriched.url.url + "&apikey=" + apiKey));

            if (s.status == "OK" && s.results != null)
            {
                Sentiment r = s.results[0].sentiment;

                using (Context db = new Context())
                {
                    r.docid = d.id;
                    r.timestamp = d.timestamp;
                    r.url = d.source.enriched.url.url;
                    r.title = d.source.enriched.url.title;

                    db.Sentiment.Add(r);
                    db.SaveChanges();
                    Console.WriteLine("Added new article: " + r.url);
                }
            }

            return s;
        }
Exemplo n.º 4
0
 private Nresponse getArticles()
 {
     //Find latest article retrieved
     using (Context db = new Context())
     {
         Sentiment f = db.Sentiment.OrderByDescending(x => x.timestamp).First();
         if (f != null)
         {
             start = f.timestamp + 1;
         }
     }
     return n = JsonConvert.DeserializeObject<Nresponse>(client.DownloadString(nService + startq + start + "&" + nQuery + apiKey));
 }