dev2main (#1)

* initial code commit

* fixes

* fix prints not showing in docker

* add github workflow

* fix naming of docker image build workflow
This commit is contained in:
PascalR 2023-04-12 16:06:00 +02:00 committed by GitHub
parent a486455113
commit c5949f7526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 97 additions and 0 deletions

38
.github/workflows/docker-image.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: Docker Build and Push
on:
push:
branches:
- main
jobs:
build_and_push:
name: Build and Push
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/timechain-nostr-bot:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM python:3.9
RUN pip install --upgrade pip
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "-u" ,"main.py"]

9
createAccount.py Normal file
View File

@ -0,0 +1,9 @@
from nostr.key import PrivateKey
private_key = PrivateKey()
public_key = private_key.public_key
print(f"Private key: {private_key.bech32()}")
print(f"Public key: {public_key.bech32()}")
print("--------------------")
print(f"Private key: {private_key.hex()}")
print(f"Public key: {public_key.hex()}")

41
main.py Normal file
View File

@ -0,0 +1,41 @@
import requests
import time
import ssl
import os
from nostr.event import Event
from nostr.relay_manager import RelayManager
from nostr.message_type import ClientMessageType
from nostr.key import PrivateKey
relay_manager = RelayManager()
relay_manager.add_relay("wss://nostr.0x50.tech")
# relay_manager.add_relay("wss://relay.damus.io")
relay_manager.open_connections({"cert_reqs": ssl.CERT_NONE}) # NOTE: This disables ssl certificate verification
time.sleep(1.25) # allow the connections to open
env_private_key = os.environ.get("PRIVATE_KEY")
# print the value of the environment variable, if it exists
if not env_private_key:
print('The environment variable "PRIVATE_KEY" is not set.')
exit(1)
private_key = PrivateKey(bytes.fromhex(env_private_key))
while True:
old_block_height = 0
url = "https://blockchain.info/latestblock"
response = requests.get(url)
data = response.json()
block_height = data["height"]
if(block_height > old_block_height):
print("Die aktuelle Bitcoin-Blockhöhe beträgt:", block_height)
event = Event(
content=str(block_height),
public_key=private_key.public_key.hex()
)
private_key.sign_event(event)
relay_manager.publish_event(event)
relay_manager.close_connections() # NEEDED?!
old_block_height = block_height
time.sleep(60)

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
requests
# time
nostr