#!/usr/bin/env python3 import requests import json import telegram import re from time import sleep from telegram.error import NetworkError, Unauthorized telegram_token= "" telegram_channel="" profile_id="" telegram_bot = telegram.Bot(telegram_token) response = requests.get("https://mastodon.bida.im/api/v1/accounts/"+profile_id+"/statuses") last_id_filename = "/var/db/mastodon2telegram/"+profile_id+"_last_id_telegram.txt" last_id_file = open(last_id_filename, 'r') last_id = int(last_id_file.read()) last_id_file.close() statuses = json.loads(response.text) statuses = sorted(statuses, key=lambda k: k['created_at']) print(last_id) for status in list(filter(lambda x: int(x["id"]) > last_id, list(filter(lambda x: x["in_reply_to_account_id"] == None, statuses)))): id = int(status["id"]) print(status["created_at"]) print(id) if last_id < id: last_id = id content = status["content"] if content != "": content = re.sub(r'
', '\n', content) content = re.sub(r'
', '\n', content) content = re.sub(r'