Ejemplo n.º 1
0
        public override IEnumerable<Kbtter4Plugin> Load(Kbtter instance, IList<string> filenames)
        {
            var files = filenames.Where(p => p.EndsWith(".py"));
            var ret = new List<Kbtter4IronPythonPlugin>();

            engine = Python.CreateEngine();

            var context = HostingHelpers.GetLanguageContext(engine) as PythonContext;
            var path = context.GetSearchPaths();
            path.Add(Environment.CurrentDirectory + "\\");
            engine.SetSearchPaths(path);

            engine.Runtime.LoadAssembly(typeof(Status).Assembly);

            foreach (var i in files)
            {
                try
                {
                    var scope = engine.CreateScope();
                    scope.SetVariable("Kbtter4", new Kbtter4PluginProvider(instance));
                    var src = engine.CreateScriptSourceFromFile(i);
                    var code = src.Compile();
                    code.Execute(scope);
                    var p = new Kbtter4IronPythonPlugin(scope,instance);
                    ret.Add(p);
                }
                catch (Exception e)
                {
                    instance.LogError(String.Format("プラグイン読み込み中にエラーが発生しました : {0}\n{1}", i, e.Message));

                }
            }

            return ret;
        }
Ejemplo n.º 2
0
        public TwitterCheck()
        {
            var settings = ConfigurationManager.AppSettings;

            var blackWords = new List<string>();
            var whiteWords = new List<string>();
            for (int i = 1; i <= SettingMax; i++)
            {
                string black = settings["twitter.blackwords." + i];
                if (black == null) continue;
                foreach (var elem in black.Split(','))
                {
                    blackWords.Add(elem);
                }
                string white = settings["twitter.whitewords." + i];
                if (white == null) continue;
                foreach (var elem in white.Split(','))
                {
                    whiteWords.Add(elem);
                }
            }
            BlackWords = blackWords.AsReadOnly();
            WhiteWords = whiteWords.AsReadOnly();
            Log.Trace.TraceEvent(TraceEventType.Information, 0,
                "{0} black words loaded", BlackWords.Count);
            Log.Trace.TraceEvent(TraceEventType.Information, 0,
               "{0} white words loaded", WhiteWords.Count);

            var replaceList = new List<KeyValuePair<string, string>>();
            for (int i = 1; i <= SettingMax; i++)
            {
                string str = settings["twitter.replace." + i];
                if (str == null) continue;
                foreach (var pair in str.Split(','))
                {
                    string[] kv = pair.Split('=');
                    replaceList.Add(new KeyValuePair<string, string>(kv[0], kv[1]));
                }
            }
            ReplaceList = replaceList.AsReadOnly();
            Log.Trace.TraceEvent(TraceEventType.Information, 0,
                "{0} replace entries loaded", ReplaceList.Count);

            try
            {
                dlNetwork = DollsLib.Learning.DataManager.LoadDeepLearning(
                    SettingManager.Settings.Twitter.DlNetTrainError);
            }
            catch (Exception)
            {
                Log.Trace.TraceEvent(TraceEventType.Warning, 0,
                "DlNwtwork {0} load failed", SettingManager.Settings.Twitter.DlNetTrainError);
            }
        }
Ejemplo n.º 3
0
        public static List<Status> getOAuthAndReplies()
        {
            var tokens = SingleService.getTokens();
            var home = tokens.Statuses.HomeTimeline();
            var mentions = tokens.Statuses.MentionsTimeline();
            List<Status> replies = new List<Status>();

            foreach(var m in mentions)
            {
                replies.Add(m);
            }
            return replies;
        }
Ejemplo n.º 4
0
        public MainWindow()
		{
            selectImage = "";
			InitializeComponent();
			pictureBoarders = new List<Rectangle>();
            twhelper = new TwitterHelpper();
            Properties.Settings.Default.FileRoot= Properties.Settings.Default.FileRoot == "" ?
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) :
                    Properties.Settings.Default.FileRoot;
            Properties.Settings.Default.Save();

            hotKey = new HotKey.HotKeyRegister(HotKey.MOD_KEY.CONTROL, Keys.Q, this);
			pictureList = new Mok.Util.PaginateList<string>(9);
			hotKey.HotKeyPressed += (k) =>
			{
	
				counter++;
                try
                {
                    wc.CaptureImage().Save(FilePath(), System.Drawing.Imaging.ImageFormat.Png);
                }
                catch(WindowCapture.WindowNotFoundException)
                {
                    System.Windows.MessageBox.Show("PC TV with Nasneが起動されていません。");
                    return;
                }
				pictureList.AddShift(FilePath());
				ReconstractView();
				selectImage = FilePath();
				pictureBoarders.ForEach(p => p.Visibility = Visibility.Hidden);
				pictureBoarders[Math.Min(8, pictureList.Count - 1)].Visibility = Visibility.Visible;

			};
			wc = new WindowCapture.WindowCapture("PC TV");
		
			Loaded += (ss, ee) =>
			{
				var picarea = PictureArea.Children;
				foreach (var item in picarea)
				{
					if (item.GetType().ToString() == "System.Windows.Shapes.Rectangle")
					{
						pictureBoarders.Add((Rectangle)item);
						((Rectangle)item).Visibility = Visibility.Hidden;
					}
				}
      
            };

		}
Ejemplo n.º 5
0
 public List<Result> Query(Query query)
 {
     List<Result> results = new List<Result>();
     string tweetMessage = query.ToString().Remove(0, 2);
     results.Add(new Result()
     {
         
         Title = "Tweet: " + tweetMessage,
         IcoPath = "Image\\twitter.png",
         Action = context =>
         {
             postTweet(tweetMessage);
             return true;
         }
     });
     return results;
 }
