[PR] カード 比較

Python Selenium でTwitter 投稿

# dnf install google-chrome

=========================================================================================================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
=========================================================================================================================
依存関係のインストール中:
google-chrome-unstable x86_64 87.0.4280.11-1 google-chrome 72 M


# pip install chromedriver-binary==87.0.4280.11-1
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting chromedriver-binary==87.0.4280.11-1
Could not find a version that satisfies the requirement chromedriver-binary==87.0.4280.11-1 (from versions: 2.29.1, 2.31.1, 2.33.1, 2.34.0, 2.35.0, 2.35.1, 2.36.0, 2.37.0, 2.38.0, 2.39.0, 2.40.1, 2.41.0, 2.42.0, 2.43.0, 2.44.0, 2.45.0, 2.46.0, 70.0.3538.16.0, 70.0.3538.67.0, 70.0.3538.97.0, 71.0.3578.30.0, 71.0.3578.33.0, 71.0.3578.80.0, 71.0.3578.137.0, 72.0.3626.7.0, 72.0.3626.69.0, 73.0.3683.20.0, 73.0.3683.68.0, 74.0.3729.6.0, 75.0.3770.8.0, 75.0.3770.90.0, 75.0.3770.140.0, 76.0.3809.12.0, 76.0.3809.25.0, 76.0.3809.68.0, 76.0.3809.126.0, 77.0.3865.10.0, 77.0.3865.40.0, 78.0.3904.11.0, 78.0.3904.70.0, 78.0.3904.105.0, 79.0.3945.16.0, 79.0.3945.36.0, 80.0.3987.16.0, 80.0.3987.106.0, 81.0.4044.20.0, 81.0.4044.69.0, 81.0.4044.138.0, 83.0.4103.14.0, 83.0.4103.39.0, 84.0.4147.30.0, 85.0.4183.38.0, 85.0.4183.83.0, 85.0.4183.87.0, 86.0.4240.22.0)
No matching distribution found for chromedriver-binary==87.0.4280.11-1

最も近いバージョンをインストール
# pip install chromedriver-binary==86.0.4240.22.0
Collecting chromedriver-binary==86.0.4240.22.0
Downloading https://files.pythonhosted.org/packages/08/85/4a12e3ea067901e76a68e5a63cd9237b4959a4558a22594fcfcd47ebf648/chromedriver-binary-86.0.4240.22.0.tar.gz
/usr/local/lib/python3.6/site-packages/setuptools/distutils_patch.py:26: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
"Distutils was imported before Setuptools. This usage is discouraged "
Installing collected packages: chromedriver-binary
Running setup.py install for chromedriver-binary ... done
Successfully installed chromedriver-binary-86.0.4240.22.0


python コード
```
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import chromedriver_binary

# アカウント情報
account = 'username''
password = 'password'

# ツイートしたい文字列
text = "テストツイート"

# Twitterログイン実行する処理
def login_twitter():
# ログインページを開く
driver.get('https://twitter.com/login/')
time.sleep(2) # 待ち
# account入力
element_account = driver.find_element_by_name("session[username_or_email]")
element_account.send_keys(account)
time.sleep(2) # 待ち
# パスワードを入力する
element_pass = driver.find_element_by_name("session[password]")
element_pass.send_keys(password)
time.sleep(3) # 動作止める
# ログインボタンクリック
element_login = driver.find_element_by_xpath('//*[@data-testid="LoginForm_Login_Button"]')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
element_login.click()
time.sleep(3) # 待ち

def send_tweet(text):
element_text = driver.find_element_by_class_name("notranslate")
element_text.click()
element_text.send_keys(text)
tweet_button = driver.find_element_by_xpath('//*[@data-testid="tweetButtonInline"]')
tweet_button.click()

# seleniumを起動
options=Options()
options.add_argument('--headless')
driver=webdriver.Chrome(chrome_options = options)

# ログイン処理
login_twitter()
# ツイートする
send_tweet(text)
time.sleep(10)
# seleniumを終了
driver.close()
driver.quit()

```

read more

github 移行

別のレポジトリにコピーする場合

古いレポジトリをクローン
% git clone --mirror https://username:password@github.com/XXXX/old.git

これで一式がクローンされるので、生成されたディレクトリに移動する
% cd old.git

