Skip to content

Commit

Permalink
added nipy to pypi repos, updated documentation and added source
Browse files Browse the repository at this point in the history
  • Loading branch information
0n4t3 committed Feb 27, 2024
1 parent 2a7c226 commit 5d4b5de
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 8 deletions.
9 changes: 9 additions & 0 deletions PyPI/build_instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Lol this is mostly here for when I forget it. But if you'd like to fork the project or otherwise want to make a python package for this script here's how to do so.

) Navigate to the source code directory

) Run python3 setup.py sdist bdist_wheel

) Run twine upload dist/*

) Enter your API Key
5 changes: 5 additions & 0 deletions PyPI/source_code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A post only Python client for Nostr, Activity Pub, and BlueSky (AT), licensed GPLv3.

Dependencies: pynostr, mastodon.py, atproto, keyring

Please be aware this client is a work in progress written by somebody who's not a developer. For assistance or further reading please see my [GitHub Repo](https://github.com/0n4t3/nipy).
1 change: 1 addition & 0 deletions PyPI/source_code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

139 changes: 139 additions & 0 deletions PyPI/source_code/nipyproto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import json
import ssl
import time
import uuid
import sys
import os
import pkg_resources
import keyring
from pynostr.event import Event
from pynostr.relay_manager import RelayManager
from pynostr.filters import FiltersList, Filters
from pynostr.message_type import ClientMessageType
from pynostr.key import PrivateKey
from pkg_resources import DistributionNotFound
from mastodon import Mastodon
from atproto import Client, client_utils

# Nostr Post Module
def nostr():
nos = (keyring.get_credential(service_name="nipy", username="nsec"))
nsec = nos.password
relay_manager = RelayManager(timeout=6) #Relay Management from PyNostr, add or remove your relays below
relay_manager.add_relay("wss://nos.lol")
relay_manager.add_relay("wss://relay.damus.io")
relay_manager.add_relay("wss://relay.primal.net")
relay_manager.add_relay("wss://offchain.pub")
relay_manager.add_relay("wss://nostr.oxtr.dev")

private_key = PrivateKey.from_nsec(nsec)
filters = FiltersList([Filters(authors=[private_key.public_key.hex()], limit=100)])
subscription_id = uuid.uuid1().hex
relay_manager.add_subscription_on_all_relays(subscription_id, filters)
event = Event(nostr_post)
event.sign(private_key.hex())

relay_manager.publish_event(event)
relay_manager.run_sync()
time.sleep(5)
while relay_manager.message_pool.has_ok_notices():
ok_msg = relay_manager.message_pool.get_ok_notice()
while relay_manager.message_pool.has_events():
event_msg = relay_manager.message_pool.get_event()
print("Nostr Post (most likely) Successful")
# End of Nostr Stuffs

# ActivityPub/Mastodon API Module
def masto():
masto_api = (keyring.get_credential(service_name="nipy", username="mastoapi"))
mastoapi = masto_api.password
masto_server = (keyring.get_credential(service_name="nipy", username="mastoserver"))
mastourl = masto_server.password
server = mastourl
token = mastoapi
mastodon = Mastodon(
access_token = token,
api_base_url = server
)

tooter = mastodon.toot(ap_post)
print("AP Post Successful: ", tooter['uri'])
# End of AP Stuffs

# BlueSky/AT Protocol Module
def at_proto():
at_name = (keyring.get_credential(service_name="nipy", username="blskyname"))
atname = at_name.password
at_api = (keyring.get_credential(service_name="nipy", username="blskyapi"))
atapi = at_api.password

client = Client()
profile = client.login(atname, atapi)
print('AT Post (most likely) Successful')

text = client_utils.TextBuilder().text(at_post)
post = client.send_post(text)
# End of BlueSky Stuffs

def configurecreds():
print("Welcome to the NIPY/ni.py credential manager. This can add or update credentials stored in Keyring, when prompted please enter information. Make sure there is no extra spaces or other unintended characters as that can prevent the script from working until you re-do this process.")
nsecinput = input("Please enter your Nostr nsec: ")
keyring.set_password("nipy", "nsec", nsecinput)
masto_apiinput = input("Please enter your Mastodon API Key: ")
keyring.set_password("nipy", "mastoapi", masto_apiinput)
masto_serverinput = input("Please enter the URL of your Mastodon API compatible server - e.g. https://example.com: ")
keyring.set_password("nipy", "mastoserver", masto_serverinput)
at_nameinput = input("Please enter your BlueSky username - e.g. username.blsky.social: ")
keyring.set_password("nipy", "blskyname", at_nameinput)
at_apiinput = input("Please enter your BlueSky app password: ")
keyring.set_password("nipy", "blskyapi", at_apiinput)
print("Credentials have been created/updated. You are now ready to make a post with ni.py")

#Help tool
def helptool():
print("NIPY, or ni.py, is a Python-based post-only client that works with the three largest non-centralized social media protocols: Nostr, Activity Pub, and the AT Protocol. Credential management is performed by the OS instead of the script with the Keyring Python module. Please run the credentials tool for initial configuration, or if you have recently updated your credentials. For assistance please check the GitHub repo at https://github.com/0n4t3/nipy or contact me on Nostr at nate@nate.mecca1.net or on Activity Pub at nate0@nerdica.net.")
print(" ")
print("NIPY is licensed GPLv3. NI.PY is also experimental software and comes with no warranties, explicit or implied.")
print(" ")
print("Thank you for using NI.PY")

#Startup Script
print("Welcome to NI.PY. Please enter broadcast to send a broadcast to all accounts, post to enter individual posts for each account, creds to perform initial setup or to re-configure existing credentials, and help for more info.")
prompt = input("Enter Option: ")

if prompt == "broadcast":
print("Enter Post to Broadcast. When finished press enter and then CTL + D on Linux/Mac or CTL + Z on Windows")
post = sys.stdin.read()
#Post Messages
print("Yeet!")
nostr_post = post
ap_post = post
at_post = post
nostr()
masto()
at_proto()

elif prompt == "post":
print("Enter Nostr Post. When finished press enter and then CTL + D on Linux/Mac or CTL + Z on Windows")
nostr_post = sys.stdin.read()
print("Nostr Post Saved :)")
print("Enter Activity Pub Post. When finished press enter and then CTL + D on Linux/Mac or CTL + Z on Windows")
ap_post = sys.stdin.read()
print("AP Post Saved :)")
print("Enter AT Protocol Post. When finished press enter and then CTL + D on Linux/Mac or CTL + Z on Windows")
at_post = sys.stdin.read()
print("AT Post Saved :)")
#Post Messages
print("Yeet!")
nostr()
masto()
at_proto()

elif prompt == "creds":
configurecreds()
elif prompt == "help":
helptool()
else:
print("Input Unrecognized, please try again.")

sys.exit()
20 changes: 20 additions & 0 deletions PyPI/source_code/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from setuptools import setup
from pathlib import Path

this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()

setup(
name='nipyproto',
version='1.1.1',
description='Post only client for Nostr, Activity Pub, and AT',
long_description=long_description,
long_description_content_type='text/markdown',
py_modules=['nipyproto'],
install_requires=['pynostr', 'mastodon.py', 'atproto', 'keyring'],
entry_points={
'console_scripts': [
'nipyproto = nipyproto:nipyproto',
],
},
)
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ Finally, this is also useful as a proof of concept. What I'd love to see is a GU
## Dependencies
`pynostr`, `mastodon.py`, and `atproto` for both versions. Additionally dependencies `keyring` and `dbus-python` for the keyring version.

## Installation (Keyring Edition)
## Installation (Pip/Pipx - Recommended)
* Install Python and Pip/Pipx. On Linux use your package manager, e.g. `apt install python3 pipx` then `pipx ensurepath` to make sure CLI prompts work. Get [Python from here](https://www.python.org/downloads/) and [Pip with these instructions](https://pip.pypa.io/en/stable/installation/) on Windows/Mac.
* Install NIPY using `pip install nipyproto` or `pipx install nipyproto`
* Run NIPY by entering `nipyproto` in your CLI. Run creds to configure creds when prompted, then you're ready to post :)


## Installation (Keyring Edition)
**Install Python & Pip**
* Use your package manager on Linux, e.g. `apt install python3 pip`
* Install [Python from here](https://www.python.org/downloads/) and [Pip with these instructions](https://pip.pypa.io/en/stable/installation/) on Windows/Mac
Expand Down Expand Up @@ -53,10 +58,9 @@ Finally, this is also useful as a proof of concept. What I'd love to see is a GU
* Install Python Dependencies with Pip `pip install setuptools pynostr mastodon.py`
* Download the latest release, and extract the simplified script.
* Run with python (e.g. `python ~/scripts/ni.py`) and consider configuring an alias
* *Note: The atproto dependency is not working on pip in Termux at the moment. You will need to use the simplified script and delete lines 15, 64-72, and 104-108 in order to run the script. I will update this if I find a fix.*
* *Note: The atproto dependency is not working standard Termux shell. It does, however, work in my Debian proot distro. The keyring version will not work in either, however, as Keyring requires a compatible Desktop Environment to delegate credential management to.*

## Installation (Simplified Version) Win/Linux/Mac

**Install Python & Pip**
* Use your package manager on Linux, e.g. `apt install python3 pip`
* Install [Python from here](https://www.python.org/downloads/) and [Pip with these instructions](https://pip.pypa.io/en/stable/installation/) on Windows/Mac
Expand All @@ -82,12 +86,8 @@ Run `pip install setuptools pynostr mastodon.py atproto`
* You can now run the script via CLI (e.g. `python3 ~/scripts/ni.py`) and you may want to consider configuring an alias

## To Do
* Look into why hashtags are misbehaving on Nostr
* Look into why hashtags & embedded posts are misbehaving on Nostr
* Look into a potential way to get links to linkify themselves on BlueSky
* Look into Atproto dependencies on Termux
* Maybe: Add a GUI and/or package it like you would a normal piece of software
* Pipe Dream: Add a tool that downloads the posts made by those you follow over a specific time period (e.g. 24hrs) and export it to a text document for consumption
* Pipe Dream: Check for replies on your posts and be able to reply to other posts

## Updates
Add this repo's [RSS feed](https://github.com/0n4t3/nipy/releases.atom) to your favorite feed reader or [just about anything](https://followanything.dns7.top/).
Expand Down

0 comments on commit 5d4b5de

Please sign in to comment.