Ejemplo n.º 6
0
    private async void muteInfo()
    {
      if (tokens != null)
      {


        user = new List<TweetClass.UserInfo>();
        try
        {

         
          foreach (var status in await tokens.Mutes.Users.ListAsync())

          {
            //data.AddInfo(userPro2, status);
            user.Add(new TweetClass.UserInfo
            {
              UserName = status.Name,
              UserId = status.Id,
              ScreenName = "@" + status.ScreenName,
              ProfileImageUrl = status.ProfileImageUrlHttps,
              FollowCount = status.FollowersCount,
              FavCount = status.FavouritesCount,
              FollowerCount = status.FriendsCount,
              Prof = status.Description

            });

          }
          this.muteView.ItemsSource = user;
        }

        catch (Exception ex)

        {

        }

      }

    }
Ejemplo n.º 7
0
        public override IEnumerable<Kbtter4Plugin> Load(Kbtter instance, IList<string> filenames)
        {
            var list = new List<Kbtter4LuaPlugin>();
            var files = filenames.Where(p => p.EndsWith(".lua"));
            foreach (var i in files)
            {
                try
                {
                    Lua l = new Lua();
                    l.LoadCLRPackage();
                    l["Kbtter4"] = new Kbtter4PluginProvider(instance);
                    l.DoFile(i);
                    list.Add(new Kbtter4LuaPlugin(l,instance));
                }
                catch (Exception e)
                {
                    instance.LogError("Luaプラグイン読み込み中にエラーが発生しました : " + e.Message);
                }
            }

            return list;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// トークンの取得
        /// </summary>
        /// <returns>トークン</returns>
        public static List<Tokens> getTokens()
        {
            if (myApis == null)
            {
                myApis = loadAPIInfo();
            }

            List<Tokens> tokens = new List<Tokens>();

            foreach(var myApi in myApis)
            {
                tokens.Add(Tokens.Create(myApi.APIKey
                , myApi.APISecret
                , myApi.AccessToken
                , myApi.AccessTokenSecret));
            }
            return tokens;
        }
Ejemplo n.º 9
0
        private void AnalyzeTextElements()
        {
            TextElements = new ObservableSynchronizedCollection<StatusTextElement>();
            var l = new List<Tuple<int[], StatusTextElement>>();

            if (Source.Entities != null)
            {
                if (Source.Entities.Urls != null)
                    foreach (var i in Source.Entities.Urls)
                    {
                        //Text = Text.Replace(i.Url.ToString(), i.DisplayUrl.ToString());
                        var e = new StatusTextElement();
                        e.Original = i.Url.ToString();
                        e.Action = main.View.OpenInDefault;
                        e.Type = StatusTextElementType.Uri;
                        e.Link = i.ExpandedUrl;
                        e.Surface = i.DisplayUrl;
                        l.Add(new Tuple<int[], StatusTextElement>(i.Indices, e));
                    }
                /*
                //互換性上の理由で画像がUrlとMedia両方で送られてくるらしいので暫定的に削除
                if (Source.Entities.Media != null)
                    foreach (var i in Source.Entities.Media)
                    {
                        //Text = Text.Replace(i.Url.ToString(), i.DisplayUrl.ToString());
                        var e = new StatusTextElement();
                        e.Original = i.Url.ToString();
                        e.Action = main.View.OpenInDefault;
                        e.Type = StatusTextElementType.Media;
                        e.Link = i.ExpandedUrl;
                        e.Surface = i.DisplayUrl;
                        l.Add(new Tuple<int[], StatusTextElement>(i.Indices, e));
                    }
                */
                if (Source.Entities.UserMentions != null)
                    foreach (var i in Source.Entities.UserMentions)
                    {
                        var e = new StatusTextElement();
                        e.Action = async (p) =>
                        {
                            var user = await Kbtter.Token.Users.ShowAsync(id => i.Id);
                            Kbtter.AddUserToUsersList(user);
                            main.View.Notify(user.Name + "さんの情報");
                            main.View.ChangeToUser();
                        };
                        e.Type = StatusTextElementType.User;
                        e.Link = new Uri("https://twitter.com/" + i.ScreenName);
                        e.Surface = "@" + i.ScreenName;
                        e.Original = e.Surface;
                        l.Add(new Tuple<int[], StatusTextElement>(i.Indices, e));
                    }

                if (Source.Entities.HashTags != null)
                    foreach (var i in Source.Entities.HashTags)
                    {
                        var e = new StatusTextElement();
                        e.Action = (p) =>
                        {
                            main.View.ChangeToSearch();
                            main.View.SearchText = "#" + i.Text;
                            Kbtter.Search("#" + i.Text);
                        };
                        e.Type = StatusTextElementType.Hashtag;
                        e.Link = new Uri("https://twitter.com/search?q=%23" + i.Text);
                        e.Surface = "#" + i.Text;
                        e.Original = e.Surface;
                        l.Add(new Tuple<int[], StatusTextElement>(i.Indices, e));
                    }

                l.Sort((x, y) => x.Item1[0].CompareTo(y.Item1[0]));
            }

            int le = 0;
            foreach (var i in l)
            {
                var el = i.Item1[1] - i.Item1[0];
                var ntl = i.Item1[0] - le;
                if (ntl != 0)
                {
                    var nt = Text.Substring(le, ntl);
                    nt = nt
                        .Replace("&lt;", "<")
                        .Replace("&gt;", ">")
                        .Replace("&amp;", "&");
                    TextElements.Add(new StatusTextElement { Surface = nt, Type = StatusTextElementType.None });
                }
                TextElements.Add(i.Item2);
                le = i.Item1[1];
            }
            //foreach (var i in l) Text = Text.Replace(i.Item2.Original, i.Item2.Surface);
            if (Text.Length > le - 1)
            {
                var ls = Text.Substring(le);
                ls = ls
                        .Replace("&lt;", "<")
                        .Replace("&gt;", ">")
                        .Replace("&amp;", "&");
                TextElements.Add(new StatusTextElement { Surface = ls, Type = StatusTextElementType.None });
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// ツイッターAPI情報のロード
        /// </summary>
        /// <returns>API情報</returns>
        public static List<TwitterAPI> loadAPIInfo()
        {
            List<TwitterAPI> APIList = new List<TwitterAPI>();
            XmlSerializer serializer = new XmlSerializer(typeof(TwitterAPI));
            StreamReader sr = new StreamReader(
                Directory.GetCurrentDirectory() + @"\twitterAPI.xml", new System.Text.UTF8Encoding(false));

            APIList.Add((TwitterAPI)serializer.Deserialize(sr));

            XmlSerializer serializer2 = new XmlSerializer(typeof(TwitterAPI));
            StreamReader sr2 = new StreamReader(
                Directory.GetCurrentDirectory() + @"\twitterAPI2.xml", new System.Text.UTF8Encoding(false));

            APIList.Add((TwitterAPI)serializer2.Deserialize(sr2));
            return APIList;
        }
Ejemplo n.º 11
0
    private async void followerTimeline()
    {
      listView2.Visibility = Visibility.Collapsed;
      userTLView.Visibility = Visibility.Visible;
      if (tokens != null)

      {
        //this.userTLView.Items.Clear();

        userPro2 = new List<TweetClass.UserInfo>();
        try

        {
          userPro2 = new List<TweetClass.UserInfo>();
          // var showedUser = tokens.Favorites.List(screen_name => ScreenName, count => 200);

          foreach (var status in await tokens.Followers.ListAsync(user_id => UserId, count => 200))

          {
            //data.AddInfo(userPro2, status);
            userPro2.Add(new TweetClass.UserInfo
            {
              UserName = status.Name,
              UserId = status.Id,
              ScreenName = "@" + status.ScreenName,
              ProfileImageUrl = status.ProfileImageUrlHttps,
              FollowCount = status.FollowersCount,
              FavCount = status.FavouritesCount,
              FollowerCount = status.FriendsCount,
              Prof = status.Description

            });

          }
          this.userTLView.ItemsSource = userPro2;
        }

        catch (Exception ex)

        {


        }

      }
    }
Ejemplo n.º 12
0
    private void userInfo()
    {
     if (tokens != null)
      {
        userPro = new List<TweetClass.UserInfo>();
        try
        {

     //     showedUser =await tokens.Users.ShowAsync(user_id => name);


          userPro.Add(new TweetClass.UserInfo
          {
            UserName = showedUser.Name,
            UserId = showedUser.Id,
            ScreenName = "@" + showedUser.ScreenName,
            ProfileImageUrl = showedUser.ProfileImageUrlHttps,
            FollowCount = showedUser.FollowersCount,
            FavCount = showedUser.FavouritesCount,
            FollowerCount = showedUser.FriendsCount,
            Prof = showedUser.Description

          }
);

          this.userInfoView.ItemsSource = userPro;

          //userTimeline2();
        }

        catch (Exception ex)

        {

        }

      }

    }
Ejemplo n.º 13
0
    private async void searchUser()
    {
      if (tokens != null)
      {
        user = new List<TweetClass.UserInfo>();
        try
        {
          string search_word = serchBox.Text;
          var result = await tokens.Users.SearchAsync(count => 100, q => search_word);

          //foreach (var status in await tokens.Search.TweetsAsync(q => serchBox.Text, count => 200, lang => "ja"))
          foreach (var status in result)
          {
            user.Add(new TweetClass.UserInfo
            {
              UserName = status.Name,
              UserId = status.Id,
              ScreenName = "@" + status.ScreenName,
              ProfileImageUrl = status.ProfileImageUrlHttps,
              FollowCount = status.FollowersCount,
              FavCount = status.FavouritesCount,
              FollowerCount = status.FriendsCount,
              Prof = status.Description

            });
          }
          userSearchView.ItemsSource = user;
        }
        catch (Exception ex)
        {
          //          viewTextBox.Text = ex.Source;
        }
      }
    }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            "Wake up, HinayakuBot!".COut ();
            bool ShutDownFlag = false;
            List<Task> Tasks = new List<Task> ();
            var CommandContext = new CommandContext ();
            var StatusContext = new StatusContext ();
            var cts = new System.Threading.CancellationTokenSource ();
            Tasks.Add(Task.Run(() =>  StreamObservable.StreamStart(CommandContext,StatusContext),cts.Token));
            Tasks.Add(Task.Run (() => AILogic.AI (CommandContext,StatusContext),cts.Token));
            Tasks.Add (Task.Run (() => UserInterface (CommandContext),cts.Token));
            System.Threading.Thread.Yield ();
            Task.WhenAll (Tasks).ContinueWith (x => ShutDownFlag = true);
            CommandContext.GetCommand.Subscribe (x => {
                if(x.Keys.Any(y => y == Constant.Cmd)) x[Constant.Cmd].COut();
                else if(x.Keys.Any(y => y == Constant.Cmd)&& x[Constant.Cmd] == Constant.CmdEnd) ShutDownFlag = true ;
            });

            var IDs = GetIdFromXml ();
            var Token = TokenCreate (IDs);

            var stream = Token.Streaming.UserAsObservable()
                .Timeout (TimeSpan.FromSeconds (30))
                .Retry (5)
                .Catch((Exception e) => {
                    Console.WriteLine(e.Message);
                    if(e.StackTrace != null) Console.WriteLine(e.StackTrace);
                    return Observable.Never<StatusMessage>();
                })
                .Publish ();

            stream
                .OfType<StatusMessage>()
                .Where (x => !x.Status.User.ScreenName.Contains (@"hinayakuBot"))
                .Select (x => new TwString{Name = x.Status.User.ScreenName, Text = x.Status.Text, Id = x.Status.Id})
                .Subscribe (x => Console.WriteLine(x.Text));

            while(true){
                if (ShutDownFlag == true){
                    Task.Delay (TimeSpan.FromSeconds (15)).Wait ();
                    cts.Cancel ();
                    break;
                }
            }

            "All Done".COut ();
        }
 private static List<DoubleUtf16Char> GetCodePoints(string str)
 {
     var result = new List<DoubleUtf16Char>(str.Length);
     for (var i = 0; i < str.Length; i++)
     {
         var c = str[i];
         result.Add(char.IsHighSurrogate(c)
             ? new DoubleUtf16Char(c, str[++i])
             : new DoubleUtf16Char(c));
     }
     return result;
 }
Ejemplo n.º 16
0
        private void tweet(Tokens tokens, string context, List<string> uploadFiles)
        {
            List<MediaUploadResult> results = new List<MediaUploadResult>();
            foreach (string filePath in uploadFiles)
            {
                MediaUploadResult result = tokens.Media.Upload(media: new FileInfo(filePath));
                results.Add(result);
            }

            var param = new Dictionary<string, object>();
            param.Add("status", context);
            if (0 < results.Count)
            {
                param.Add("media_ids", results.Select(x => x.MediaId));
            }

            if (this.status != null)
            {
                param.Add("in_reply_to_status_id", this.status.Id.ToString());
            }

            tokens.Statuses.UpdateAsync(param);
            resetReply();
            resetAppend();

            string message = string.Format("Tweeted: {0}", context);
            changeStatus(message, NotificationStatus.DoTweet);
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            //StreamReader sr = new StreamReader(@"account_csv.log");
            StreamReader sr = new StreamReader(args[0]);
            bool isCrawTrainData = true;
            string imagePath = "images";
            string corpusPath = "corpus";
            System.Net.WebClient wc = new System.Net.WebClient();

            ulong savedId = Properties.Settings.Default.Last_ID;
            bool isLoad = false;
            if (savedId != 0) isLoad = true;

            var tokens = TwitterAPI.getTokens();
            System.Text.RegularExpressions.Regex r =
    new System.Text.RegularExpressions.Regex(@"https?://[\w/:%#\$&\?\(\)~\.=\+\-]+");

            //画像保存用
            if (!Directory.Exists(imagePath) && isCrawTrainData) Directory.CreateDirectory(imagePath);
            //文書保存用
            if (!Directory.Exists(corpusPath) && isCrawTrainData) Directory.CreateDirectory(corpusPath);

            //ループ
            while (sr.Peek() > -1)
            {
                string id_str = sr.ReadLine().Split(',')[0];
                ulong account_id = Convert.ToUInt64(id_str);
                bool unMedia = true;

                //goto saved pointer
                if (isLoad && savedId != account_id) continue;
                if (savedId == account_id)
                {
                    isLoad = false;
                    continue;
                }

                Console.WriteLine(id_str+":");
                UserResponse user=null;

                //UserResponce取得
                userFirst:
                try
                {
                    user = tokens[nowTokenIndex].Users.Show(id => account_id);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(("user:"******"Rate limit exceeded")
                    {
                        System.Threading.Thread.Sleep(new TimeSpan(0, 1, 0));
                        goto userFirst;
                    }
                    else if (ex.Message == "Over capacity")
                    {
                        System.Threading.Thread.Sleep(new TimeSpan(0, 1, 0));
                        goto userFirst;
                    }
                }

                try
                {
                    uint counter = Properties.Settings.Default.counter;
                    List<int> RTList = new List<int>(), FavList = new List<int>();
                    List<string> myCorpus = new List<string>();
                    List<int> CorpusRT = new List<int>();
                    List<long> CorpusID = new List<long>();
                    List<string> CorpusTime = new List<string>();

                    //user info
                    userInfo uf = new userInfo(user);

                    //get tweet
                    var lines = CoreTweetExtend.GetUserTimeLines(tokens, account_id, 3000, new TimeSpan(0, 1, 0), (n) => Console.WriteLine(n));

                    //画像用ファイル
                    string myImagePath = Path.Combine(imagePath, user.Id.Value.ToString());
                    if (!Directory.Exists(myImagePath) && isCrawTrainData) Directory.CreateDirectory(myImagePath);

                    foreach (var str in lines)
                    {
                        RTList.Add(str.RetweetCount.Value);
                        FavList.Add(str.FavoriteCount.Value);

                        //Mediaのみ取得
                        if (str.Entities.Media != null || !isCrawTrainData)
                        {
                            //文章手直し
                            string replaced = r.Replace(str.Text, "");
                            replaced = replaced.Replace("\r", "");
                            replaced = replaced.Replace("\n", "");
                            if (isCrawTrainData)
                            {
                                replaced = replaced.Replace(",", "、");
                                replaced = replaced.Replace(".", "。");
                            }

                            if (replaced != "")
                            {
                                myCorpus.Add(replaced);
                                CorpusRT.Add(str.RetweetCount.Value);
                                CorpusID.Add(str.Id);
                                CorpusTime.Add(str.CreatedAt.ToString("yyyy/MM/dd HH:mm:ss"));

                                //メディア保存
                                if (isCrawTrainData)
                                {
                                    unMedia = false;
                                    string tweetPath = Path.Combine(myImagePath, str.Id.ToString());
                                    Directory.CreateDirectory(tweetPath);
                                    foreach(var media in str.Entities.Media)
                                    {
                                        string thisPath = Path.Combine(tweetPath, Path.GetFileName(media.MediaUrl));
                                        wc.DownloadFile(media.MediaUrl, thisPath);

                                        Console.WriteLine(thisPath+":"+counter);
                                    }
                                }
                            }
                        }
                    }

                    if (!unMedia)
                    {

                        //統計計算
                        uf.RTMean = RTList.Average();
                        uf.RTDev = Math.Sqrt(RTList.Select(t => Math.Pow(t - uf.RTMean, 2.0)).Sum() / RTList.Count());
                        uf.FavMean = FavList.Average();
                        uf.FavDev = Math.Sqrt(FavList.Select(t => Math.Pow(t - uf.FavMean, 2.0)).Sum() / FavList.Count());

                        //ユーザ情報書き込み
                        if (isCrawTrainData)
                        {
                            using (StreamWriter sw_ui = new StreamWriter("user_info.txt", true, Encoding.UTF8))
                            {
                                sw_ui.WriteLine(uf.ToString());
                            }
                        }

                        //コーパス書き込み
                        string mycpPath = Path.Combine(corpusPath, user.Id + ".txt");
                        using (StreamWriter cw_cp = new StreamWriter(mycpPath, true, Encoding.UTF8))
                        {
                            foreach (string cp in myCorpus.Zip(CorpusID, (first, second) => string.Format("{0},{1}", first, second)).Zip(CorpusRT, (first, second) => string.Format("{0},{1}", first, second)))
                            {
                                cw_cp.WriteLine(cp);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Properties.Settings.Default.Last_ID = account_id;
                Console.WriteLine(Properties.Settings.Default.counter);
                Properties.Settings.Default.counter++;
                Properties.Settings.Default.Save();
            }
        }
Ejemplo n.º 18
0
    public void AddInfo(List<TweetClass.UserInfo> userPro, CoreTweet.User user/*=null, CoreTweet.*/)
    {
      userPro.Add(new TweetClass.UserInfo
      {
        UserName = user.Name,
        UserId = user.Id,
        ScreenName = "@" + user.ScreenName,
        ProfileImageUrl = user.ProfileImageUrlHttps,
        FollowCount = user.FollowersCount,
        FavCount = user.FavouritesCount,
        FollowerCount = user.FriendsCount,
        Prof = user.Description

      }
);
    }
Ejemplo n.º 19
0
        public async void UpdateStatus()
        {
            taken = true;
            UpdateStatusCommand.RaiseCanExecuteChanged();

            var opt = new Dictionary<string, object>();
            opt["status"] = UpdateStatusText;
            if (IsReplying) opt["in_reply_to_status_id"] = ReplyingStatus.SourceStatus.Id;

            try
            {
                if (HasMedia)
                {
                    var iil = new List<long>();
                    foreach (var i in Medias) iil.Add((await Kbtter.Token.Media.UploadAsync(media => i.MediaStream)).MediaId);
                    opt["media_ids"] = iil;
                }

                await Kbtter.Token.Statuses.UpdateAsync(opt);
                View.Notify("ツイート送信に成功しました。");
            }
            catch (Exception te)
            {
                View.Notify("ツイート送信中にエラーが発生しました : " + te.Message);
            }


            foreach (var i in Medias) i.Dispose();
            Medias.Clear();
            RaisePropertyChanged(() => HasMedia);
            IsReplying = false;

            taken = false;
            UpdateStatusText = "";
            UpdateStatusCommand.RaiseCanExecuteChanged();
            AddMediaCommand.RaiseCanExecuteChanged();
            RemoveMediaCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 20
0
        private List<Status> getTalk(Status tweet)
        {
            List<Status> talk = new List<Status>();
            talk.Add(tweet);

            while (tweet.InReplyToStatusId != null)
            {
                tweet = getTweetFromId(this.tokens, tweet.InReplyToStatusId.ToString());
                talk.Add(tweet);
            }

            return talk;
        }
Ejemplo n.º 21
0
 public static IReadOnlyList<OptionSelectionValue> GetDecomposedValues(this OptionSelectionValue v)
 {
     var ret = new List<OptionSelectionValue>();
     var em = Enum.GetValues(typeof(OptionSelectionValue)).Cast<OptionSelectionValue>();
     foreach (var i in em) if ((v & i) != 0) ret.Add(i);
     return ret;
 }
Ejemplo n.º 22
0
        internal void AnalyzeText()
        {
            _Text = _Text
                .Replace("&amp;", "&")
                .Replace("&lt;", "<")
                .Replace("&gt;", ">");
            TextElements = new List<StatusElement>();

            var el = new List<EntityInfo>();
            if (origin.Entities != null)
            {
                if (origin.Entities.Urls != null) el.AddRange(origin.Entities.Urls.Select(p => new EntityInfo { Indices = p.Indices, Text = p.DisplayUrl, Infomation = p.ExpandedUrl.ToString(), Type = "Url" }));
                if (origin.Entities.Media != null) el.AddRange(origin.Entities.Media.Select(p => new EntityInfo { Indices = p.Indices, Text = p.DisplayUrl, Infomation = p.ExpandedUrl.ToString(), Type = "Media" }));
                if (origin.Entities.UserMentions != null) el.AddRange(origin.Entities.UserMentions.Select(p => new EntityInfo { Indices = p.Indices, Text = "@" + p.ScreenName, Infomation = p.ScreenName, Type = "Mention" }));
                if (origin.Entities.HashTags != null) el.AddRange(origin.Entities.HashTags.Select(p => new EntityInfo { Indices = p.Indices, Text = "#" + p.Text, Infomation = p.Text, Type = "Hashtag" }));
                el.Sort((x, y) => x.Indices[0].CompareTo(y.Indices[0]));
            }
            int n = 0;
            string s = _Text;
            foreach (var i in el)
            {
                i.Indices[0] = i.Indices[0] >= s.Length ? s.Length - 1 : i.Indices[0];
                var ssi = i.Indices[0] - n;
                ssi = (i.Indices[0] + ssi > s.Length) ? (s.Length - n) : ssi;
                TextElements.Add(new StatusElement { Text = s.Substring(n, ssi), Type = "None" });
                TextElements.Add(new StatusElement { Text = i.Text, Infomation = i.Infomation, Type = i.Type });
                n = (i.Indices[1] >= s.Length - 1) ? s.Length - 1 : i.Indices[1];
            }
            if (n < s.Length - 1) TextElements.Add(new StatusElement { Text = s.Substring(n), Type = "None" });
        }
Ejemplo n.º 23
0
        public TitleChildSceneOptionEdit(User[] op)
        {
            opts = op;
            osi = new int[opts.Length];
            oii = new OptionInitializationInformation[opts.Length];
            sum = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "オプション装備編集", X = 230, Y = 8 };
            type = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Blue) { Value = "装備タイプ", X = 160, Y = 32 + 8 };
            dirc = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Green) { Value = "装備方向", X = 160, Y = 64 + 8 };
            mode = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Green) { Value = "モード", X = 160, Y = 96 + 8 };
            uvdesc = new List<StringSprite>()
            {
                new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Red) { Value = "装備固有オプション1", X = 160, Y = 128 + 8 },
                new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Red) { Value = "装備固有オプション2", X = 160, Y = 160 + 8 },
                new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Red) { Value = "装備固有オプション3", X = 160, Y = 192 + 8 },
            };

            seltype = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "", X = 360, Y = 32 + 8 };
            seldirc = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "", X = 360, Y = 64 + 8 };
            selmode = new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "", X = 360, Y = 96 + 8 };
            ipuvdesc = new List<StringSprite>()
            {
                new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "", X = 360, Y = 128 + 8 },
                new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "", X = 360, Y = 160 + 8 },
                new StringSprite(CommonObjects.FontSystemMedium, CommonObjects.Colors.Black) { Value = "", X = 360, Y = 192 + 8 },
            };

            uvs = new List<StringSprite>();
            uvs.Add(type);
            uvs.Add(dirc);
            uvs.Add(mode);
            uvs.AddRange(uvdesc);

            seluvs = new List<StringSprite>();
            seluvs.Add(seltype);
            seluvs.Add(seldirc);
            seluvs.Add(selmode);
            seluvs.AddRange(ipuvdesc);

            uvsmal = new List<MenuAllocationInformation>
            {
                new MenuAllocationInformation{ X = 144, Y = 48 },
                new MenuAllocationInformation{ X = 144, Y = 80 },
                new MenuAllocationInformation{ X = 144, Y = 112 },
                new MenuAllocationInformation{ X = 144, Y = 144 },
                new MenuAllocationInformation{ X = 144, Y = 176 },
                new MenuAllocationInformation{ X = 144, Y = 208 },
            };

            for (int i = 0; i < uvsmal.Count; i++)
            {
                int ci = i;
                uvsmal[i].Upper = uvsmal[(i + uvsmal.Count - 1) % uvsmal.Count];
                uvsmal[i].Lower = uvsmal[(i + 1) % uvsmal.Count];
                uvsmal[i].AvailableChangingAction =
                    (p, v) =>
                    {
                        uvs[ci].Alpha = seluvs[ci].Alpha = v ? 1.0 : 0.5;
                    };
                if (i >= 1) uvsmal[i].IsAvailable = false;
            }

            udc = new[]
            {
                new MultiAdditionalCoroutineSprite(){HomeX=64,HomeY=64,ScaleX=0.8,ScaleY=0.4,Image=CommonObjects.ImageCursor128[2],X=64,Y=48},
                new MultiAdditionalCoroutineSprite(){HomeX=64,HomeY=64,ScaleX=0.8,ScaleY=0.4,Image=CommonObjects.ImageCursor128[3],X=64,Y=208},
            };
            selopts = new List<MultiAdditionalCoroutineSprite>();
            foreach (var i in opts)
            {
                if (i == null) continue;
                selopts.Add(new MultiAdditionalCoroutineSprite() { HomeX = 48, HomeY = 48, X = 64, Y = 128, Image = BigUserImageManager.GetUserImage(i), Alpha = 0 });
            }
            avu = selopts.Count;
            for (int i = 0; i < avu; i++)
            {
                osi[i] = 0;
                oii[i] = new OptionInitializationInformation();
            }
            selopts.Add(new MultiAdditionalCoroutineSprite() { HomeX = 48, HomeY = 48, X = 64, Y = 128, Image = CommonObjects.ImageOptionEditEnd, Alpha = 0 });
            selopts[usel].Alpha = 1;

            mc = new MultiAdditionalCoroutineSprite() { Image = CommonObjects.ImageCursor128[1], HomeX = 64, HomeY = 64, ScaleX = 0.25, ScaleY = 0.25 };
            mc.X = uvsmal[smsel].X;
            mc.Y = uvsmal[smsel].Y;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Sends a POST request with multipart/form-data as an asynchronous operation.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="prm">The parameters.</param>
        /// <param name="authorizationHeader">The OAuth header.</param>
        /// <param name="options">The connection options for the request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// <para>The task object representing the asynchronous operation.</para>
        /// <para>The Result property on the task object returns the response.</para>
        /// </returns>
        internal static async Task<AsyncResponse> HttpPostWithMultipartFormDataAsync(Uri url, KeyValuePair<string, object>[] prm, string authorizationHeader, ConnectionOptions options, CancellationToken cancellationToken, IProgress<UploadProgressInfo> progress)
        {
            if(options == null) options = ConnectionOptions.Default;

            var req = new HttpRequestMessage(HttpMethod.Post, url);
            var toDispose = new List<IDisposable>();

#if WIN_RT
            var content = new HttpMultipartFormDataContent();
            foreach(var x in prm)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var valueStream = x.Value as Stream;
                var valueInputStream = x.Value as IInputStream;
                var valueArraySegment = x.Value as ArraySegment<byte>?;
                var valueBytes = x.Value as IEnumerable<byte>;
                var valueBuffer = x.Value as IBuffer;
                var valueInputStreamReference = x.Value as IInputStreamReference;
                var valueStorageItem = x.Value as IStorageItem;

                var fileName = "file";

                if (valueStorageItem != null)
                {
                    fileName = valueStorageItem.Name;
                }
                else if (x.Value.GetType().FullName == "System.IO.FileInfo")
                {
                    var ti = x.Value.GetType().GetTypeInfo();
                    valueStream = (Stream)ti.GetDeclaredMethod("OpenRead").Invoke(x.Value, null);
                    fileName = (string)ti.GetDeclaredProperty("Name").GetValue(x.Value);
                    toDispose.Add(valueStream);
                }

                if (valueInputStreamReference != null)
                {
                    valueInputStream = await valueInputStreamReference.OpenSequentialReadAsync().AsTask().ConfigureAwait(false);
                    toDispose.Add(valueInputStream);
                }
                else if (valueStream != null)
                {
                    valueInputStream = valueStream.AsInputStream();
                }
                else if (valueArraySegment != null)
                {
                    valueBuffer = valueArraySegment.Value.Array.AsBuffer(valueArraySegment.Value.Offset, valueArraySegment.Value.Count);
                }
                else if (valueBytes != null)
                {
                    var valueByteArray = valueBytes as byte[] ?? valueBytes.ToArray();
                    valueBuffer = valueByteArray.AsBuffer();
                }

                if(valueInputStream != null)
                    content.Add(new HttpStreamContent(valueInputStream), x.Key, fileName);
                else if(valueBuffer != null)
                    content.Add(new HttpBufferContent(valueBuffer), x.Key, fileName);
                else
                    content.Add(new HttpStringContent(x.Value.ToString()), x.Key);
            }
