Ejemplo n.º 1
0
 public void puxaLista()
 {
     try
     {
         System.IO.StreamReader file = new System.IO.StreamReader(@"Data.txt");
         lista = new List <TweetRetorno>();
         string line;
         while ((line = file.ReadLine()) != null)
         {
             tweetJson          = new TweetRetorno();
             tweetJson.id_tweet = line.Substring(0, 19);
             //Console.WriteLine(tweetJson.id_tweet.Length);
             tweetJson.mensager = line.Substring(19, 526);
             //Console.WriteLine(tweetJson.mensager.Length);
             tweetJson.user_id = line.Substring(545, 19);
             //Console.WriteLine(tweetJson.user_id.Length);
             tweetJson.user = line.Substring(564, 20);
             //Console.WriteLine(tweetJson.user.Length);
             //Console.ReadLine();
             lista.Add(tweetJson);
         }
         file.Close();
     }
     catch (System.IO.FileNotFoundException e)
     {
         Console.WriteLine("Arquivo nao encontrado");
     }
     return;
 }
Ejemplo n.º 2
0
        public void AddTweet(TweetRetorno newTweetRetorno)
        {
            var json   = File.ReadAllText("arquivoDados.txt");
            var tweets = JsonConvert.DeserializeObject <List <TweetRetorno> >(json);

            tweets.Add(newTweetRetorno);
            File.WriteAllText("arquivoDados.txt", JsonConvert.SerializeObject(tweets));
        }
Ejemplo n.º 3
0
        public void insereNaLsita(String matchingTweets)
        {
            lista = new List <TweetRetorno>();
            JArray arrayDeJSon = JArray.Parse(matchingTweets);
            var    c           = arrayDeJSon.Count;
            var    i           = 0;

            while (c > 0)
            {
                //Console.WriteLine(i +" c = " +c);
                tweetJson = new TweetRetorno();

                tweetJson.id_tweet = arrayDeJSon[i]["id_str"].ToString().Replace("\n", "  ").PadRight(19, ' ');
                byte[] bytes = Encoding.Default.GetBytes(tweetJson.id_tweet);
                tweetJson.id_tweet = Encoding.UTF8.GetString(bytes);
                Console.WriteLine(tweetJson.id_tweet.Length);

                tweetJson.mensager = arrayDeJSon[i]["full_text"].ToString().Replace("\n", "");
                Console.WriteLine(tweetJson.mensager);
                Console.WriteLine(tweetJson.mensager.Length);
                bytes = Encoding.Default.GetBytes(tweetJson.mensager);
                Console.WriteLine(bytes);
                tweetJson.mensager = Encoding.UTF8.GetString(bytes).PadRight(526, ' ');
                Console.WriteLine(tweetJson.mensager);
                Console.WriteLine(tweetJson.mensager.Length);

                tweetJson.mensager = Regex.Replace(tweetJson.mensager, @"\p{Cs}", " ");
                Console.WriteLine(tweetJson.mensager);
                Console.WriteLine(tweetJson.mensager.Length);


                tweetJson.user_id = arrayDeJSon[i]["user"]["id_str"].ToString().Replace("\n", "  ").PadRight(19, ' ');
                bytes             = Encoding.Default.GetBytes(tweetJson.user_id);
                tweetJson.user_id = Encoding.UTF8.GetString(bytes);
                Console.WriteLine(tweetJson.user_id.Length);

                tweetJson.user = arrayDeJSon[i]["user"]["screen_name"].ToString().Replace("\n", "  ").PadRight(20, ' ');
                bytes          = Encoding.Default.GetBytes(tweetJson.user);
                tweetJson.user = Encoding.UTF8.GetString(bytes);
                Console.WriteLine(tweetJson.user.Length);

                lista.Add(tweetJson);
                //Console.ReadLine();
                c--;
                i++;
            }
            return;
        }
Ejemplo n.º 4
0
        public void dadosPeloJson()
        {
            string[] stringDeJson = null;
            int      count        = 0;

            if (File.Exists(@"teste1.json"))
            {
                stringDeJson = File.ReadAllLines(@"teste1.json");
                while (count < 100)
                {
                    JArray arrayDeJSon = JArray.Parse(stringDeJson[count]);
                    var    c           = arrayDeJSon.Count;
                    var    i           = 0;
                    while (c > 0)
                    {
                        //Console.WriteLine(i +" c = " +c);
                        tweetJson = new TweetRetorno();

                        /*
                         * tweetJson.id_tweet = arrayDeJSon[i]["id_str"].ToString().Replace("\n", "  ").PadRight(19, ' ');
                         * byte[] bytes = Encoding.Default.GetBytes(tweetJson.id_tweet);
                         * tweetJson.id_tweet = Encoding.UTF8.GetString(bytes);
                         * Console.WriteLine(tweetJson.id_tweet.Length);
                         *
                         * tweetJson.mensager = arrayDeJSon[i]["full_text"].ToString().Replace("\n", "");
                         * Console.WriteLine(tweetJson.mensager);
                         * Console.WriteLine(tweetJson.mensager.Length);
                         * bytes = Encoding.Default.GetBytes(tweetJson.mensager);
                         * Console.WriteLine(bytes);
                         * tweetJson.mensager = Encoding.UTF8.GetString(bytes).PadRight(526, ' ');
                         * Console.WriteLine(tweetJson.mensager);
                         * Console.WriteLine(tweetJson.mensager.Length);
                         *
                         * tweetJson.mensager = Regex.Replace(tweetJson.mensager, @"\p{Cs}", " ");
                         * Console.WriteLine(tweetJson.mensager);
                         * Console.WriteLine(tweetJson.mensager.Length);
                         *
                         *
                         * tweetJson.user_id = arrayDeJSon[i]["user"]["id_str"].ToString().Replace("\n", "  ").PadRight(19, ' ');
                         * bytes = Encoding.Default.GetBytes(tweetJson.user_id);
                         * tweetJson.user_id = Encoding.UTF8.GetString(bytes);
                         * Console.WriteLine(tweetJson.user_id.Length);
                         *
                         * tweetJson.user = arrayDeJSon[i]["user"]["screen_name"].ToString().Replace("\n", "  ").PadRight(20, ' ');
                         * bytes = Encoding.Default.GetBytes(tweetJson.user);
                         * tweetJson.user = Encoding.UTF8.GetString(bytes);
                         * Console.WriteLine(tweetJson.user.Length);
                         */
                        tweetJson.hashtags = arrayDeJSon[i]["entities"]["hashtags"].ToString();
                        Console.WriteLine(tweetJson.hashtags);

                        lista.Add(tweetJson);
                        //Console.ReadLine();
                        c--;
                        i++;
                        count++;
                    }
                }
            }
            return;
        }