Exemplo n.º 1
0
        private void AddWrapper()
        {
            Post post = null;

            try
            {
                post = new Post(String.Empty, TweetText, _attachements.ToList());
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            var poster  = new TwitterPoster(_authCreds);
            var wrapper = new TwitterPostWrapper(post, TimeSpan.FromMilliseconds(1), _authCreds);


            wrapper.TryPost();//starts timer
            wrapper.PostingFinished += (sender, e) =>
            {
                if (e.Result) //posting was successfull
                {
                    MessageBox.Show("Tweet posted");
                }
                else
                {
                    MessageBox.Show(e.Exception.Message);//TODO:implement logging
                }
            };
        }
Exemplo n.º 2
0
        public async Task startPostingAsync(bool latest, bool popular, int delay)
        {
            int randomNum    = getRandomNum(latest, popular);
            var mainInstance = Main.getInstance();
            var status       = mainInstance.getStatusLabel();
            var comboBox     = mainInstance.getPwdComboBox();

            while (true)
            {
                status.Text = "기사 정보를 수집 중입니다.";
                List <LoginInfo> loginInfos = LoginData.getInstance().getData();

                Article targetArticle;

                var maxIndex = comboBox.Items.Count;
                comboBox.SelectedIndex = 0;
                foreach (var item in loginInfos.Select((value, i) => new { i, value }))
                {
                    if (_cancel)
                    {
                        status.Text = "중지";
                        _cancel     = false;
                        return;
                    }
                    while (true)
                    {
                        try
                        {
                            await TwitterProfileScraper.getUserProfile(item.value);

                            break;
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                            continue;
                        }
                    }
                    try
                    {
                        while (true)
                        {
                            targetArticle = await _scraper[randomNum].getArticleInfoAsync();
                            var title = targetArticle.getTitle();

                            var filter =
                                from data in _articleHistory
                                where data.Equals(title)
                                select data;

                            if (!filter.Any())
                            {
                                _articleHistory.Add(title);
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    if (_cancel)
                    {
                        status.Text = "중지";
                        _cancel     = false;
                        return;
                    }
                    var index     = item.i;
                    var loginInfo = item.value;

                    status.Text = "트위터에 기사를 포스팅 중입니다.";
                    try
                    {
                        await TwitterPoster.twitterAsync(loginInfo, targetArticle);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                        if (index + 1 >= maxIndex)
                        {
                            await Task.Delay(delay * 1000);

                            break;
                        }
                        continue;
                    }

                    status.Text = "다음 계정 대기 중";
                    if (index + 1 >= maxIndex)
                    {
                        await Task.Delay(delay * 1000);

                        break;
                    }
                    comboBox.SelectedIndex = index + 1;
                    await Task.Delay(delay * 1000);
                }
            }
        }
Exemplo n.º 3
0
        getUserProfile(LoginInfo loginInfo)
        {
            var browser = await PuppeteerInstance.getInstance();

            using (var page = await browser.NewPageAsync())
            {
                await TwitterPoster.twitterLoginAsync(loginInfo, page);

                var profileButtonHandle = await page.WaitForSelectorAsync(ProfileSelector);

                await profileButtonHandle.ClickAsync();

                await Task.Delay(3000);

                ElementHandle profilePictureHandle     = null;
                ElementHandle profileTitleHandle       = null;
                ElementHandle profileDescriptionHandle = null;
                ElementHandle profileSiteHandle        = null;
                string        imgSrc      = "";
                string        title       = "";
                string        description = "";
                string        site        = "";
                try
                {
                    profilePictureHandle = await page.WaitForSelectorAsync(PictureSelector);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                    profilePictureHandle = null;
                }
                if (profilePictureHandle != null)
                {
                    imgSrc = profilePictureHandle.GetPropertyAsync("src").Result.ToString().Replace("JSHandle:", "");
                }
                await Task.Delay(3000);

                try
                {
                    profileTitleHandle = await page.WaitForSelectorAsync(TitleSelector, new WaitForSelectorOptions { Timeout = 3000 });
                }
                catch (Exception)
                {
                    profileTitleHandle = null;
                }
                try
                {
                    profileDescriptionHandle = await page.WaitForSelectorAsync(DescriptionSelector, new WaitForSelectorOptions { Timeout = 3000 });
                }
                catch (Exception)
                {
                    profileDescriptionHandle = null;
                }
                try
                {
                    profileSiteHandle = await page.WaitForSelectorAsync(SiteSelector, new WaitForSelectorOptions { Timeout = 3000 });
                }
                catch (Exception)
                {
                    profileSiteHandle = null;
                }

                if (profileTitleHandle != null)
                {
                    title = profileTitleHandle.GetPropertyAsync("text").Result.ToString().Replace("JSHandle:", "");
                }
                if (profileDescriptionHandle != null)
                {
                    description = profileDescriptionHandle.GetPropertyAsync("textContent").Result.ToString().Replace("JSHandle:", "");
                }
                if (profileSiteHandle != null)
                {
                    site = profileSiteHandle.GetPropertyAsync("text").Result.ToString().Replace("JSHandle:", "");
                }

                var profilePicture = SaveImage(imgSrc);

                var profile = new Profile
                {
                    picture     = profilePicture,
                    title       = title,
                    description = description,
                    site        = site
                };
                FormControl(profile);
                await page.GoBackAsync();

                await Task.Delay(3000);

                await browser.CloseAsync();

                browser.Dispose();
                return(profile);
            }
        }
Exemplo n.º 4
0
        ModifyProfile(Profile profile, LoginInfo loginInfo)
        {
            var browser = await PuppeteerInstance.getInstance();

            using (var page = await browser.NewPageAsync())
            {
                try
                {
                    await TwitterPoster.twitterLoginAsync(loginInfo, page);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                    await page.GoToAsync(URL);
                }

                await Task.Delay(3000);

                var profileButtonHandle = await page.WaitForSelectorAsync(ProfileSelector);

                await profileButtonHandle.ClickAsync();

                await Task.Delay(3000);

                var modifyButtonHandle = await page.WaitForSelectorAsync(ModifyButtonSelector);

                await modifyButtonHandle.ClickAsync();

                await Task.Delay(3000);

                ElementHandle modifyPictureHandle = null;
                try
                {
                    modifyPictureHandle = await page.WaitForSelectorAsync(ModifyPictureSelector);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                    modifyPictureHandle = await page.WaitForSelectorAsync("#page-container > div.ProfileCanopy.ProfileCanopy--withNav.js-variableHeightTopBar.ProfileCanopy--large > div > div.ProfileCanopy-header.u-bgUserColor > div.AppContainer > div.ProfileCanopy-avatar > div.ProfileAvatarEditing > div.ProfileAvatarEditing-buttonContainer > button > div.ProfileAvatarEditing-addAvatarHelp");

                    await Task.Delay(3000);
                }
                var modifyTitleHandle = await page.WaitForSelectorAsync(ModifyTitleSelector);

                var modifyDescriptionHandle = await page.WaitForSelectorAsync(ModifyDescriptionSelector);

                var modifySiteHandle = await page.WaitForSelectorAsync(ModifySiteSelector);

                var saveButtonHandle = await page.WaitForSelectorAsync(SaveButtonSelector);

                await modifyPictureHandle.ClickAsync();

                byte[]       byteArrayIn = profile.picture;
                MemoryStream ms          = new MemoryStream(byteArrayIn, 0, byteArrayIn.Length);
                ms.Position = 0;
                var returnImage = Image.FromStream(ms, true);
                returnImage.Save("./ModifyTEMP.png");
                var uploadPictureHandle = await page.WaitForSelectorAsync(UploadPictureSelector);

                await uploadPictureHandle.UploadFileAsync("./ModifyTEMP.png");

                var button = await page.WaitForSelectorAsync
                                 ("#profile_image_upload_dialog-dialog > div.modal-content > div.modal-footer > button.EdgeButton.EdgeButton--primary.profile-image-save");

                await button.ClickAsync();

                await Task.Delay(3000);

                await modifyTitleHandle.FocusAsync();

                await page.Keyboard.DownAsync("Control");

                await page.Keyboard.PressAsync("A");

                await page.Keyboard.UpAsync("Control");

                await page.Keyboard.PressAsync("Backspace");

                await page.Keyboard.TypeAsync(profile.title);

                await modifyDescriptionHandle.FocusAsync();

                await page.Keyboard.DownAsync("Control");

                await page.Keyboard.PressAsync("A");

                await page.Keyboard.UpAsync("Control");

                await page.Keyboard.PressAsync("Backspace");

                await page.Keyboard.TypeAsync(profile.description);

                await modifySiteHandle.FocusAsync();

                await page.Keyboard.DownAsync("Control");

                await page.Keyboard.PressAsync("A");

                await page.Keyboard.UpAsync("Control");

                await page.Keyboard.PressAsync("Backspace");

                await page.Keyboard.TypeAsync(profile.site);

                await saveButtonHandle.ClickAsync();

                await browser.CloseAsync();

                browser.Dispose();
            }
        }
Exemplo n.º 5
0
    protected void WireUpTweetLink()
    {
        if (FlightToTweet != null)
        {
            string szTwitterURL = String.Format(System.Globalization.CultureInfo.InvariantCulture, "http://www.twitter.com/home?status={0}", HttpUtility.UrlEncode(TwitterPoster.TweetContent(FlightToTweet, Request.Url.Host)));

            lnkTweetThis.Attributes["onclick"] = "javascript:window.open('" + szTwitterURL + "', 'TweetFlight', 'height=700,width=800,scrollbars=1,menubar=1,toolbar=1');";
            lnkTweetThis.Visible = FlightToTweet.CanPost;
        }
    }