def update_table(page_current, page_size, sort_by, filter, n_clicks):
    '''
    This function automatically updates the Reddit section of the dashboard
    '''
    filtering_expressions = filter.split(' && ')
    
    if n_clicks is None:
            raise PreventUpdate
    
    else:
        dff = get_reddit()
        for filter_part in filtering_expressions:
                col_name, operator, filter_value = split_filter_part(filter_part)
        if operator in ('eq', 'ne', 'lt', 'le', 'gt', 'ge'):
                # these operators match pandas series operator method names
                dff = dff.loc[getattr(dff[col_name], operator)(filter_value)]
        elif operator == 'contains':
                dff = dff.loc[dff[col_name].str.contains(filter_value)]
        elif operator == 'datestartswith':
                # this is a simplification of the front-end filtering logic,
                # only works with complete fields in standard format
                dff = dff.loc[dff[col_name].str.startswith(filter_value)]
        if len(sort_by):
                dff = dff.sort_values(
                [col['column_id'] for col in sort_by],
                ascending=[
                col['direction'] == 'asc'
                for col in sort_by
                ],
                inplace=False)
        page = page_current
        size = page_size
        return dff.iloc[page * size: (page + 1) * size].to_dict('records')
Beispiel #2
0
def new_tweets(n):
        get_reddit()
        return print("updated reddit")
conn = sqlite3.connect('stocks.sqlite')

#instantiate dash app server using flask for easier hosting
server = Flask(__name__)
app = dash.Dash(__name__,server = server ,meta_tags=[{ "content": "width=device-width"}], external_stylesheets=[dbc.themes.BOOTSTRAP])

#used for dynamic callbacks
app.config.suppress_callback_exceptions = True

#get options flow from twitter
get_options_flow()
flow = pd.read_sql("select datetime, text from tweets order by datetime desc", conn)

#get reddit data
global dfr 
dfr = get_reddit()
                

#######################  Creating the layout  #######################


layout1 = html.Div([
                dbc.Row([dbc.Col(make_card("Enter Ticker", "success", ticker_inputs('ticker-input', 'date-picker', 36)))]) #row 1
                ,dbc.Row([dbc.Col([make_card("Twitter Order Flow", 'primary', make_table('table-sorting-filtering2', flow, '17px', 10))])
                        ,dbc.Col([make_card("Fin table ", "secondary", html.Div(id="fin-table"))])
                        ])
                , dbc.Row([make_card("select ticker", "warning", "select ticker")],id = 'cards') #row 2
                , dbc.Row([
                        dbc.Col([                                
                        dbc.Row([make_card("Wallstreet Bets New Posts", 'primary'
                                            ,[html.P(html.Button('Refresh', id='refresh'))
Beispiel #4
0
from tweet_data import get_options_flow
from fin_report_data import get_financial_report 

#Connect to sqlite database
conn = sqlite3.connect('stocks.sqlite')
#instantiate dash app server using flask for easier hosting
server = Flask(__name__)
app = dash.Dash(__name__,server = server ,meta_tags=[{ "content": "width=device-width"}], external_stylesheets=[dbc.themes.BOOTSTRAP])
server.wsgi_app = WhiteNoise(server.wsgi_app, root='static/')
#used for dynamic callbacks
app.config.suppress_callback_exceptions = True
#get options flow from twitter
get_options_flow()
flow = pd.read_sql("select datetime, text from tweets order by datetime desc", conn)
#get reddit data
get_reddit()
top_post = pd.read_sql("select title, score, post from reddit order by score desc", conn)

#creating dash layout
layout1 = html.Div([
dbc.Row([dbc.Col([make_card("Twitter Order Flow", 'primary', make_table('table-sorting-filtering2', flow, '17px', 10))])
         ,dbc.Col([make_card("Wallstreet Bets Top Daily Posts", 'primary', make_table('table-sorting-filtering', top_post, '17px', 4))])
        ],
        no_gutters=True,)#end row
, dbc.Row([dbc.Col(make_card("Enter Ticker", "success", ticker_inputs('ticker-input', 'date-picker', 36)))]) #row 2
, dbc.Row(id = 'cards')
, dbc.Row([
        dbc.Col([make_card("Fin table ", "secondary", html.Div(id="fin-table"))])
        ,dbc.Col([dbc.Row([dbc.Alert("_Charts_", color="primary")], justify = 'center')
        ,dbc.Row(html.Div(id='x-vol-1'), justify = 'center')
        , dcc.Interval(