Skip to content

Mastodon - Beiträge des NodeBB-Forums automatisiert posten

Linux
9 1 647
  • Ein Anfang 🙂

    2ac64792-48eb-443f-954e-9bc868cf4b82-grafik.png

    wird noch ausführlicher, aber jetzt ist Feierabend für heute.

  • Das Beispiel oben habe ich mit curl gesendet.

    curl -H 'Authorization: Bearer <Zugangs-Token>' https://nrw.social/api/v1/statuses -F 'status=Just posted a new blog: {{EntryTitle}} - {{EntryUrl}}'
    

    Den Token kann man sich hier erzeugen.

    5490f35d-27c7-4d85-a00a-c19785fb608a-grafik.png

    Jetzt suche ich noch nach einer praktikablen Lösung, das ganze zu automatisieren.

  • Mal OpenAI gefragt 🙂

    import requests
    import json
    
    if __name__ == '__main__':
    
        # Replace these with your actual Mastodon credentials and access token
        MASTODON_INSTANCE = 'https://nrw.social'
        ACCESS_TOKEN = 'ACCESS-TOKEN'
    
        def send_to_mastodon(topic_title, topic_content):
            try:
                mastodon_api = f"{MASTODON_INSTANCE}/api/v1/statuses"
                status = f"New Topic: {topic_title}\n\n{topic_content}\n\n#Python #NewTopic"
    
                # Use the Mastodon access token for authorization
                headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'}
                data = {'status': status}
    
                # Send the status update to Mastodon
                response = requests.post(mastodon_api, headers=headers, data=data)
                response.raise_for_status()
                print('Posted to Mastodon:', response.json())
            except requests.exceptions.RequestException as e:
                print('Error posting to Mastodon:', e)
    
    
        # Example usage when creating a new topic in Python
        topic_title = 'Hello Mastodon'
        topic_content = 'This is my first post from Python to Mastodon!'
    
        send_to_mastodon(topic_title, topic_content)
    
  • Und dann mal gefragt, wie ich an die letzte Topic ID komme.

    import redis
    
    # Replace these with your actual Redis configuration
    REDIS_HOST = 'localhost'
    REDIS_PORT = 6379
    REDIS_DB = 0
    
    def get_last_topic_id():
        try:
            # Connect to the Redis database
            r = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
    
            # Get the last Topic ID from the Redis list
            last_topic_id = r.lindex('topics:tid', -1)
            
            if last_topic_id is not None:
                last_topic_id = int(last_topic_id.decode())
                return last_topic_id
            else:
                print('No Topics found in Redis database.')
                return None
        except redis.exceptions.RedisError as e:
            print('Error connecting to Redis:', e)
            return None
    
    # Example usage
    last_topic_id = get_last_topic_id()
    if last_topic_id is not None:
        print('Last Topic ID:', last_topic_id)
    

    Ok, das werde ich dann am WE mal testen und in was Brauchbares umsetzen.

  • Ok, das OpenAI muss auch gefüttert werden, sonst kommt man da auch nicht weiter.

    Das obere Beispiel muss erst mal um eine Authentifizierung erweitert werden.

    # Replace these with your actual Redis configuration
    REDIS_HOST = 'localhost'
    REDIS_PORT = 6380
    REDIS_DB = 0
    REDIS_PASSWORD =  "<PASSWORD>"
    

    und

    # Connect to the Redis database with authentication (if required)
    r = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PASSWORD)
    

    Ok, war einfach. Danach kam folgende Fehlermeldung.

    :~/mastodon$ python3 main.py 
    Erfolg Redis<ConnectionPool<Connection<host=localhost,port=6380,db=0>>>
    Error connecting to Redis: WRONGTYPE Operation against a key holding the wrong kind of value
    

    Was das sein soll kann ich mir vorstellen, aber was nun? OK, OpenAI bitte arbeiten 🙂

    Darf man das von OpenAI einfach posten? Ach, da die auch keinen Quellenangaben haben und alles nur geklaut ist, kann ich das auch machen 🙂

    The error message "WRONGTYPE Operation against a key holding the wrong kind of value" in Redis typically occurs when you try to perform an operation on a key with a data type that is incompatible with that operation. In the context of NodeBB, this error might occur if the 'topics:tid' key is expected to be a Redis list, but it contains data of a different type.
    
    To investigate and resolve this issue, you can take the following steps:
    
        Check the data type of the 'topics:tid' key: Use the Redis CLI to inspect the data type of the key to verify if it is indeed a list. Open a terminal or command prompt and run the following command:
    
        bash
    
    redis-cli
    
    Then, in the Redis CLI, check the data type of the key:
    
    bash
    
        TYPE topics:tid
    
        The response should be "list" if the key is of the correct type. If it is not a list, this could be the cause of the error.
    
        Confirm NodeBB's usage of the key: Ensure that NodeBB is using the 'topics:tid' key as a list and not attempting to use it as a different data type. Check your NodeBB codebase or any plugins that might interact with this key to ensure that they treat it as a list.
    
        Clean up the incorrect data: If you find that the data in the 'topics:tid' key is of the wrong type, you might need to clean up the data. Be cautious when doing this to avoid data loss. If you are not sure about the correct approach, consider seeking help from NodeBB community forums or relevant documentation.
    
        Re-populate the correct data: After resolving any data type issues, you may need to re-populate the 'topics:tid' key with the correct data. NodeBB should handle this automatically when users create new topics, but if necessary, you can manually set the key to the correct value.
    
        Restart NodeBB: After making any changes, be sure to restart your NodeBB server to ensure that the changes take effect.
    
    Remember that modifying the Redis data directly can be risky, so it's essential to have backups and exercise caution while making any changes. If you are uncertain about how to proceed, seeking assistance from experienced NodeBB developers or the community can be beneficial.
    

    Ok, testen wir den Typ auf der Konsole.

    redis-cli -p 6380
    127.0.0.1:6380> AUTH default <PASSWORD>
    127.0.0.1:6380> OK
    127.0.0.1:6380> TYPE topics:tid
    zset
    127.0.0.1:6380> exit
    

    Ok, nun weiß ich das der Datensatz vom Type zset ist. Wir füttern wieder die Maschine.

    If the Redis key 'topics:tid' is of type "zset" (sorted set), the "WRONGTYPE Operation against a key holding the wrong kind of value" error could occur if you're trying to perform an operation on it that's only applicable to lists or other data types.
    
    In a sorted set, the elements are stored in such a way that they are ordered based on a score. Each element has a score associated with it, and the elements are sorted based on this score. This data structure is quite different from a list, which stores elements in a specific order without any associated scores.
    
    To resolve the issue, you need to ensure that the operations you perform on the 'topics:tid' key are appropriate for a sorted set data type.
    
    If you intended to use the sorted set for holding the topic IDs, here's how you can get the last topic ID from a sorted set in Python using the redis library:
    
    python
    
    import redis
    
    # Replace these with your actual Redis configuration and password (if any)
    REDIS_HOST = 'localhost'
    REDIS_PORT = 6379
    REDIS_DB = 0
    REDIS_PASSWORD = 'your-redis-password'  # Set to None if no password is used
    
    def get_last_topic_id():
        try:
            # Connect to the Redis database with authentication (if required)
            r = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PASSWORD)
    
            # Get the last Topic ID from the sorted set
            last_topic_id = r.zrange('topics:tid', -1, -1, withscores=True)
    
            if last_topic_id:
                last_topic_id = int(last_topic_id[0][0].decode())
                return last_topic_id
            else:
                print('No Topics found in the sorted set.')
                return None
        except redis.exceptions.RedisError as e:
            print('Error connecting to Redis:', e)
            return None
    
    # Example usage
    last_topic_id = get_last_topic_id()
    if last_topic_id is not None:
        print('Last Topic ID:', last_topic_id)
    
    In this code, we use the zrange command to retrieve the last element (topic ID) from the sorted set 'topics:tid' with the optional withscores=True parameter to also get the score associated with it (although in this case, the score might not be used).
    
    Make sure to replace 'localhost' and 6379 with the appropriate host and port where your Redis server is running, and set REDIS_DB to the appropriate database number used by NodeBB (usually 0). Also, replace 'your-redis-password' with the actual password used for authentication, or set it to None if no password is required.
    

    Das danach in mein Python Script eingefügt und ausprobiert.

    ~/mastodon$ python3 main.py 
    Last Topic ID: 1456
    

    Kontrolle, der letzte Beitrag in meinem Forum ist folgender.

    Passt 🙂 Jetzt kann ich weitermachen.

  • FrankMF FrankM hat am auf dieses Thema verwiesen
  • FrankMF FrankM hat am auf dieses Thema verwiesen
  • Das kleine Projekt ist erfolgreich beendet.

    ba0fddff-8579-42f7-9391-cac6f05e5912-grafik.png

    So bald ich den Code bereinigt habe, werde ich den bei gitlab.com einstellen, das es sich jeder Interessierte dort kopieren kann. Es kommt auch noch eine ausführliche Anleitung dazu.

  • Das versprochene Gitlab Repository https://gitlab.com/Bullet64/nodebb_post_to_mastodon

    Viel Spaß beim Testen 🙂

  • Uupps, da hat noch ein Test auf nicht erlaubte Kategorien gefehlt. Ich habe hier z.B. einen privaten Bereich, blöd wenn man das dann nach Mastodon schiebt, es aber niemand lesen kann weil ihm die Rechte fehlen.

    Die Kategorien kann man in der config.py eintragen.

  • Ergänzt um eine automatische Übernahme der Tags aus dem Forum. Man muss den Beiträgen in Mastodon ja auch Reichweite geben 🙂

  • OpenCloud - Storage Backends testen

    OpenCloud opencloud linux docker
    2
    0 Stimmen
    2 Beiträge
    122 Aufrufe
    FrankMF
    So, mal weiter damit beschäftigen. Also, durch meine ganze Testerei war doch ein Haufen Müll angefallen. dockeruser@opencloud:~/opencloud/deployments/examples/opencloud_full$ docker volume ls DRIVER VOLUME NAME local 0fcd6f237898477b251f3dacb6cd083996092b783f991f899b06d89befc41b1e local 1d8df3f5d41613ad93ed753ce2102a14738cf00e8e7d127ec79881660be291ab local 3b612ce20b207c226640d6b84c32c788cd0fad9f9157578c2310f4b3db63dd29 local 5dfdde733fefb9fdb805acec8338a860762e88cd0753f4bb4098a19fbcd4b6c3 local 6bd5659759fb99b0d0613175d2392ca268dbdb3bd0353b85ccdf9a6004e798c0 local 6f8881420aa0e7713ed5308e635fcb9382939b6570afbd1d776866a07f6d61f2 local 29f7d20edd9eda935041cea7af5aab0af748175d7df8f345288463753d2afa9a local 66ca6287706aac5013b458a109e7c143c4fb177670734fc7a0f68495b1c62fd4 local 74d304835ef51f91226cc22dbbd494d2ddc9a4d91badf88814cae24126efd04a local 0203eb654c1f28a60899ded4660fb101ea222a5f8c86a225d39f3e5da877f1c0 local 271c474feb2ed915afb8efa85e422461fcfdf8acd4097355841eadf33847b7ef local 569a8c34804afd5861299973bed023c0146f40c0dbda0d980b8651bbcadc7fc9 local 655b1f446b5db9749787d4be4445887dcb3d19906d4244d059a0f292a6cd5f01 local 843bb8d0d7845adab06e146c44b153b842d5a1a1d8eb3972bdee1d3cbcb7e815 local 987ee19b8639ad5fffabba276ceb1ca09af6ebc66efb007e561570589c9c53a8 local 1004f5b7b161a4fe37a07d7960740e5cd09b90d5744f1922fb3e41c1265f800a local 2043c77b57728106cbcca8b7e2d3ae2f07ddf4ca44ee21fca232526c95e07381 local 3685c81df1be0061352dfc5b0e6db8d8d9f9b0915a271f1ca53d2796a7876805 local 9581abcfb4fb42b2fabfabbc8139cc4659ca83d92a8b60041957565409293ef4 local 796650f1fa887ff0b153822b268a10aa3579f4f2ca3ce6855ff292e49b3bb6b8 local 426251107e3131a250b27b96e795355332127f19ccf1ec8252860aff5d0caec8 local bd43ceef38448db348cc34e7dc5c4fee9c834d8b6c5957b1e6cdb83cec7b0974 local d94e7ce6c0fb1f4f7b811f624b4526ea889f2f8b99d2aa1b21e79d00dfeb38d0 local e87a27c307a8be80839fae1c006273d57570bb99f60c78c95e86a1e9ea1a786c local f2b3e30406db730e2a341850243c115b6eb231f30f41f5353c7b2427de39af75 local opencloud_full_certs local opencloud_full_opencloud-apps local opencloud_full_opencloud-config local opencloud_full_opencloud-data Oje, das sieht ziemlich vermüllt aus. Dann mal ganz mutig alles löschen. Vorher alles gestoppt. docker compose down Volume löschen, nur ein Beispiel docker volume rm opencloud_full_opencloud-data Alles gelöscht. Dann mal ein Neustart docker compose up -d Jetzt sieht das schon viel besser aus. dockeruser@opencloud:~/opencloud/deployments/examples/opencloud_full$ docker volume ls DRIVER VOLUME NAME local 3737a8eab68ffdc08d6e41493346feeb2e06ef350a210213ab450775318e49f8 local opencloud_full_opencloud-apps Da ich neugierig bin, schauen wir mal rein. root@opencloud:~ ls -lha /var/lib/docker/volumes/3737a8eab68ffdc08d6e41493346feeb2e06ef350a210213ab450775318e49f8/_data/web/assets/apps/ total 8.0K drwxr-x--x 2 dockeruser dockeruser 4.0K May 19 18:25 . drwxr-x--x 3 dockeruser dockeruser 4.0K May 31 10:21 .. Vermutlich ein Speicher, wo die Web Apps was ablegen können. Der andere zeigt es dann klarer. root@opencloud-4gb-fsn1-2:~# ls -lha /var/lib/docker/volumes/opencloud_full_opencloud-apps/_data total 28K drwxr-x--x 7 dockeruser dockeruser 4.0K May 31 10:22 . drwx-----x 3 root root 4.0K May 31 10:21 .. drwxr-xr-x 2 root root 4.0K May 31 10:22 draw-io drwxr-xr-x 2 root root 4.0K May 31 10:21 external-sites drwxr-xr-x 3 root root 4.0K May 31 10:22 json-viewer drwxr-xr-x 2 root root 4.0K May 31 10:22 progress-bars drwxr-xr-x 3 root root 4.0K May 31 10:22 unzip Ok, das sollte mir erst mal reichen. Meine Installation lagert die certs ja aus, das habe ich im docker compose geändert. dockeruser@opencloud:~/opencloud/deployments/examples/opencloud_full$ ls -lha certs/ total 44K drwxr-xr-x 2 dockeruser dockeruser 4.0K May 30 05:49 . drwxr-xr-x 6 dockeruser dockeruser 4.0K May 31 10:38 .. -rw------- 1 dockeruser dockeruser 33K May 29 11:00 acme.json Im docker-compose.yml volumes: - ./certs:/certs # bind-mount acme.json Der Grund dafür ist, das ich das docker-compose nicht als root laufen haben möchte. Die Hauptdaten sind nach lokal ausgelagert. OC_CONFIG_DIR=/home/dockeruser/oc_data/config OC_DATA_DIR=/home/dockeruser/oc_data/data Somit sollte jetzt alles so passen und ich muss mal langsam mit der Spielerei aufhören
  • Minio - Objektspeicher selbst gehostet

    Linux minio linux restic
    1
    1
    0 Stimmen
    1 Beiträge
    216 Aufrufe
    Niemand hat geantwortet
  • Podman - Netzwerke prunen

    Podman podman linux
    1
    0 Stimmen
    1 Beiträge
    137 Aufrufe
    Niemand hat geantwortet
  • Linux security update [DSA 5658-1]

    Linux linux
    1
    0 Stimmen
    1 Beiträge
    282 Aufrufe
    Niemand hat geantwortet
  • Update 1.30.3 released

    Vaultwarden vaultwarden linux
    1
    0 Stimmen
    1 Beiträge
    154 Aufrufe
    Niemand hat geantwortet
  • Pycharm - Nach Stromausfall startet es nicht mehr.

    Linux pycharm linux
    1
    0 Stimmen
    1 Beiträge
    151 Aufrufe
    Niemand hat geantwortet
  • Quartz64 - SPDIF Modul

    Verschoben Quartz64 - A quartz64 linux
    2
    3
    0 Stimmen
    2 Beiträge
    353 Aufrufe
    FrankMF
    Für das bequeme Umschalten der Soundkarten kann man das Tool alsamixer benutzen. pacman -S alsa-utils Danach alsamixer [image: 1633791802992-e912744f-8f69-4b28-a50b-7ffc8a3ab399-grafik.png]
  • Linux Mint 20 “Ulyana” Cinnamon released!

    Linux linuxmint linux
    4
    0 Stimmen
    4 Beiträge
    450 Aufrufe
    FrankMF
    Gut, die AMD Grafikkarte hat mich nicht glücklich gemacht Somit ist sie jetzt Geschichte. [image: 1595690007860-3b0958a7-7c12-46cc-b4de-0aeca38ee77b-grafik.png] Nach der Installation war dann die Hardwarebeschleunigung aus. Linux Mint weist einen aber darauf hin, was man nun machen kann. [image: 1595690201876-8105abd7-23a3-41d5-a961-aba2b859dcb9-grafik.png] Ich hatte dann den empfohlenen Treiber installiert. Nach einem Neustart war dann auch die Hardwarebeschleunigung aktiv. Zwei Dinge, die mich an der AMD-Karte im Zusammenspiel mit Linux Mint 20 Cinnamon genervt haben. Suspend ging nicht Ausloggen aus der Session Da ist eine Sache die ich sehr gerne nutze, Suspend, und dann geht das nicht Meine Recherchen im Netz brachten mich zu keinem Ergebnis, deswegen die NVidia Karte. Es kann sein, das ich zu dumm war die Lösung zu finden..... Aktuelle Bildschirmeinstellung. [image: 1595690523392-989d2eb4-f8c9-4c91-b4eb-e862efabac9b-grafik.png] Braucht jemand eine AMD Radeon RX 5500 XT ???