xpostblue

package module
v0.0.0-...-e1171b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 10 Imported by: 1

README

X-POST-TO-BLUE

This Golang package provides long-form posting on Twitter Blue using the Playwright library.

Installation

To use this package, you need to have Go installed. You can install it using the following command:

go get github.com/username/xpostblue

# playwright
go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps
# Or
go install github.com/playwright-community/playwright-go/cmd/playwright@latest
playwright install --with-deps
Usage
package main

import (
	"github.com/username/x-post-to-blue"
)

func main() {
	// Create a new client
	client := xpostblue.New(true)
	// Close the client
	defer client.Close()

	// Login to Twitter
	err := client.Login("yourusername", "yourpassword")
	if err != nil {
		panic(err)
	}

	// Post a message on Twitter
    files := []string{"./images/1.jpg", "./images/2.jpg"}
	err = client.Post(true, 5, "Hello, world! and long long-text", nil)
	if err != nil {
		panic(err)
	}
}

See module test file for details.

Structs
  • ClientBody: Main client struct containing Playwright instances and page methods
  • PostLocator: Locator struct containing the elements for login and post sections
Methods
  • New(isHeadless bool) *ClientBody: Initialize a new client
  • Close(): Close the client and browser
  • Login(username, password string) error: Login to Twitter
  • Post(isPost bool, sleepSecForUpload int, msg string, files []string) error: Post a message on Twitter
Dependencies
  • Playwright Go
  • Zerolog
License

This package is released under the MIT License.

For more information on Playwright Go, visit https://github.com/mxschmitt/playwright-go.

Feel free to contribute to this package by submitting issues or pull requests on GitHub.

Documentation

Index

Constants

View Source
const (
	// /i/flow/login
	TWITTER    = "https://twitter.com"
	TWITTERPRO = "https://pro.twitter.com"
	PATHHOME   = "/home"
	PATHLOGIN  = "/i/flow/login"

	// Login section
	INPUTID   = "input[type='text']"
	BTNID     = "xpath=//span[text()='次へ']"
	INPUTPASS = "input[type='password']"
	BTNPASS   = "[data-testid='LoginForm_Login_Button']"
	INPUTTEL  = "[data-testid='ocfEnterTextTextInput']"
	BTNTEL    = "[data-testid='ocfEnterTextNextButton']"

	// Post section
	CONFIRMAREA = "[data-testid='tweetTextarea_0']"
	TOPOST      = "div[aria-label='ポストを作成']"
	INPUTMSG    = "[data-testid='tweetTextarea_0']"
	SELECTFILE  = "input[data-testid='fileInput']"
	BTNPOST     = "xpath=//span[text()='ポストする']"
)

日本語指定のため、ラベル文字列は日本語になっています。 lang=en に変更することで、UIラベルは英語になります。

Variables

This section is empty.

Functions

func SetError

func SetError(err error, msg any) error

Types

type ClickType

type ClickType int
const (
	ClickTypeClick ClickType
	ClickTypeTap
)

type ClientBody

type ClientBody struct {
	Pw      *playwright.Playwright
	Browser playwright.Browser
	Context playwright.BrowserContext
	Page    playwright.Page

	URL       *url.URL
	ClickType ClickType

	PostLocator *PostLocator

	MaxWaitSecForConfirmFIle int
	MaxWaitSecForInput       int
}

func New

func New(isHeadless bool, useDevice *string) *ClientBody

func (*ClientBody) CheckAdditionalCredentials

func (p *ClientBody) CheckAdditionalCredentials(tel string) error

CheckAdditionalCredentials 再確認のための電話番号入力画面が表示されているか確認する

func (*ClientBody) ClickBtnLogin

func (p *ClientBody) ClickBtnLogin() error

ログインページで、ClickBtnLogin IDを入力後ボタンをクリック

func (*ClientBody) ClickBtnPass

func (p *ClientBody) ClickBtnPass() error

ログインページで、ClickPassBtn パスワード入力後ボタンをクリック

func (*ClientBody) ClickBtnPost

func (p *ClientBody) ClickBtnPost(isPost bool) error

投稿ページで、ClickBtnPost 投稿ボタンをクリック

func (*ClientBody) ClickBtnTel

func (p *ClientBody) ClickBtnTel() error

ログインページで、ClickBtnTel 電話番号入力後ボタンをクリック

func (*ClientBody) Close

func (p *ClientBody) Close()

func (*ClientBody) InputFiles

func (p *ClientBody) InputFiles(with_file bool, files ...string) error

投稿ページで、InputFiles 投稿ファイルをアップロード

func (*ClientBody) InputID

func (p *ClientBody) InputID(usernameOrEmail string) error

ログインページで、InputID ユーザー名/メールアドレスを入力 ID/Email/TEL入力欄となっている

func (*ClientBody) InputPassword

func (p *ClientBody) InputPassword(password string) error

ログインページで、InputPassword パスワードを入力

func (*ClientBody) InputTel

func (p *ClientBody) InputTel(tel string) error

ログインページで、InputTel 電話番号を入力

func (*ClientBody) InputText

func (p *ClientBody) InputText(msg string) error

投稿ページで、InputText 投稿内容を入力

func (*ClientBody) IsThere

func (p *ClientBody) IsThere(locate string) (bool, error)

func (*ClientBody) Login

func (p *ClientBody) Login(username, password string, tel *string) error

func (*ClientBody) Post

func (p *ClientBody) Post(isPost bool, sleepSecForUpload int, msg string, files ...string) error

func (*ClientBody) SetClickType

func (p *ClientBody) SetClickType(clickType ClickType) *ClientBody

func (*ClientBody) SetDefaultTimeout

func (p *ClientBody) SetDefaultTimeout(sec int) *ClientBody

func (*ClientBody) SetWaitForInput

func (p *ClientBody) SetWaitForInput(sec int) *ClientBody

func (*ClientBody) SetWaitForUpdateFile

func (p *ClientBody) SetWaitForUpdateFile(sec int) *ClientBody

func (*ClientBody) ToLogin

func (p *ClientBody) ToLogin() error

ログインページへ遷移

func (*ClientBody) ToPost

func (p *ClientBody) ToPost() error

投稿ページへ遷移

func (*ClientBody) Wait

func (p *ClientBody) Wait(minWaitMillisec, ms int)

Wait 指定時間(ミリ秒)待機 minwaitmillsec引数を最低待機時間、ms引数を上限とした乱数msを追加し、待機

type PostLocator

type PostLocator struct {
	LoginURL string
	ProURL   string

	InputID   string
	BtnID     string
	InputPass string
	BtnPass   string
	// additional credentials
	InputTel string
	BtnTel   string

	ConfirmArea string
	ToPost      string
	InputMsg    string
	SelectFile  string
	BtnPost     string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL