Skip to content

Mastodon - Beiträge des NodeBB-Forums automatisiert posten

Linux
  • 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.

    https://linux-nerds.org/topic/1456/mastodon-beiträge-des-nodebb-forums-automatisiert-posten

    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 🙂

  • Firefox - Cookie Banner blocken

    Linux
    1
    0 Stimmen
    1 Beiträge
    112 Aufrufe
    Niemand hat geantwortet
  • 0 Stimmen
    25 Beiträge
    3k Aufrufe
    FrankMF

    Hallo @wooshell , erst mal sehr schade das Du so einen Stress mit dem Board hast. Ich habe das jetzt schon Monate laufen, übrigens ohne einen Kühler. Ok, wird ordentlich warm aber ich hasse Lüfter 😉

    Ich kann leider nicht so richtig erkennen, wo dein Problem liegt. Wie groß ist dein Speicher? Ist der in der Liste der unterstützen RAM Riegel?

    Das habe ich verbaut.

    RAM: Corsair Vengeance SODIMM 32GB (2x16GB) DDR4 2400MHz CL16 https://www.corsair.com/de/de/Kategorien/Produkte/Arbeitsspeicher/VENGEANCE-DDR4-SODIMM/p/CMSX32GX4M2A2400C16

    Aus dem Bauch heraus, würde ich auf RAM tippen.

  • Firefox mit .deb Paket

    Linux
    3
    0 Stimmen
    3 Beiträge
    108 Aufrufe
    FrankMF

    Wer auch wie ich das Problem hat, das manche Webseiten keinen Text mehr anzeigen. Ich habe da was gefunden.

    Link Preview Image Flatpak Firefox 112 not showing (some? bitmap?) fonts in Debian

    favicon

    (neilzone.co.uk)

  • 0 Stimmen
    2 Beiträge
    247 Aufrufe
    FrankMF

    Hier kurz vor dem Abschluss der Spiegelung.

    d54abd23-aa52-482d-b9e1-52ece09106ec-grafik.png

    Und alles wieder gut und eine Menge gelernt 🤓

    594b6283-bbbe-4cec-8401-d57cce52012b-grafik.png

  • 0 Stimmen
    1 Beiträge
    163 Aufrufe
    Niemand hat geantwortet
  • 0 Stimmen
    1 Beiträge
    170 Aufrufe
    Niemand hat geantwortet
  • LUKS verschlüsselte Platte mounten

    Linux
    2
    0 Stimmen
    2 Beiträge
    663 Aufrufe
    FrankMF

    So, jetzt das ganze noch einen Ticken komplizierter 🙂

    Ich habe ja heute, für eine Neuinstallation von Ubuntu 20.04 Focal eine zweite NVMe SSD eingebaut. Meinen Bericht zu dem Thema findet ihr hier. Aber, darum soll es jetzt hier nicht gehen.

    Wir haben jetzt zwei verschlüsselte Ubuntu NVMe SSD Riegel im System. Jetzt klappt die ganze Sache da oben nicht mehr. Es kommt immer einen Fehlermeldung.

    unbekannter Dateisystemtyp „LVM2_member“.

    Ok, kurz googlen und dann findet man heraus, das es nicht klappen kann, weil beide LVM Gruppen, den selben Namen benutzen.

    root@frank-MS-7C37:/mnt/crypthome/root# vgdisplay --- Volume group --- VG Name vgubuntu2 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size <464,53 GiB PE Size 4,00 MiB Total PE 118919 Alloc PE / Size 118919 / <464,53 GiB Free PE / Size 0 / 0 VG UUID lpZxyv-cNOS-ld2L-XgvG-QILa-caHS-AaIC3A --- Volume group --- VG Name vgubuntu System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <475,71 GiB PE Size 4,00 MiB Total PE 121781 Alloc PE / Size 121781 / <475,71 GiB Free PE / Size 0 / 0 VG UUID jRYTXL-zjpY-lYr6-KODT-u0LJ-9fYf-YVDna7

    Hier oben sieht man das schon mit geändertem Namen. Der VG Name muss unterschiedlich sein. Auch dafür gibt es ein Tool.

    root@frank-MS-7C37:/mnt/crypthome/root# vgrename --help vgrename - Rename a volume group Rename a VG. vgrename VG VG_new [ COMMON_OPTIONS ] Rename a VG by specifying the VG UUID. vgrename String VG_new [ COMMON_OPTIONS ] Common options for command: [ -A|--autobackup y|n ] [ -f|--force ] [ --reportformat basic|json ] Common options for lvm: [ -d|--debug ] [ -h|--help ] [ -q|--quiet ] [ -v|--verbose ] [ -y|--yes ] [ -t|--test ] [ --commandprofile String ] [ --config String ] [ --driverloaded y|n ] [ --nolocking ] [ --lockopt String ] [ --longhelp ] [ --profile String ] [ --version ] Use --longhelp to show all options and advanced commands.

    Das muss dann so aussehen!

    vgrename lpZxyv-cNOS-ld2L-XgvG-QILa-caHS-AaIC3A vgubuntu2 ACHTUNG Es kann zu Datenverlust kommen, also wie immer, Hirn einschalten!

    Ich weiß, das die erste eingebaute Platte mit der Nummer /dev/nvme0n1 geführt wird. Die zweite, heute verbaute, hört dann auf den Namen /dev/nvme1n1. Die darf ich nicht anpacken, weil sonst das System nicht mehr startet.

    /etc/fstab

    # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> /dev/mapper/vgubuntu-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/nvme1n1p2 during installation UUID=178c7e51-a1d7-4ead-bbdf-a956eb7b754f /boot ext4 defaults 0 2 # /boot/efi was on /dev/nvme0n1p1 during installation UUID=7416-4553 /boot/efi vfat umask=0077 0 1 /dev/mapper/vgubuntu-swap_1 none swap sw 0 0

    Jo, wenn jetzt die Partition /dev/mapper/vgubuntu2-root / anstatt /dev/mapper/vgubuntu-root / heißt läuft nichts mehr. Nur um das zu verdeutlichen, auch das könnte man problemlos reparieren. Aber, ich möchte nur warnen!!

    Nachdem die Änderung durchgeführt wurde, habe ich den Rechner neugestartet. Puuh, Glück gehabt, richtige NVMe SSD erwischt 🙂

    Festplatte /dev/mapper/vgubuntu2-root: 463,58 GiB, 497754832896 Bytes, 972177408 Sektoren Einheiten: Sektoren von 1 * 512 = 512 Bytes Sektorgröße (logisch/physikalisch): 512 Bytes / 512 Bytes E/A-Größe (minimal/optimal): 512 Bytes / 512 Bytes

    Nun können wir die Platte ganz normal, wie oben beschrieben, mounten. Nun kann ich noch ein paar Dinge kopieren 😉

  • SCP mit IPv6 nutzen

    Linux
    1
    0 Stimmen
    1 Beiträge
    206 Aufrufe
    Niemand hat geantwortet