Code Monkey home page Code Monkey logo

Comments (2)

valcanobacon avatar valcanobacon commented on June 19, 2024 1

Made a little Proof of Concept (PoC) and it works fine. When the Boost comes in it needs to pull the RSS feed and find related item. I did not except the ID of the status on the local server to be different then that on the remote server; It needs to find the local ID via the V2 search API before posting a reply.

import asyncio
import atoot
import logging
import requests
from urllib.parse import urlparse
from bs4 import BeautifulSoup
from uuid import uuid4

mastodon_instance='noagendasocial.com'
mastodon_access_token='REDACTED'

feed_url='https://feeds.podcastindex.org/pc20.xml'
episode_title='Episode 134: ChapterGPT'
episode_guid='PC20134'

logging.getLogger().setLevel(logging.DEBUG)


async def main():
    logging.info("Start")
    mastodon = await atoot.MastodonAPI.create(
        mastodon_instance, access_token=mastodon_access_token
    )
    resp = await mastodon.verify_account_credentials()
    logging.debug(resp)
    logging.info(f"Connected to {mastodon_instance}")

    reply_to_id = None

    response = requests.get(feed_url)
    if response.status_code in [requests.status_codes.codes.ok]:
        soup = BeautifulSoup(response.text, "lxml")
        items = soup.find_all(["podcast:liveitem", "item"])
        item = next(filter(lambda x: x.title.get_text() == episode_title or x.guid.get_text() == episode_guid, items), None)
        if item is not None:
            social_interact = item.find("podcast:socialinteract", protocol="activitypub")
            if social_interact is not None and social_interact['uri'] is not None:
                status = await mastodon.search(social_interact['uri'], resolve=True)
                if status is not None and status.get('statuses'):
                    reply_to_id = status.get('statuses', [{}])[0].get('id')

    print(reply_to_id)
            
    resp = await mastodon.create_status(
       status=str(uuid4()),
       in_reply_to_id=reply_to_id,
    )
    logging.debug(resp)

    await mastodon.close()
    logging.info(f"Closed")

asyncio.run(main())

from boostbots.

valcanobacon avatar valcanobacon commented on June 19, 2024

brilliant

from boostbots.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.