mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 02:46:28 +00:00
Add use_tor boolean to envvars
This commit is contained in:
parent
d73b05f76c
commit
5281176e3c
@ -21,6 +21,7 @@ POSTGRES_HOST='127.0.0.1'
|
||||
POSTGRES_PORT='5432'
|
||||
|
||||
# Tor proxy for remote calls (e.g. fetching prices or sending Telegram messages)
|
||||
USE_TOR=True
|
||||
TOR_PROXY='127.0.0.1:9050'
|
||||
|
||||
# Auto unlock LND password. Only used in development docker-compose environment.
|
||||
|
@ -1,6 +1,4 @@
|
||||
from datetime import timedelta
|
||||
from tkinter import N, ON
|
||||
from tokenize import Octnumber
|
||||
from django.utils import timezone
|
||||
from api.lightning.node import LNNode
|
||||
from django.db.models import Q, Sum
|
||||
|
@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from api.models import Profile
|
||||
from api.messages import Telegram
|
||||
from api.utils import get_tor_session
|
||||
from api.utils import get_session
|
||||
from decouple import config
|
||||
import requests
|
||||
import time
|
||||
@ -15,7 +15,7 @@ class Command(BaseCommand):
|
||||
bot_token = config('TELEGRAM_TOKEN')
|
||||
updates_url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
|
||||
|
||||
session = get_tor_session()
|
||||
session = get_session()
|
||||
telegram = Telegram()
|
||||
def handle(self, *args, **options):
|
||||
"""Infinite loop to check for telegram updates.
|
||||
|
@ -1,13 +1,13 @@
|
||||
from decouple import config
|
||||
from secrets import token_urlsafe
|
||||
from api.models import Order
|
||||
from api.utils import get_tor_session
|
||||
from api.utils import get_session
|
||||
import time
|
||||
|
||||
class Telegram():
|
||||
''' Simple telegram messages by requesting to API'''
|
||||
|
||||
session = get_tor_session()
|
||||
session = get_session()
|
||||
|
||||
def get_context(user):
|
||||
"""returns context needed to enable TG notifications"""
|
||||
|
10
api/utils.py
10
api/utils.py
@ -10,12 +10,14 @@ from api.models import Order
|
||||
logger = logging.getLogger('api.utils')
|
||||
|
||||
TOR_PROXY = config('TOR_PROXY', default='127.0.0.1:9050')
|
||||
USE_TOR = config('USE_TOR', cast=bool, default=True)
|
||||
|
||||
def get_tor_session():
|
||||
def get_session():
|
||||
session = requests.session()
|
||||
# Tor uses the 9050 port as the default socks port
|
||||
session.proxies = {'http': 'socks5://' + TOR_PROXY,
|
||||
'https': 'socks5://' + TOR_PROXY}
|
||||
if USE_TOR:
|
||||
session.proxies = {'http': 'socks5://' + TOR_PROXY,
|
||||
'https': 'socks5://' + TOR_PROXY}
|
||||
return session
|
||||
|
||||
|
||||
@ -70,7 +72,7 @@ def get_exchange_rates(currencies):
|
||||
Returns the median price list.
|
||||
"""
|
||||
|
||||
session = get_tor_session()
|
||||
session = get_session()
|
||||
|
||||
APIS = config("MARKET_PRICE_APIS",
|
||||
cast=lambda v: [s.strip() for s in v.split(",")])
|
||||
|
Loading…
Reference in New Issue
Block a user