55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
|
# 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
|