#else
            var content = new MultipartFormDataContent();
            foreach (var x in prm)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var valueStream = x.Value as Stream;
                if (valueStream != null)
                {
                    content.Add(new StreamContent(valueStream), x.Key, "file");
                    continue;
                }

                var valueArraySegment = x.Value as ArraySegment<byte>?;
                if (valueArraySegment != null)
                {
                    content.Add(
                        new ByteArrayContent(valueArraySegment.Value.Array, valueArraySegment.Value.Offset, valueArraySegment.Value.Count),
                        x.Key, "file");
                    continue;
                }

                var valueBytes = x.Value as IEnumerable<byte>;
                if (valueBytes != null)
                {
                    content.Add(new ByteArrayContent(valueBytes as byte[] ?? valueBytes.ToArray()), x.Key, "file");
                    continue;
                }

#if FILEINFO
                var valueFileInfo = x.Value as FileInfo;
                if (valueFileInfo != null)
                {
                    valueStream = valueFileInfo.OpenRead();
                    content.Add(new StreamContent(valueStream), x.Key, valueFileInfo.Name);
                    toDispose.Add(valueStream);
                    continue;
                }
#else
                var fileInfoType = x.Value.GetType();
                if (fileInfoType.FullName == "System.IO.FileInfo")
                {
                    var ti = fileInfoType.GetTypeInfo();
                    valueStream = (Stream)ti.GetDeclaredMethod("OpenRead").Invoke(x.Value, null);
                    content.Add(new StreamContent(valueStream), x.Key, (string)ti.GetDeclaredProperty("Name").GetValue(x.Value));
                    toDispose.Add(valueStream);
                    continue;
                }
#endif

                content.Add(new StringContent(x.Value.ToString()), x.Key);
            }
#endif

            cancellationToken.ThrowIfCancellationRequested();
            req.Content = content;
            var res = await ExecuteRequest(req, authorizationHeader, options, cancellationToken, progress).ConfigureAwait(false);

            foreach (var x in toDispose)
                x.Dispose();

            return res;
        }
Ejemplo n.º 25
0
        private static int Main()
        {
            ShowAppInfo();
            Initialize();

            Settings.Load();
            CheckDownloadPath();

            var consumerKey = Settings.Current.ConsumerKey;
            var consumerSecret = Settings.Current.ConsumerSecret;
            var accessToken = Settings.Current.AccessToken;
            var accessTokenSecret = Settings.Current.AccessTokenSecret;

            try
            {
                if (!String.IsNullOrEmpty(accessToken))
                    accessToken = RijndaelEncryption.DecryptRijndael(accessToken);

                if (!String.IsNullOrEmpty(accessTokenSecret))
                    accessTokenSecret = RijndaelEncryption.DecryptRijndael(accessTokenSecret);
            }
            catch (Exception)
            {
                Console.WriteLine("Cannot read OAuth Token!");
                accessToken = null;
                accessTokenSecret = null;
            }

            Tokens tokens;
            try
            {
                tokens = GetTwitterToken(consumerKey, consumerSecret, accessToken, accessTokenSecret);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return 1;
            }

            var downloadPath = Settings.Current.DownloadPath;
            if (!Directory.Exists(downloadPath))
                Directory.CreateDirectory(downloadPath);

            var files = Directory.GetFiles(downloadPath, "*.*",
                            SearchOption.AllDirectories)
                            .Where(s => s.EndsWith(".mp4") || s.EndsWith(".jpg") || s.EndsWith(".png"));

            const int count = 200;
            long maxId = 0;
            var bRemainTweet = true;

            ListedResponse<Status> favorites = null;

            while (bRemainTweet)
            {
                var arguments = new Dictionary<string, object> {{"count", count}};
                if (maxId != 0) arguments.Add("max_id", maxId - 1);

                try
                {
                    favorites = tokens.Favorites.List(arguments);
                }
                catch (TwitterException ex)
                {
                    // Too many request: Twitter limit exceeded
                    if (ex.Status == (HttpStatusCode)429)
                    {
                        Console.WriteLine("Twitter API limit에 걸렸습니다. " +
                                          "60초 뒤에 재시도 합니다~");
                        if (favorites != null)
                        {
                            Console.WriteLine("limit이 풀리는 시간은 아래와 같습니다");
                            Console.Write(favorites.RateLimit.Reset.LocalDateTime
                                .ToString(CultureInfo.InvariantCulture));

                        }
                        Thread.Sleep(600000); // 60 초 동안 쉰다
                        continue;
                    }
                    Console.WriteLine(ex.Message);
                    return 1;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return 1;
                }

                // update max id
                maxId = favorites.Max(twt => twt.Id);

                Parallel.ForEach(favorites, twt =>
                {
                    var pathnames = new List<string>();
                    var uris = new List<string>();

                    if (twt.ExtendedEntities != null && twt.ExtendedEntities.Media != null)
                    {
                        foreach (var uri in twt.ExtendedEntities.Media.Select(media => media.MediaUrl))
                        {
                            var pathname = Path.Combine(downloadPath, uri.Segments.Last());
                            if (File.Exists(pathname)) continue;
                            pathnames.Add(pathname);
                            uris.Add(ModifyImageUri(uri.ToString()));
                        }
                    }
                    else if (twt.Entities.Urls != null)
                    {
                        foreach (var url in twt.Entities.Urls)
                        {
                            try
                            {
                                var uri = url.ExpandedUrl;
                                var htmlCode = "";
                                try
                                {
                                    var htmlwc = new WebClient();
                                    htmlCode = htmlwc.DownloadString(uri);
                                }
                                // Ex: http://www.hibrain.net/hibrainWebApp/servlet/ExtraBoardManager;jsessionid=cbf601fa30d525c2695a62ba45f1af11a728c9fa9859.e34Sc30Qb3mSc40ObxiSchiSbNb0n6jAmljGr5XDqQLvpAe?extraboardCmd=view&menu_id=29&extraboard_id=132163&group_id=132129&program_code=10&list_type=list&pageno=1
                                catch (WebException)
                                {
                                    continue;
                                }

                                var doc = new HtmlAgilityPack.HtmlDocument();
                                doc.LoadHtml(htmlCode);

                                var nodes = doc.DocumentNode.SelectNodes("//source");
                                if (nodes == null) continue;

                                foreach (var link in nodes)
                                {
                                    if (!link.Attributes.Any(x => x.Name == "type" && x.Value == "video/mp4"))
                                        continue;

                                    var attributes = link.Attributes.Where(x => x.Name == "video-src").ToList();
                                    foreach (var att in attributes)
                                    {
                                        var pathname = Path.Combine(downloadPath, att.Value.Split('/').Last());
                                        if (File.Exists(pathname)) continue;
                                        pathnames.Add(pathname);
                                        uris.Add(att.Value);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }

                    var twtxt = ShowTweet(twt);
                    Console.WriteLine(twtxt);

                    var wc = new WebClient();
                    for (var i = 0; i < uris.Count; i++)
                    {
                        try
                        {
                            Console.WriteLine(" - Downloading... {0} (Twitter image)", uris[i].ToString());
                            wc.DownloadFile(uris[i], pathnames[i]);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    Console.WriteLine();
                });

                Console.WriteLine("Limit: {0}/{1}, Reset: {2}",
                    favorites.RateLimit.Remaining,
                    favorites.RateLimit.Limit,
                    favorites.RateLimit.Reset.LocalDateTime.ToString(CultureInfo.InvariantCulture));

                if (favorites.Count < count)
                    bRemainTweet = false;
            }

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();

            Settings.Current.Save();
            return 0;
        }