#!/usr/bin/env python3 from settings import * from mastodon import Mastodon from os.path import exists import tweepy from lxml.html import document_fromstring def main(): if not exists(app_path): Mastodon.create_app( bot_name, api_base_url = api_url, to_file = app_path ) if not exists(user_path): mastodon = Mastodon( client_id = app_path, api_base_url = api_url ) mastodon.log_in( account_name, account_password, to_file = user_path ) mastodon_api = Mastodon( access_token = user_path, api_base_url = api_url ) mastodon_user = mastodon_api.account_verify_credentials() twitter_api = tweepy.Client( consumer_key = twitter_auth_keys['consumer_key'], consumer_secret = twitter_auth_keys['consumer_secret'], access_token = twitter_auth_keys['access_token'], access_token_secret = twitter_auth_keys['access_token_secret'] ) print(twitter_api.get_me()) timeline = mastodon_api.account_statuses(mastodon_user,exclude_replies=True) for toot in timeline: if(toot.visibility == 'public' and toot.account.id == mastodon_user.id and not toot.reblog): tootfrm(toot.content) #print(timeline) def tootfrm(content): content = content.replace('
', "\n") res = document_fromstring(content) printit(res, "") print(res.text_content()) def printit(parent, body, block=" "): for el in parent: # print(block, el, el.text_content()) if 'u-url' in el.classes: el.text = el.text_content() + "@grml.de" el.find('.//span').text = '' el.find('.//span').drop_tag() # for classname in iter(el.classes): # print(block + " " + classname) body = printit(el, body, block + " ") return body def test(): content = '

Python Test
@toot
twitter.com/mattxiv/status/152

' # parser = MyHTMLParser() content = content.replace('
', "\n") res = document_fromstring(content) print(res.text_content()) body = printit(res, "") print(body) print(res.text_content()) if __name__ == "__main__": main() #test()