Ejemplo n.º 1
0
 static void NewTweet(TwitterStatus tweet)
 {
     if (!jsonView)
     {
         lock (_locker)
         {
             string newtweet = tweet.Text.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ");
             if (tweet.Geo != null)
             {
                 Console.Write(string.Format("New tweet: @{0}, {1}: {2} ", tweet.User.ScreenName, tweet.CreatedDate, tweet.Text));
                 foreach (Coordinate c in tweet.Geo.Coordinates)
                 {
                     Console.Write("({0}, {1}) ", c.Latitude, c.Longitude);
                 }
                 Console.WriteLine();
                 using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Kheradruakh\Documents\School\CPSC530\TwitterCollector\data\result1.csv", true))
                     file.Write(tweet.User.ScreenName + "," + tweet.CreatedDate + "," + tweet.Id + "," + newtweet);
                 foreach (Coordinate c in tweet.Geo.Coordinates)
                 {
                     using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Kheradruakh\Documents\School\CPSC530\TwitterCollector\data\result1.csv", true))
                         file.Write("," + c.Latitude + "," + c.Longitude);
                 }
                 using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Kheradruakh\Documents\School\CPSC530\TwitterCollector\data\result1.csv", true))
                     file.WriteLine("");
             }
             else
             {
                 Console.WriteLine("No Location Data");
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void Add(TwitterStatus status)
 {
     if (!stats.ContainsKey(status.Id)) {
         stats.Add(status.Id, status);
         Invalid = true;
     }
 }
Ejemplo n.º 3
0
		public void Post(string Tweet, TwitterStatus ReplyTo)
		{
			new Task(() =>
			         {
			         	try
			         	{
			         		foreach (ExtendedOAuthTokens o in m.NowTokens)
			         		{
			         			var t = TwitterStatus.Update(o.OAuthTokens, Tweet, new StatusUpdateOptions() { InReplyToStatusId = ReplyTo.Id });
			         			if (t.Result != RequestResult.Success)
			         			{
			         				if (t.Result == RequestResult.RateLimited)
			         				{
			         					MConsole.WriteLine(o.UserName + " has been RateLimited. ResetDate must be " + t.RateLimiting.ResetDate.ToString() + ".");
			         				}
			         				else
			         				{
			         					MConsole.WriteLine("Some error happened : " + t.ErrorMessage);
			         				}
			         			}
			         			else MConsole.WriteLine("Success to tweet as " + o.UserName + " " + Tweet);
			         		}
			         	}
			         	catch (Exception e)
			         	{
			         		MConsole.WriteLine("Some error happened : " + e.Message);
			         	}
			         }).Start();
		}
Ejemplo n.º 4
0
 /// <summary>
 /// Replies to the specified status.
 /// </summary>
 /// <param name="replyTo">A status that replies to.</param>
 /// <param name="status">A new status text.</param>
 public void Reply(TwitterStatus replyTo, string status)
 {
     var option = new StatusUpdateOptions()
     {
         InReplyToStatusId = replyTo.Id
     };
     Post(string.Format("@{0} {1}", replyTo.User.ScreenName, status), option);
 }
Ejemplo n.º 5
0
 public void InsertTweetIn(TwitterStatus tweet, ColumnType colType)
 {
     for (int i = 0; i < flowColumns.Controls.Count; i++) {
     ColumnControl cc = (ColumnControl)flowColumns.Controls[i];
     if (cc.ColType == colType) {
       cc.InsertTweet(cc.flowColumn, tweet);
     }
       }
 }
Ejemplo n.º 6
0
        public override void Post(string post)
        {
            OAuthTokens tokens = new OAuthTokens();
            tokens.AccessToken = AccessToken.Token;
            tokens.AccessTokenSecret = AccessToken.TokenSecret;
            tokens.ConsumerKey = TwitterHelper.Twitter_ConsumerKey;
            tokens.ConsumerSecret = TwitterHelper.Twitter_ConsumerSecret;

            TwitterStatus status = new TwitterStatus();
            TwitterStatus.Update(tokens, post);
        }
Ejemplo n.º 7
0
 public TweetElement(dynamic prnt, TwitterStatus status, UserDatabase.User usr)
 {
     InitializeComponent();
     dbUser = usr;
     name = status.User.ScreenName;
     Date = status.CreatedDate.Month.ToString() + "/" + status.CreatedDate.Day.ToString() + " " + status.CreatedDate.Hour.ToString() + ":" + status.CreatedDate.Minute.ToString();
     imagelocation = status.User.ProfileImageLocation;
     ID = status.Id.ToString();
     Status = status;
     datelabel.Text = Date;
     parent = prnt;
     SolidColorBrush gBrush = new SolidColorBrush(Color.FromArgb((byte)(polyOpacity * 255), 0, 0, 0));
     messagePolygon.Fill = gBrush;
 }
Ejemplo n.º 8
0
        public void reply(TwitterStatus Status)
        {
            ((App)System.Windows.Application.Current).inreply = true;
            ((App)System.Windows.Application.Current).replystatus = Status;

            textBox1.Text = "@" + Status.User.ScreenName + " ";
            if (textBox1.Visibility == Visibility.Collapsed)
            {
                testbutton.Content = "Tweet";
                TweetElements.Margin = new Thickness(0, 0, 0, 70);
                textBox1.Visibility = Visibility.Visible;
                charleft.Visibility = Visibility.Visible;
                TweetLbl.Visibility = Visibility.Visible;

            }
            textBox1.Focus();
        }
        public Tweet ConvertToViewModel(TwitterStatus status)
        {
            Tweet tweet;

            tweet = new Tweet()
            {
                Id = status.Id,
                Username = status.User.ScreenName,
                ProfileImageURL = status.User.ProfileImageLocation,
                Text = status.Text,
                Timestamp = status.CreatedDate.ToString(),
                NumberOfFollowers = status.User.NumberOfFollowers
            };

            tweet.Text = tweet.FormatTweetText();

            return tweet;
        }
Ejemplo n.º 10
0
 private void debugDToolStripMenuItem_Click(object sender, EventArgs e)
 {
     TwitterStatus[][] t = new TwitterStatus[Main.Columns.Count][];
     for (int i = 0; i < Main.Columns.Count; i++)
     {
         t[i] = Main.Columns[i].timeline.ToArray();
     }
     OAuthTokens[] o = new OAuthTokens[ExtendedOAuthTokens.Tokens.Count];
     for (int j = 0; j < ExtendedOAuthTokens.Tokens.Count; j++)
     {
         o[j] = ExtendedOAuthTokens.Tokens[j].OAuthTokens;
     }
     if (EditingPath != null)
     {
         string copy = "Scripts/" + Rc.CutString("\\", EditingPath)[Rc.CutString("\\", EditingPath).Length - 1];
         try { File.Copy(EditingPath, copy); }
         catch { }
         Script.Run(Rc.CutString(".", Rc.CutString("\\", EditingPath)[Rc.CutString("\\", EditingPath).Length - 1])[0], this.textBox1.Text ,new Action<object>(Get),new Arg().SetArgValue(t, "Tweets") , new Arg().SetArgValue(o, "Accounts"));
     }
 }
Ejemplo n.º 11
0
 public TweetExtended(Twitterizer.TwitterStatus st)
 {
     using (var db = new dbContainer()) {
         try {
             Local = db.TweetSet.First(t => t.TweetId == st.Id);
         } catch (InvalidOperationException) {
             Local             = new Twitruc.DAL.Tweet();
             Local.Content     = st.Text;
             Local.AuthorNick  = st.User.ScreenName;
             Local.Date        = st.CreatedDate;
             Local.TweetId     = st.Id;
             Local.TwitrucUser = null;
             Local.Public      = !st.User.IsProtected;
             db.TweetSet.AddObject(Local);
             db.SaveChanges();
         }
         Tweeter = st;
         EndInit();
     }
 }
Ejemplo n.º 12
0
        public TwitterMessageBuilder Append(TwitterStatus status,
                                            ContactModel sender,
                                            bool isHighlight)
        {
            if (status == null) {
                throw new ArgumentNullException("status");
            }
            if (sender == null) {
                throw new ArgumentNullException("sender");
            }

            // MessageModel serializer expects UTC values
            TimeStamp = status.CreatedDate.ToUniversalTime();

            ID = status.StringId;

            AppendSenderPrefix(sender, isHighlight);

            if (status.RetweetedStatus == null && status.QuotedStatus == null) {
                AppendMessage(status.Text);
            }
            if (status.RetweetedStatus != null) {
                var rtMsg = String.Format(
                    "RT @{0}: {1}",
                    status.RetweetedStatus.User.ScreenName,
                    status.RetweetedStatus.Text
                );
                AppendMessage(rtMsg);
            }
            if (status.QuotedStatus != null) {
                var qtMsg = String.Format(
                    "QT @{0}: {1}",
                    status.QuotedStatus.User.ScreenName,
                    status.QuotedStatus.Text
                );
                AppendMessage(status.Text);
                AppendSpace();
                AppendMessage(qtMsg);
            }
            return this;
        }
Ejemplo n.º 13
0
        public TweetElement(MainWindow1 prnt, TwitterStatus status, UserDatabase.User usr, ImageSource Imagesource, bool MoreThanOneUser = false)
        {
            InitializeComponent();
            dbUser = usr;
            moreusers = MoreThanOneUser;
            name = status.User.ScreenName;
            tweetImg.Source = Imagesource;
            ID = status.Id.ToString();
            Status = status;

            favBtn.MouseDown += new MouseButtonEventHandler(favBtn_MouseDown);

            if (status.Retweeted != true)
            {
                retweetBtn.MouseDown += new MouseButtonEventHandler(retweetBtn_MouseDown);
            }

            parent = prnt;
            SolidColorBrush gBrush = new SolidColorBrush(Color.FromArgb((byte)(polyOpacity * 255), 0, 0, 0));
            messagePolygon.Fill = gBrush;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// ツッコミ投稿
        /// </summary>
        /// <param name="s">ツッコミ対象status</param>
        private void Kamatte(TwitterStatus s)
        {
            var t = Settings.IncrementKamatteCount(s.User.Id);
            var sb = new StringBuilder("誰かかまってやれよ! ");
            if (t == null)
            {
                t = new TargetUser();
                t.Id = s.User.Id;
                t.Name = s.User.ScreenName;
                t.DailyKamatteCount = 1;
                t.TotalKamatteCount = 1;
                t.Filter = "(?!)";
                Settings.Targets.Add(t);
            }
            if (t != null)
            {
                sb.Append("(本日").Append(t.DailyKamatteCount).Append("回目, 累計").Append(t.TotalKamatteCount).Append("回) ");
            }
            sb.Append("RT ").Append(s.User.ScreenName).Append(": ").Append(s.Text.Replace("@", "(at)"));

            var r = Twitter.GetInstance().StatusUpdate(sb.Length > 140 ? sb.ToString(0, 139) + "…" : sb.ToString());
            if (r.Result.Equals(RequestResult.Success))
            {
                Log("Tweet kamatte!: @" + s.User.ScreenName + ", Count: " + t.DailyKamatteCount + "/" + t.TotalKamatteCount);
            }
            else
            {
                Log("Tweet error: " + r.ErrorMessage);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// watchingListへのスレッドセーフな値の追加
        /// </summary>
        /// <param name="status">追加するTwitterStatus</param>
        /// <returns>追加が成功したかどうか</returns>
        private bool AddStatusToWatchingList(TwitterStatus status)
        {
            try
            {
                watchingList.Add(status.Id, status);
            }
            catch (ArgumentException ex)
            {
                DebugLog("WatchingList key is duplicated: " + ex.ParamName);
                return false;
            }
            catch (Exception ex)
            {
                DebugLog(ex.ToString());
                return false;
            }

            if (kamatteCheckTimer == null)
            {
                kamatteCheckTimer = new Timer(KamatteCheckTask, null, Settings.WaitTime * 60 * 1000, Timeout.Infinite);
                DebugLog("KamatteCheckTimer is set after " + Settings.WaitTime + " minutes.");
            }

            return true;
        }
Ejemplo n.º 16
0
        void StreamStoppedcallback(Twitterizer.Streaming.StopReasons stopreason)
        {
            //What happen??!??!?!??!!??!1//1/1/111oneone
            //Restart dat SHEET OF PAPER
            //System.Threading.Thread.Sleep(2000); wat
            TwitterStatus notification = new TwitterStatus();
            notification.Text = "Stream died! Restarting stream when twitter is aviable again...";
            notification.User = new TwitterUser();
            notification.User.ScreenName = "Internal message system";
            NewTweet(notification, privOAuth);

            bool offline = true;
            while (offline)
            {

                bool isOnline = false;

                try
                {
                     System.Net.NetworkInformation.Ping pong = new System.Net.NetworkInformation.Ping();
                     IPAddress adress = new IPAddress(new byte[] {8,8,8,8});

                     if (pong.Send(adress).Status == System.Net.NetworkInformation.IPStatus.Success)
                     {
                         System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
                         System.Net.NetworkInformation.PingReply result = ping.Send("www.twitter.com");
                         if (result.Status == System.Net.NetworkInformation.IPStatus.Success)
                         { isOnline = true; }
                     }
                }
                catch(Exception){}

                if (isOnline)
                {
                    offline = false;
                }
                else
                {
                    System.Threading.Thread.Sleep(10000);
                }
            }

            notification = new TwitterStatus();
            notification.Text = "Restarting stream!";
            notification.User = new TwitterUser();
            notification.User.ScreenName = "Internal message system";
            NewTweet(notification, privOAuth);

            System.Threading.Thread.Sleep(500);

            clear("connection lost");
            FetchTweets(privOAuth);

            StartStream(new Twitterizer.Streaming.StreamOptions());
        }
Ejemplo n.º 17
0
 void StatuscreatedCallback(TwitterStatus status)
 {
     if (NewTweet != null)
         NewTweet(status, privOAuth);
 }
Ejemplo n.º 18
0
 internal void OnStatusCreated(TwitterStatus status)
 {
     if (StatusCreated != null) {
         StatusCreated(status);
     }
 }
Ejemplo n.º 19
0
 void StatusCreatedCallback(TwitterStatus status)
 {
     MessageBox.Show("ee");
     label1.Text += status.User.Name + " - " + status.Text;
 }
Ejemplo n.º 20
0
 void Add(TwitterStatus t)
 {
     try
     {
         if (timeline.Count > 0)
         {
             var rev = timeline.ToArray().Reverse().ToList();
             rev.Add(t);
             rev.Reverse();
             timeline = rev;
         }
         else
         {
             timeline.Add(t);
         }
         ShowF();
     }
     catch { }
 }
Ejemplo n.º 21
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         AtNameLabel = null;
         datelabel = null;
         favBtn = null;
         replyBtn = null;
         retweetBtn = null;
         TweetBlock = null;
         tweetImg = null;
         contextmenu = null;
         dbUser = null;
         favimageborder = null;
         ID = null;
         imageborder = null;
         label1 = null;
         messagePolygon = null;
         name = null;
         NameLabel = null;
         parent = null;
         polyOpacity = 0;
         replyBtn = null;
         replyimageborder = null;
         retweetBtn = null;
         retweetimageborder = null;
         Status = null;
         tweetelementgrid = null;
         tweetElement = null;
     }
 }
Ejemplo n.º 22
0
 void stream_OnStatusDeleted(TwitterStatus status)
 {
     Console.WriteLine(string.Format("Deleted: id = {0}", status.Id));
 }
Ejemplo n.º 23
0
 void stream_OnStatus(TwitterStatus status)
 {
     Console.WriteLine(string.Format("Created: @{0}: {1}", status.User.ScreenName, status.Text));
 }
Ejemplo n.º 24
0
        /// <see cref="LabMonitoring.ITweetHandler"/>
        public void HandleStatus(TwitterStatus target, logOutput log)
        {
            if (target.InReplyToStatusId != null)
            {
                /* Receive a reply message */
                if (target.User.Id == target.InReplyToUserId)
                {
                    /* Self reply message */
                    if (watchingList.ContainsKey((decimal)target.InReplyToStatusId))
                    {
                        Log("Receive a self reply message: [" + target.Id + "] @" + target.User.ScreenName + " " + target.Text + " to " + target.InReplyToStatusId);
                        Kamatte(target);
                        watchingList.Remove((decimal)target.InReplyToStatusId);
                    }
                }
                else
                {
                    /* Other's tweet */
                    /* A message sent from othe to target */
                    if (watchingList.ContainsKey((decimal)target.InReplyToStatusId))
                    {
                        Log("Receive a message sent from other to target: [" + target.Id + "] @" + target.User.ScreenName + " " + target.Text + " to " + target.InReplyToStatusId);
                        watchingList.Remove((decimal)target.InReplyToStatusId);
                    }
                }
            }
            else
            {
                /* Global target */
                if (Regex.IsMatch(target.Text, Settings.GlobalFilter))
                {
                    if (AddStatusToWatchingList(target))
                    {
                        Log("Receive a global filter tweet: [" + target.Id + "] @" + target.User.ScreenName + " " + target.Text);
                    }
                    return;
                }

                /* Recieve a nomal message */
                if (Settings.GetTargetIdArray().Contains(target.User.Id.ToString()) && target.RetweetedStatus == null)
                {
                    /* Target's tweet */
                    var t = Settings.GetTargetUserFromId(target.User.Id);
                    string f = null;
                    if (t != null)
                    {
                        f = t.Filter;
                    }
                    if (string.IsNullOrEmpty(f))
                    {
                        f = ".*";
                    }

                    if (Regex.IsMatch(target.Text, "(ぼっち|ボッチ)飯"))
                    {
                        Kamatte(target);
                        return;
                    }
                    if (!Regex.IsMatch(target.Text, f, RegexOptions.IgnoreCase)) return;
                    if (Regex.IsMatch(target.Source, ">ikejun<")) return;

                    if (AddStatusToWatchingList(target))
                    {
                        Log("Receive a target tweet: [" + target.Id + "] @" + target.User.ScreenName + " " + target.Text);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        void OnStatusCreated(TwitterStatus status)
        {
            Trace.Call(status);

            try {
                if (MessageRateLimiter.IsRateLimited) {
                    return;
                }

                // filter native and old-school retweets
                if (status.RetweetedStatus != null || status.Text.StartsWith("RT @")) {
                    return;
                }

                MessageRateLimiter++;

                var sender = ProtocolManager.GetPerson(status.User);
                var userId = status.User.Id.ToString();
                lock (Chat.UnsafePersons) {
                    if (!Chat.UnsafePersons.ContainsKey(userId)) {
                        Session.AddPersonToGroupChat(Chat, sender);
                    }
                }
                var msg = CreateMessageBuilder().
                    Append(status, sender).
                    ToMessage();
                Session.AddMessageToChat(Chat, msg);
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("OnStatusCreated()", ex);
            #endif
            }
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Returns the status text with HTML links to users, urls, and hashtags.
 /// </summary>
 /// <remarks>This will only work if you specify <see cref="SearchOptions.IncludeEntities"/> = <c>true</c> when executing the search.</remarks>
 /// <returns></returns>
 public string LinkifiedText()
 {
     return(TwitterStatus.LinkifiedText(Entities, Text));
 }
Ejemplo n.º 27
0
		public void Retweet(TwitterStatus t)
		{
			new Task(() =>
			         {
			         	try
			         	{
			         		foreach (ExtendedOAuthTokens o in m.NowTokens)
			         		{
			         			var f = TwitterStatus.Retweet(o.OAuthTokens, t.Id);
			         			if (f.Result != RequestResult.Success)
			         			{
			         				if (f.Result == RequestResult.RateLimited)
			         				{
			         					MConsole.WriteLine(o.UserName + " has been RateLimited. ResetDate must be " + f.RateLimiting.ResetDate.ToString() + ".");
			         				}
			         				else
			         				{
			         					MConsole.WriteLine("Some error happened : " + f.ErrorMessage);
			         				}
			         			}
			         			else MConsole.WriteLine("Success to retweet [" + t.User.ScreenName + ": " + t.Text + "] as " + o.UserName);
			         		}
			         	}
			         	catch (Exception e)
			         	{
			         		MConsole.WriteLine("Some error happened : " + e.Message);
			         	}
			         }).Start();
		}
 static void NewTweet(TwitterStatus tweet)
 {
     Console.WriteLine(string.Format("New tweet: @{0}: {1}", tweet.User.ScreenName, tweet.Text));
 }
 void NewTweet(TwitterStatus twitterizerStatus)
 {
     Tweet tweet = this._translationService.ConvertToViewModel(twitterizerStatus);
     this._repository.Add(tweet);
 }
Ejemplo n.º 30
0
 string ComposeContent(TwitterStatus tweet)
 {
     return string.Format(
        @"{0}:\n{1}\n{2} {3}",
        tweet.User.Name,
        tweet.Text.Length > 80 ? tweet.Text.Substring(0, 80) : tweet.Text,
        tweet.User.Location,
        tweet.CreatedDate
        );
 }
Ejemplo n.º 31
0
        private void NewTweet(TwitterStatus tweet)
        {
            string _text = HttpUtility.HtmlDecode(tweet.Text);
            DateTime server_time = ServerTime();
            TimeSpan time_gap = (server_time - tweet.CreatedDate);

            string str_gap;
            if(time_gap.Days >= 365) { str_gap = (time_gap.Days / 365).ToString() + "년 전"; }
            else if(time_gap.Days > 30) { str_gap = (time_gap.Days / 30).ToString() + "달 전"; }
            else if(time_gap.Days > 0) { str_gap = time_gap.Days.ToString() + "일 전"; }
            else if(time_gap.Hours > 0) { str_gap = time_gap.Hours.ToString() + "시간 전"; }
            else if(time_gap.Minutes > 0) { str_gap = time_gap.Minutes.ToString() + "분 전"; }
            else { str_gap = time_gap.Seconds.ToString() + "초 전"; }
        }
Ejemplo n.º 32
0
 /// <summary>
 /// PublicStream新Status受信時ハンドラ
 /// </summary>
 /// <param name="target">受信したStatus</param>
 private void onPStatus(TwitterStatus target)
 {
     if (target.User.Id.Equals(BotUserId)) return;
     NewPublicStatusEvent(target, LogOutput);
 }