feat(run): 增加 docker build image 和执行脚本
增加 docker build image 和执行脚本 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
581db1bce5
commit
c7463b378d
@ -4,6 +4,8 @@ ADD . /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
RUN sudo apt update
|
||||
RUN sudo apt install -y python3-pip
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
CMD ["python", "main.py"]
|
||||
CMD ["python3", "main.py"]
|
||||
|
||||
6
env.sh
Executable file
6
env.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
export FF_PASSWORD=
|
||||
export FF_ACCOUNT=
|
||||
export M_INSTANCE=
|
||||
export M_TOKEN=
|
||||
export YOUR_CONTAINER_NAME=mas2ff
|
||||
2
last_id.txt
Normal file
2
last_id.txt
Normal file
@ -0,0 +1,2 @@
|
||||
107896829133801546
|
||||
107897040775908429
|
||||
78
main.py
78
main.py
@ -1,9 +1,32 @@
|
||||
from mastodon import Mastodon
|
||||
import argparse
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
import time
|
||||
|
||||
|
||||
def post_fanfou(webdrive_, fanfou_status, images=None):
|
||||
if not images:
|
||||
images = []
|
||||
# post status
|
||||
if not images:
|
||||
input_field = webdrive_.find_element(by=By.NAME, value='content')
|
||||
input_field.send_keys(fanfou_status)
|
||||
input_field.submit()
|
||||
else:
|
||||
# post with images
|
||||
pass
|
||||
|
||||
def run(instance, access_token, fanfou_account, fanfou_password):
|
||||
chrome = webdriver.Chrome()
|
||||
# login to fanfou
|
||||
chrome.get('https://m.fanfou.com/')
|
||||
login_name = chrome.find_element(by=By.NAME, value='loginname')
|
||||
login_pass = chrome.find_element(by=By.NAME, value='loginpass')
|
||||
login_name.send_keys(fanfou_account)
|
||||
login_pass.send_keys(fanfou_password)
|
||||
login_pass.submit()
|
||||
|
||||
def run(instance, access_token):
|
||||
mastodon_cli = Mastodon(
|
||||
access_token=access_token, api_base_url=instance)
|
||||
me_info = mastodon_cli.me()
|
||||
@ -12,11 +35,58 @@ def run(instance, access_token):
|
||||
me_id, exclude_replies=True)
|
||||
min_id = None
|
||||
max_id = None
|
||||
# first time run
|
||||
# init min_id
|
||||
for status in me_timeline:
|
||||
if not status['reblog'] and status['visibility'] == 'public':
|
||||
min_id = status['id']
|
||||
print(status['content'])
|
||||
break
|
||||
# if is in already posted status
|
||||
posted_ids = []
|
||||
# if file not exist, create it
|
||||
with open('last_id.txt', 'a+') as f:
|
||||
f.seek(0)
|
||||
# read lines
|
||||
posted_ids = f.readlines()
|
||||
# remove \n
|
||||
posted_ids = [x.strip() for x in posted_ids]
|
||||
print(posted_ids)
|
||||
if str(min_id) not in posted_ids:
|
||||
content = status['content'].replace('<p>', '').replace('</p>', '').replace('<br />', '\n')
|
||||
post_fanfou(chrome, content, None)
|
||||
# write to file
|
||||
with open('last_id.txt', 'a') as f:
|
||||
f.write(str(min_id) + '\n')
|
||||
posted_ids.append(min_id)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
while True:
|
||||
# get new status
|
||||
me_timeline = mastodon_cli.account_statuses(
|
||||
me_id, exclude_replies=True, min_id=min_id)
|
||||
# if no new status
|
||||
if not me_timeline:
|
||||
time.sleep(10)
|
||||
continue
|
||||
statuses = []
|
||||
for status in me_timeline:
|
||||
statuses.append(status)
|
||||
statuses.reverse()
|
||||
for status in statuses:
|
||||
if not status['reblog'] and status['visibility'] == 'public':
|
||||
if str(status['id']) not in posted_ids:
|
||||
content = status['content'].replace('<p>', '').replace('</p>', '').replace('<br />', '\n')
|
||||
print(status['id'], content)
|
||||
post_fanfou(chrome, content, None)
|
||||
with open('last_id.txt', 'a') as f:
|
||||
f.write(str(status['id']) + '\n')
|
||||
posted_ids.append(status['id'])
|
||||
time.sleep(10)
|
||||
# update min_id
|
||||
if statuses:
|
||||
min_id = statuses[-1]['id']
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Mastodon Bot')
|
||||
@ -24,3 +94,9 @@ if __name__ == '__main__':
|
||||
help='https://nofan.xyz/settings/applications')
|
||||
parser.add_argument('--mastodon-instance', dest='m_instance', required=True,
|
||||
help='https://nofan.xyz/')
|
||||
parser.add_argument('--fanfou-account', dest='ff_account', required=True,
|
||||
help='abc@def.com')
|
||||
parser.add_argument('--fanfou-password', dest='ff_password', required=True,
|
||||
help='fanfou passworad')
|
||||
args = parser.parse_args()
|
||||
run(args.m_instance, args.m_token, args.ff_account, args.ff_password)
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
requests
|
||||
Mastodon.py
|
||||
argparse
|
||||
selenium
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user