commit db3bd0afae2fc1c1996ffc2b4d9904718068e020 Author: mroxso <24775431+mroxso@users.noreply.github.com> Date: Wed Mar 27 13:19:28 2024 +0100 initial code commit (WIP) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b644aea --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/ +userdata.txt \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..2469016 --- /dev/null +++ b/main.py @@ -0,0 +1,54 @@ +# 1. Get Profile Name of User +# 2. Download all images from the profile with instaloader python library +# 3. Create a nostr account (create nostr secret key (nsec)) +# 4. Save the username toghether with the nsec in a file +# 5. Upload the images to nostr.build +# 4. Post all images to nostr account with the urls returned from nostr.build + +import instaloader +import requests +import json +import os +from PIL import Image + +# 1. Profilname des Benutzers abrufen +username = 'highperfocused' + +# 2. Alle Bilder vom Profil mit der instaloader Python-Bibliothek herunterladen +L = instaloader.Instaloader() +profile = instaloader.Profile.from_username(L.context, username) + +# os.makedirs(username, exist_ok=True) + +for post in profile.get_posts(): + L.download_post(post, target=username) + +# 3. Ein nostr-Konto erstellen (nostr secret key (nsec) erstellen) +# 4. Den Benutzernamen zusammen mit dem nsec in einer Datei speichern +# 5. Die Bilder auf nostr.build hochladen +# 6. Alle Bilder mit den von nostr.build zurückgegebenen URLs auf das nostr-Konto posten + +# Hier ist ein Platzhalter für die nostr.build-API, da sie nicht öffentlich verfügbar ist. +# Sie müssen Ihre eigenen API-Aufrufe und -Schlüssel verwenden. +nostr_api_key = 'your_nostr_api_key' +nostr_secret_key = 'your_nostr_secret_key' + +# Save the username and nostr secret key in a file +with open('keys.txt', 'a') as file: + file.write(f'{username},{nostr_secret_key}\n') + +for image in os.listdir(username): + try: + Image.open(os.path.join(username, image)) + + with open(os.path.join(username, image), 'rb') as f: + # # Upload the image to nostr.build + # response = requests.post('https://nostr.build/api/upload', files={'file': f}, headers={'Authorization': 'Bearer ' + nostr_api_key}) + # url = json.loads(response.text)['url'] + + # # Post the image to the nostr account + # response = requests.post('https://nostr.build/api/post', data={'url': url, 'nsec': nostr_secret_key}, headers={'Authorization': 'Bearer ' + nostr_api_key}) + print(f'Posted {image} to nostr account with url: dummy') + except IOError: + # file is not an image + pass diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a16d2fc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +instaloader +Pillow \ No newline at end of file