Skip to content

Instantly share code, notes, and snippets.

@rssnyder
Last active April 19, 2021 17:37
Show Gist options
  • Save rssnyder/6cca56d32a2ead4f11d3390f35cab06a to your computer and use it in GitHub Desktop.
Save rssnyder/6cca56d32a2ead4f11d3390f35cab06a to your computer and use it in GitHub Desktop.
load bots into bot service
[Unit]
Description=discord-stock-ticker
Wants=basic.target
After=basic.target network.target
Before=sshd.service
[Service]
SyslogIdentifier=discord-stock-ticker
StandardOutput=syslog
StandardError=syslog
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/etc/discord-stock-ticker/discord-stock-ticker -port 8000
ExecStartPost=/etc/discord-stock-ticker/load /etc/discord-stock-ticker/client.db localhost:8000 pre
Restart=always
[Install]
WantedBy=multi-user.target
#!/bin/bash
chmod +x load
mkdir -p /etc/discord-stock-ticker
cp load /etc/discord-stock-ticker/
cp client.service /etc/systemd/system/$1.service
systemctl daemon-reload
#!/usr/bin/python3
from sqlite3 import connect
import logging
from json import dumps
from time import sleep
import sys
from requests import get, post
if len(sys.argv) < 3:
print('pass db file and url')
sys.exit(1)
sleep(2)
db_client = connect(sys.argv[1])
get_cur = db_client.cursor()
get_cur.execute(
'SELECT token, ticker, type FROM newbots'
)
while item := get_cur.fetchone():
if not item[1]:
continue
token = item[0]
ticker = item[1]
typ = item[2]
print(f'{typ}: {ticker}')
if typ == 'crypto':
crypto = True
name = ticker
else:
crypto = False
if typ != 'stock':
name = typ
else:
name = ticker
data = {
"ticker": ticker,
"name": name,
"frequency": 60,
"crypto": crypto,
"discord_bot_token": token
}
if len(sys.argv) == 4:
data['frequency'] = 2
data['set_nickname'] = True
data['set_color'] = True
print(data)
resp = post(
f'http://{sys.argv[2]}/ticker',
data=dumps(data)
)
print(resp.text)
sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment