Esempio n. 1
0
        static RedditArticles GetArticles(string _token)
        {
            var client  = new RestClient("https://oauth.reddit.com/r/soccer/hot");
            var request = new RestRequest(Method.GET);

            request.AddHeader($"Authorization", "Bearer " + _token);
            request.AddParameter("undefined", "Sentiment Analysis/0.1 by Zycroft", ParameterType.RequestBody);
            IRestResponse  response = client.Execute(request);
            RedditArticles myReddit = RedditArticles.FromJson(response.Content);

            return(myReddit);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string RedditLogin       = ""; // Reddit user login
            string RedditPWD         = ""; // Reddit user password
            string RedditAppID       = ""; // Reddit App ID
            string RedditAppSecret   = ""; // Reddit App secret
            string redditAccessToken = ""; // Store key here if you going to build DB a few times it is good for 120min
            string AzureSentAppKey   = "[YourSetimentAppKey]";

            gremlinServer = new GremlinServer("[YourCosmoDB].gremlin.cosmos.azure.com", 443, enableSsl: true,
                                              username: $"/dbs/[database id]/colls/[Graph id]",
                                              password: "******");
            // Make sure the graph DB is empty to start
            using (var gremlinClient = new GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))
            {
                var result = AzureAsync(gremlinClient, "g.V().drop()");      // Clear DB
                Console.WriteLine("\n{{\"Returned\": \"{0}\"}}", result.Result.Count);
            }

            if (redditAccessToken == "")
            {
                redditAccessToken = AuthToken(RedditLogin, RedditPWD, RedditAppID, RedditAppSecret); // Get Reddit access token
            }
            RedditArticles  myArt         = GetArticles(redditAccessToken);                          // Get Reddit articles
            EntitiesData    EntitiesData  = CreateEntitiesData(myArt);                               // Create sentiment entity data structure for entities
            EntitiesResult  ArtEntities   = GetEntities(AzureSentAppKey, EntitiesData);              // Get entities from Azure API
            SemtimentData   SentimentData = CreateSentimentData(myArt);                              // Create sentiment data structure
            SemtimentResult ArtSentiment  = GetSentiment(AzureSentAppKey, SentimentData);            // Get sentiment for article

            SaveArtResults(SentimentData, ArtSentiment, ArtEntities);                                // Save results in Cosmos DB

/*
 *          foreach(QuickTypeEntitiesResult.Entity artEnt in ArtEntities.Documents[0].Entities)
 *          {
 *              Console.WriteLine("e:" + artEnt.Name);
 *          }
 *          System.Threading.Thread.Sleep(1000);
 *          ParseComments(redditAccessToken, articl.Data.Name.Substring(3));
 */
        }
Esempio n. 3
0
        static EntitiesData CreateEntitiesData(RedditArticles _myArt)
        {
            List <QuickTypeEntitiesData.Document> list = new List <QuickTypeEntitiesData.Document>();
            EntitiesData _AzData = new EntitiesData();
            int          i       = 0;

            foreach (QuickTypeArticles.Child articl in _myArt.Data.Children)
            {
                if (articl.Kind == "t3" && articl.Data.Author != "AutoModerator")  // Ensure its an Article and not a bot post
                {
                    i++;
                    list.Add(new QuickTypeEntitiesData.Document
                    {
                        Id       = i,
                        Language = "en",
                        Text     = articl.Data.Title
                    });
                }
            }
            _AzData.Documents = list.ToArray();
            return(_AzData);
        }