from mastodon import Mastodon import argparse from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options 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_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--disable-gpu') chrome = webdriver.Chrome(options=chrome_options) # 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() mastodon_cli = Mastodon( access_token=access_token, api_base_url=instance) me_info = mastodon_cli.me() me_id = me_info['id'] me_timeline = mastodon_cli.account_statuses( 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('
', '').replace('
', '').replace('', '').replace('
', '').replace('