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 🙂

  • ufw - Die einfache Firewall

    Linux
    3
    0 Stimmen
    3 Beiträge
    126 Aufrufe
    FrankMF

    Beispiel um eingehend einen Port für eine IP-Adresse zu erlauben.

    ufw allow from 1.1.1.1 to any port 8000
  • 0 Stimmen
    2 Beiträge
    241 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

  • Debian 11 Bullseye released!

    Linux
    4
    0 Stimmen
    4 Beiträge
    281 Aufrufe
    FrankMF

    Mein Systemadmin auf der Arbeit meinte heute, angesprochen auf das Problem, läuft der Network-Manager? Ok, gute Frage...... Schauen wir mal.

    Ich bin mir leider nicht 100% sicher, ob er vor meinem Eingreifen lief, ich denke aber schon. Warum ich unsicher bin?

    root@debian:~# systemctl enable systemd-networkd.service Created symlink /etc/systemd/system/dbus-org.freedesktop.network1.service → /lib/systemd/system/systemd-networkd.service. Created symlink /etc/systemd/system/multi-user.target.wants/systemd-networkd.service → /lib/systemd/system/systemd-networkd.service. Created symlink /etc/systemd/system/sockets.target.wants/systemd-networkd.socket → /lib/systemd/system/systemd-networkd.socket. Created symlink /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service → /lib/systemd/system/systemd-networkd-wait-online.service.

    Ok, danach

    root@debian:~# systemctl start systemd-networkd.service root@debian:~# systemctl status systemd-networkd.service ● systemd-networkd.service - Network Service Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; ven> Active: active (running) since Tue 2021-08-17 17:36:38 CEST; 6s ago TriggeredBy: ● systemd-networkd.socket Docs: man:systemd-networkd.service(8) Main PID: 1288 (systemd-network) Status: "Processing requests..." Tasks: 1 (limit: 19087) Memory: 3.9M CPU: 39ms CGroup: /system.slice/systemd-networkd.service └─1288 /lib/systemd/systemd-networkd Aug 17 17:36:38 debian systemd[1]: Starting Network Service... Aug 17 17:36:38 debian systemd-networkd[1288]: enp25s0: Gained IPv6LL Aug 17 17:36:38 debian systemd-networkd[1288]: Enumeration completed Aug 17 17:36:38 debian systemd[1]: Started Network Service.

    Danach ging immer noch nix.

    root@debian:/etc/network# ^C root@debian:/etc/network# nmcli device show GENERAL.DEVICE: wlx7cdd907cbec2 GENERAL.TYPE: wifi GENERAL.HWADDR: BA:59:C0:76:C7:F5 GENERAL.MTU: 1500 GENERAL.STATE: 20 (nicht verfügbar) GENERAL.CONNECTION: -- GENERAL.CON-PATH: -- GENERAL.DEVICE: enp25s0 GENERAL.TYPE: ethernet GENERAL.HWADDR: 30:9C:23:60:C6:8E GENERAL.MTU: 1500 GENERAL.STATE: 10 (nicht verwaltet) GENERAL.CONNECTION: -- GENERAL.CON-PATH: -- WIRED-PROPERTIES.CARRIER: an IP4.ADDRESS[1]: 192.168.3.169/24 IP4.GATEWAY: 192.168.3.1 IP4.ROUTE[1]: dst = 192.168.3.0/24, nh = 0.0.0.0, mt = 0 IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 192.168.3.1, mt = 0 IP6.ADDRESS[1]: 2a02:908:1260:13bc:329c:23ff:xxxx:xxxx/64 IP6.ADDRESS[2]: fd8a:6ff:2880:0:329c:23ff:fe60:c68e/64 IP6.ADDRESS[3]: fe80::329c:23ff:fe60:c68e/64 IP6.GATEWAY: fe80::e4d3:f0ff:fe8f:2354 IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 256 IP6.ROUTE[2]: dst = ::/0, nh = fe80::e4d3:f0ff:fe8f:2354, mt = 1024 IP6.ROUTE[3]: dst = 2a02:908:xxxx:xxxx::/64, nh = ::, mt = 256 IP6.ROUTE[4]: dst = fd8a:6ff:2880::/64, nh = ::, mt = 256

    Jetzt hatte ich das erste Mal einen Ansatz, wonach ich suchen musste.

    GENERAL.STATE: 10 (nicht verwaltet)

    Etwas Suche im Netz und dann das

    nano /etc/NetworkManager/NetworkManager.conf

    Inhalt der Datei

    [main] plugins=ifupdown,keyfile [ifupdown] managed=false

    Das false in true geändert. Danach ein

    systemctl restart NetworkManager

    und ich konnte den Network-Manager auf dem Desktop benutzen!?!?!?

    Bildschirmfoto vom 2021-08-17 18-07-25.png

    Irgendwas ist da durcheinander im Bullseye 😳

  • 0 Stimmen
    1 Beiträge
    161 Aufrufe
    Niemand hat geantwortet
  • 0 Stimmen
    1 Beiträge
    304 Aufrufe
    Niemand hat geantwortet
  • Restic - forget --keep-last 3 --prune

    Restic
    2
    0 Stimmen
    2 Beiträge
    578 Aufrufe
    FrankMF

    Ich habe mich damit noch ein wenig beschäftigt, die letzten drei zu behalten, ist nicht so optimal. Da es viele Optionen bei dem Befehl gibt, hier ein Ausschnitt

    Flags: -l, --keep-last n keep the last n snapshots -H, --keep-hourly n keep the last n hourly snapshots -d, --keep-daily n keep the last n daily snapshots -w, --keep-weekly n keep the last n weekly snapshots -m, --keep-monthly n keep the last n monthly snapshots -y, --keep-yearly n keep the last n yearly snapshots

    habe ich das ein wenig so angepasst, das ich denke es passt für mich.

    restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune

    Damit behalte ich auch die jeweils eines pro Monat. Und die letzten drei. Das sieht dann so aus.

    root@debian:~# ./backup2.sh repository 2f3f6147 opened successfully, password is correct Files: 38 new, 100 changed, 13268 unmodified Dirs: 0 new, 1 changed, 0 unmodified Added to the repo: 10.166 GiB processed 13406 files, 50.324 GiB in 3:24 snapshot 849f614c saved repository 2f3f6147 opened successfully, password is correct Applying Policy: keep the last 3 snapshots, 3 monthly snapshots snapshots for (host [debian], paths [/home/frank]): keep 5 snapshots: ID Time Host Tags Reasons Paths ------------------------------------------------------------------------------------ a7251cfd 2019-11-28 17:00:01 debian monthly snapshot /home/frank 283d4027 2019-12-31 17:00:01 debian monthly snapshot /home/frank ae2b96ec 2020-01-01 21:47:46 debian last snapshot /home/frank 079e00a6 2020-01-02 17:00:01 debian last snapshot /home/frank 849f614c 2020-01-03 21:08:45 debian last snapshot /home/frank monthly snapshot ------------------------------------------------------------------------------------ 5 snapshots remove 26 snapshots: ID Time Host Tags Paths ------------------------------------------------------------------ 896f16c2 2019-11-07 22:23:40 debian /home/frank b21bcf6d 2019-11-11 17:00:01 debian /home/frank f89248fb 2019-11-12 17:00:01 debian /home/frank 123ab546 2019-11-13 17:00:01 debian /home/frank b82d87d0 2019-11-18 17:00:01 debian /home/frank 040b0ab7 2019-11-19 17:00:01 debian /home/frank 7221d8ef 2019-11-20 17:00:01 debian /home/frank 84132a25 2019-11-21 17:00:01 debian /home/frank b558a52c 2019-11-25 17:00:01 debian /home/frank e5cc0c3e 2019-12-02 17:00:01 debian /home/frank 22423fa5 2019-12-03 17:00:01 debian /home/frank 39df1ab9 2019-12-04 17:00:01 debian /home/frank 98843457 2019-12-05 17:00:01 debian /home/frank b0cdd4b6 2019-12-09 17:00:01 debian /home/frank 828414f9 2019-12-10 17:00:01 debian /home/frank e34a27c3 2019-12-11 17:00:01 debian /home/frank 6e488c3b 2019-12-12 17:00:01 debian /home/frank 17898403 2019-12-16 17:00:01 debian /home/frank 1973305a 2019-12-17 17:00:01 debian /home/frank 9553bedd 2019-12-18 17:00:01 debian /home/frank fedf749d 2019-12-19 17:00:01 debian /home/frank 8e7cb876 2019-12-23 17:00:01 debian /home/frank 0bd0d102 2019-12-25 17:00:01 debian /home/frank 13d348b0 2019-12-26 17:00:01 debian /home/frank c7d960aa 2019-12-30 17:00:01 debian /home/frank f6ea9118 2020-01-01 17:00:01 debian /home/frank ------------------------------------------------------------------ 26 snapshots 26 snapshots have been removed, running prune counting files in repo building new index for repo [0:35] 100.00% 7806 / 7806 packs repository contains 7806 packs (46537 blobs) with 41.110 GiB processed 46537 blobs: 0 duplicate blobs, 0 B duplicate load all snapshots find data that is still in use for 5 snapshots [0:01] 100.00% 5 / 5 snapshots found 32654 of 46537 data blobs still in use, removing 13883 blobs will remove 0 invalid files will delete 715 packs and rewrite 752 packs, this frees 5.027 GiB [2:28] 100.00% 752 / 752 packs rewritten counting files in repo [0:01] 100.00% 6571 / 6571 packs finding old index files saved new indexes as [d137b425 f7caee99 a6e9711a] remove 35 old index files [1:13] 100.00% 1467 / 1467 packs deleted done using temporary cache in /tmp/restic-check-cache-916655151 repository 2f3f6147 opened successfully, password is correct created new cache in /tmp/restic-check-cache-916655151 create exclusive lock for repository load indexes check all packs check snapshots, trees and blobs read all data [7:47] 100.00% 6571 / 6571 items duration: 7:47 no errors were found root@debian:~#

    Am Ende seht ihr noch, wie Restic alle Files testet. Mein Script sieht jetzt so aus.

    #!/bin/bash # Script um mit Restic Daten automatisiert zu sichern! # Dient zum Sichern der Homepartition auf dem ROCKPro64 NAS! # Was soll gesichert werden? backup_pfad=/home/frank # Programm Start restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ backup $backup_pfad --exclude-file=excludes.txt restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune # Testen restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ check --read-data

    Das dann schön mit einem Cronjob laufen lassen und die Datensicherung ist erledigt 😉

  • SSHFS

    Linux
    1
    0 Stimmen
    1 Beiträge
    289 Aufrufe
    Niemand hat geantwortet
  • Upgrade auf NodeBB 1.11.0

    NodeBB
    1
    0 Stimmen
    1 Beiträge
    364 Aufrufe
    Niemand hat geantwortet