Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MathNodes/meile-plan-rest i…
Browse files Browse the repository at this point in the history
…nto main
  • Loading branch information
freQniK committed Mar 10, 2024
2 parents baba1b9 + 2d9bb19 commit c047539
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
82 changes: 82 additions & 0 deletions helpers/top-up-subscribers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/env python3
import json
import pymysql
import scrtxxs
from datetime import datetime
import pexpect
from os import path
import requests
from time import sleep

VERSION = 20240309.1613

API_DVPN_BALANCE = "https://api.sentinel.mathnodes.com/cosmos/bank/v1beta1/balances/%s/by_denom?denom=udvpn"
SATOSHI = 1000000

keyring_passphrase = scrtxxs.HotWalletPW

class TopUpSubscribers():

def __init__(self):
self.__transfer_cmd = '%s tx bank send --gas auto --gas-prices 0.2udvpn --gas-adjustment 2.0 --yes %s %s 1000000udvpn --node "%s"'



def connDB(self):
db = pymysql.connect(host=scrtxxs.MySQLHost,
port=scrtxxs.MySQLPort,
user=scrtxxs.MySQLUsername,
passwd=scrtxxs.MySQLPassword,
db=scrtxxs.MySQLDB,
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor
)

return db

def get_subscribers(self, db):

c = db.cursor()

query = "select * from meile_subscriptions where subscribe_date > '2024-03-04';"
c.execute(query)

return c.fetchall()

def top_up(self, subscribers):

for s in subscribers:
print(s)
API_URL = API_DVPN_BALANCE % s['wallet']
try:
r = requests.get(API_URL)
amtjson = r.json()

except Exception as e:
print(str(e))
continue

balance = float(int(amtjson['balance']['amount']) / SATOSHI)

if balance < 0.1:
print(f"Balance: {balance}, Sending 1dvpn to: {s['wallet']}")
transfer_cmd = self.__transfer_cmd % (scrtxxs.sentinelhub,scrtxxs.WalletAddress,s['wallet'],scrtxxs.RPC)

print(transfer_cmd)
try:
child = pexpect.spawn(transfer_cmd)

child.expect("Enter .*")
child.sendline(keyring_passphrase)
child.expect(pexpect.EOF)
except Exception as e:
print(str(e))

sleep(6)

if __name__ == "__main__":
topup = TopUpSubscribers()
subscribers = topup.get_subscribers(topup.connDB())
print(subscribers)
topup.top_up(subscribers)

2 changes: 1 addition & 1 deletion meile_plan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def add_wallet_to_plan():
tx = None
expires = None

transfer_cmd = '%s tx bank send --gas auto --gas-prices 0.2udvpn --gas-adjustment 2.0 --yes %s %s 1000000udvpn --node "%s"' % (scrtxxs.sentinelhub,
transfer_cmd = '%s tx bank send --gas auto --gas-prices 0.2udvpn --gas-adjustment 2.0 --chain-id sentinelhub-2 --yes %s %s 1000000udvpn --node "%s"' % (scrtxxs.sentinelhub,
scrtxxs.WalletAddress,
wallet,
scrtxxs.RPC)
Expand Down

0 comments on commit c047539

Please sign in to comment.