Skip to content

Commit

Permalink
simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
montezdesousa committed Jan 17, 2023
1 parent 9181c6a commit d1c5ff1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 60 deletions.
9 changes: 0 additions & 9 deletions openbb_terminal/common/behavioural_analysis/exceptions.py

This file was deleted.

67 changes: 16 additions & 51 deletions openbb_terminal/common/behavioural_analysis/reddit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from os import environ
from typing import List, Tuple
import warnings
from multiprocessing import Process, Queue
import time

import finviz
import pandas as pd
Expand All @@ -21,7 +19,6 @@
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

from openbb_terminal import config_terminal as cfg
from openbb_terminal.common.behavioural_analysis.exceptions import APITimeoutError
from openbb_terminal.common.behavioural_analysis.reddit_helpers import find_tickers
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.rich_config import console
Expand All @@ -43,46 +40,6 @@
warnings.filterwarnings("ignore", category=UserWarning, module="psaw")


def worker(func, queue):
"""Worker to run in parallel.
Parameters
----------
func : function
Function to run
queue : Queue
Queue to put the return value in
"""
ret = func()
queue.put(ret)


def get_PushshiftAPI(wait: int = 5) -> PushshiftAPI:
"""Get PushshiftAPI.
Parameters
----------
wait : int
Number of seconds to wait for PushshiftAPI to respond
Returns
-------
PushshiftAPI
PushshiftAPI object
"""

queue: Queue = Queue()
p = Process(target=worker, args=(PushshiftAPI, queue))
p.start()
time.sleep(wait)
if p.is_alive():
p.terminate()
p.join()
raise APITimeoutError

return queue.get()


@log_start_end(log=logger)
@check_api_key(
[
Expand Down Expand Up @@ -140,8 +97,10 @@ def get_watchlists(
return [], {}, 0

try:
psaw_api = get_PushshiftAPI()
except APITimeoutError:
console.print("Connecting to API...")
psaw_api = PushshiftAPI()
except Exception as e:
console.print(f"[red]{e}.[/red]\n")
return [], {}, 0

if not psaw_api:
Expand Down Expand Up @@ -258,8 +217,10 @@ def get_popular_tickers(
return pd.DataFrame()

try:
psaw_api = get_PushshiftAPI()
except APITimeoutError:
console.print("Connecting to API...")
psaw_api = PushshiftAPI()
except Exception as e:
console.print(f"[red]{e}.[/red]\n")
return pd.DataFrame()

if not psaw_api:
Expand Down Expand Up @@ -582,8 +543,10 @@ def get_spac(
subs = pd.DataFrame(columns=columns)

try:
psaw_api = get_PushshiftAPI()
except APITimeoutError:
console.print("Connecting to API...")
psaw_api = PushshiftAPI()
except Exception as e:
console.print(f"[red]{e}.[/red]\n")
return pd.DataFrame(), {}, 0

if not psaw_api:
Expand Down Expand Up @@ -835,8 +798,10 @@ def get_due_dilligence(
return pd.DataFrame()

try:
psaw_api = get_PushshiftAPI()
except APITimeoutError:
console.print("Connecting to API...")
psaw_api = PushshiftAPI()
except Exception as e:
console.print(f"[red]{e}.[/red]\n")
return pd.DataFrame()

if not psaw_api:
Expand Down

0 comments on commit d1c5ff1

Please sign in to comment.