• Activity
  • Votes
  • Comments
  • New
  • All activity
  • Showing only topics in ~tildes with the tag "python.3". Back to normal view / Search all groups
    1. Tildee — A python library for interacting with Tildes

      Update! After a few hours of struggling I managed to set up Read the docs for Tildee, it should help using the library significantly. After getting some inspiration from TAPS I thought that maybe...

      Update! After a few hours of struggling I managed to set up Read the docs for Tildee, it should help using the library significantly.

      After getting some inspiration from TAPS I thought that maybe I try to work on something vaguely similar on my own. And after… some? hours of coding today I came up with this: tildee.py (source)
      It's a wrapper for the Tildes Public/Web API that is already used by the site internally to make it work. The obvious problem with that is that it will at one point break when this unstable API is changed. It can do basically all things a normal user can do with the notable exception of applying comment labels (because I haven't gotten around to that yet).

      Example of usage for a DM reply bot (result):

      import sys
      from tildee import TildesClient
      import time
      
      # Initialize client and log in, 2FA isn't supported yet and will probably break in horrible ways
      t = TildesClient("username", "password", base_url="https://localhost:4443", verify_ssl=False)
      
      while True:
          # Retrieve the "unread messages" page and get a list of the conversations there
          unread_message_ids = t.fetch_unread_message_ids()
          for mid in unread_message_ids:
              # Access the conversation history page; this also clears the "unread" flag 
              conversation = t.fetch_conversation(mid)
              # Get the text of the last message
              text = conversation.entries[-1].content_html
              # Abort if it's from the current user (I don't think this could actually happen)
              if conversation.entries[-1].author == t.username:
                  break
              print(f"Found a message by {conversation.entries[-1].author}")
              # If the message contains a reference, reply in kind
              if "hello there" in text.lower():
                  print("Replying…")
                  t.create_message(mid, f"General {conversation.entries[-1].author}! You are a bold one.")
              # Delay before processing next unread message
              time.sleep(3)
          # Delay before next unread check
          time.sleep(60)
      

      This has a lot of potential. Haven't yet figured out potential for what, but I'll take what I can get.
      I'd be really grateful if someone with a little more experience than me (that's not exactly a high bar :P) could give me some pointers on the project's structure and the "API design", hence the ask tag. Other creative ideas for what to use this for are appreciated, too.

      47 votes