新しいレポジトリにコピー
% git push --mirror https://sername:password@github.com/XXXX/new.git

read more

MySQL 旧バージョンでのdump取り込み

grep -l 'utf8mb4_0900_ai_ci' xxx.dmp | xargs sed -i.bak -e 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g'

read more

CentOS 8 遅い対策

# systemctl stop ksmtuned
# systemctl disable ksmtuned

# systemctl stop ksm
# systemctl disable ksm

read more

Ruby on Rails モデルの削除

# rails destroy model モデル名
# rails generate migration drop_table_モデル名s
# rake db:migrate

実行の例

% bin/rails destroy model Bookmark
Running via Spring preloader in process 65220
invoke active_record
remove db/migrate/20200314041531_create_bookmarks.rb
remove app/models/bookmark.rb
invoke test_unit
remove test/models/bookmark_test.rb
remove test/fixtures/bookmarks.yml

read more

CentOS 8 node.js yarn install

# curl -sL https://rpm.nodesource.com/setup_12.x | bash -
# dnf install -y nodejs

# curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
# dnf install -y yarn

read more

CentOS 8 MySQL インストール後


mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+

mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)


mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

> CREATE USER 'USER'@'localhost' IDENTIFIED BY 'PASSWORD';
> GRANT ALL ON *.* TO 'USER'@'localhost' WITH GRANT OPTION;
> FLUSH PRIVILEGES;


read more

CentOS 8 DNS設定

# nmcli c mod ens160 ipv4.dns 8.8.8.8,8.8.4.4

ens160 はネットワークの設定名

# vi /etc/resolv.conf
nameserver 8.8.8.8

# cat /etc/sysconfig/network-scripts/ifcfg-enp4s0f0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp4s0f0
UUID=4605bc1b-465e-4ffc-8326-fd52ff154a9b
DEVICE=enp4s0f0
ONBOOT=yes
IPADDR=192.168.10.6
PREFIX=24
GATEWAY=192.168.10.1
DNS1=8.8.8.8
DNS2=8.8.4.4

read more

CentOS 8 iptables 利用

既存のFireWallを止める
# systemctl stop firewalld.service
# systemctl mask firewalld.service
Created symlink /etc/systemd/system/firewalld.service → /dev/null.

確認
# systemctl list-unit-files | grep firewalld
firewalld.service masked

# dnf install -y iptables-services
# systemctl start iptables.service
Created symlink /etc/systemd/system/basic.target.wants/iptables.service → /usr/lib/systemd/system/iptables.service.

# systemctl list-unit-files | grep iptables
iptables.service enabled

# systemctl start ip6tables.service
# systemctl enable ip6tables.service
Created symlink /etc/systemd/system/basic.target.wants/ip6tables.service → /usr/lib/systemd/system/ip6tables.service.

# systemctl list-unit-files | grep ip6tables
ip6tables.service enabled

------------------------------------------
#clear
/sbin/iptables -F
/sbin/iptables -X
#policy
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -A INPUT -p icmp -j ACCEPT
/sbin/iptables -A INPUT -i lo -j ACCEPT
#http
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 8000 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 10000 -j ACCEPT

#ssh
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -i eth1 -p tcp --dport 22 -j ACCEPT

# rails
/sbin/iptables -A INPUT -p tcp --dport 3000 -j ACCEPT

# django
/sbin/iptables -A INPUT -p tcp --dport 8000 -j ACCEPT

#webmin
/sbin/iptables -A INPUT -s 192.168.1.1/24 -p tcp --dport 10000 -j ACCEPT


# for samba
/sbin/iptables -A INPUT -s 192.168.1.1/24 -p tcp --dport 139 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.1/24 -p udp --dport 137 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.1/24 -p udp --dport 138 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.1/24 -p tcp --dport 445 -j ACCEPT


/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

systemctl restart iptables.service
---------

#systemctl restart iptables.service

read more

CentOS 8 python 設定

python3が既にインストールされている

# which python3
/usr/bin/python3

# alternatives --config python
2 プログラムがあり 'python' を提供します。

選択 コマンド
-----------------------------------------------
*+ 1 /usr/libexec/no-python
2 /usr/bin/python3

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2

# python --version
Python 3.6.8

# update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1

read more

Recent entry

Search

Tag Cloud

Page Top