Beispiel #1
0
def get_display_status():
    group_data = []
    # _login()
    monitoring_status, messaging_status = get_application_status()
    headers = [
        "GroupMe Group ID", "Bot ID", "Bot Monitoring Status",
        "Bot Messaging Status", "Current Message", "Triggering Message"
    ]
    global_data = [
        "Global monitoring status: " + "On" if monitoring_status else "Off",
        "Global messaging status: " + "On" if messaging_status else "Off"
    ]
    if monitoring_status:
        query = "SELECT groupme_group_id FROM groupme_yahoo"
        groups = db.fetch_all(query)
        # logging.warn("groups: %s"%groups)
        for group in groups:
            g = get_group_data(group[0])
            # logging.warn("g %s"%g)
            bot_id = g['bot_id'][0:4]
            group_data.append([
                group[0], bot_id, "On" if g['status'] else "Off",
                "On" if g['messaging_status'] else "Off", g['message_num'],
                g['message_limit']
            ])
    display = {
        "headers": headers,
        "group_data": group_data,
        "global_data": global_data
    }
    return display
Beispiel #2
0
 def retrieve_by_name(self, name):
     """
     Retrieves an object by name from the database.
     """
     fetch_result = db.fetch_all("SELECT * FROM %s WHERE name = '%s'" % (self._get_table_name(), name))
     if len(fetch_result) < 1:
         raise Exception("The name '%s' doesn't exist." % name)
     return self._new_instance(list(fetch_result[0]))
Beispiel #3
0
 def retrieve_by_id(self, object_id):
     '''
     Retrieves an object by id from the database.
     '''
     fetch_result = db.fetch_all("SELECT * FROM %s WHERE id = '%d'" % (self.__table_name, object_id))
     if len(fetch_result) < 1:
         raise Exception("The id '%d' doesn't exist." % object_id)
     return self._new_instance(list(fetch_result[0]))
Beispiel #4
0
 def is_valid_name(self, name):
     """
     Returns true if the name is associated with an existing object.
     """
     fetch_result = db.fetch_all("SELECT id FROM %s WHERE name = '%s'" % (self._get_table_name(), name))
     if len(fetch_result) >= 1:
         return True
     else:
         return False
Beispiel #5
0
 def get_name_from_id(self, object_id):
     """
     Returns the name of the object that is associated with the given id.
     """
     fetch_result = db.fetch_all("SELECT name FROM %s WHERE id = '%d'" % (self._get_table_name(), object_id))
     if len(fetch_result) >= 1:
         return fetch_result[0][0]
     else:
         raise Exception("The id '%d' doesn't exist." % object_id)
Beispiel #6
0
 def get_id_from_name(self, name):
     """
     Returns the id of the object that is associated with the given name.
     """
     fetch_result = db.fetch_all("SELECT id FROM %s WHERE name = '%s'" % (self._get_table_name(), name))
     if len(fetch_result) >= 1:
         return fetch_result[0][0]
     else:
         raise Exception("The name '%s' doesn't exist." % name)
Beispiel #7
0
 def retrieve_all(self):
     '''
     Retrieves all objects of this type.
     '''
     fetch_result = db.fetch_all("SELECT id FROM %s" % self.__table_name)
     all_objects = []
     for fetch_row in fetch_result:
         all_objects.append(self.retrieve_by_id(fetch_row[0]))
     return all_objects
Beispiel #8
0
 def is_valid_id(self, object_id):
     '''
     Returns true if the id is associated with an existing object.
     '''
     fetch_result = db.fetch_all("SELECT id FROM %s WHERE id = '%d'" % (self.__table_name, object_id))
     if len(fetch_result) >= 1:
         return True
     else:
         return False
Beispiel #9
0
def archive(request):
    """
   Returns a full archive (list) of all entries, most recent at top
   """
    context = wegblob_settings.config
    context["archive"] = db.fetch_all()
    for i, entry in enumerate(context["archive"]):
        context["archive"][i]["tags"] = _format_post_tags(entry["tags"])

    response = render_to_response("wegblob-archive.html", context, context_instance=RequestContext(request))
    return response
Beispiel #10
0
def archive(request):
    """
   Returns a full archive (list) of all entries, most recent at top
   """
    context = wegblob_settings.config
    context['archive'] = db.fetch_all()
    for i, entry in enumerate(context['archive']):
        context['archive'][i]['tags'] = _format_post_tags(entry['tags'])

    response = render_to_response('wegblob-archive.html',
                                  context,
                                  context_instance=RequestContext(request))
    return response
Beispiel #11
0
def load_messages(groupme_group_id):
    msg_list = []
    if groupme_group_id:
        select = "SELECT * FROM messages WHERE groupme_group_id = %s;"
        select_values = (str(groupme_group_id), )
        raw_messages = db.fetch_all(select, values=select_values)
        for msg in raw_messages:
            msg_list.append({
                "groupme_group_id": msg[0],
                "message_object": msg[1],
                "index": msg[2],
                "sender_is_bot": msg[3]
            })
    return msg_list
Beispiel #12
0
def load_triggers(group_id):
    query = """SELECT * FROM triggers WHERE group_id=%s"""
    values = (group_id, )
    l = db.fetch_all(query, values)
    triggers = []
    for trigger in l:
        d = {
            'index': trigger[0],
            'type': trigger[1],
            'days': trigger[2],
            'periods': trigger[3],
            'status': trigger[4],
            'group_id': trigger[5]
        }
        triggers.append(d)
    return triggers
Beispiel #13
0
def process_pos(inserts):
    # Retrieve the relevant info from the database
    #p = period.g_period
    #from_date = p.first()
    #to_date = p.last()
    fmt = "SELECT Code, Cost FROM qryPO WHERE BillingPeriod='%s'"
    sql = fmt % (period.yyyymm())
    costs = {}
    for rec in db.fetch_all(sql):
        costs[str(rec[0])] = rec[1]
    
    # Add PO costs to database
    for jcode in costs:
        cost = costs[jcode]
        if not inserts.has_key(jcode): continue # can happen with '3. Sundry' for example
        #    inserts[jcode] = create_insertion(jcode)
        inserts[jcode]['InvPODatabaseCosts'] = cost
Beispiel #14
0
def daily_cal():
    data = db.fetch_all()
    answer = ''
    summary = 0

    # return data

    for row in data:
        if int(time.strftime('%d')) == time.strptime(row[3],
                                                     "%Y-%m-%d").tm_mday:
            answer += str(row[1]) + ' - ' + str(row[2]) + ' ккал\n'
            summary += row[2]

    if answer == '':
        answer = "Вы еще ничего не ели? :("
    else:
        answer += '*Всего за день: *' + str(summary) + ' ккал'

    return answer
Beispiel #15
0
 def save(self):
     """
     Saves this object.
     """
     if self._get_factory().is_valid_name(self.get_name()):
         raise Exception("The name '%s' already exists." % self.get_name())
     if self.get_id() == -1:
         # Compute the next unique id.
         fetch_result = db.fetch_all(
             "SELECT id FROM %s ORDER BY id DESC LIMIT 1" % self._get_factory()._get_table_name()
         )
         if len(fetch_result) == 0:
             self._get_data()[0] = 0
         else:
             self._get_data()[0] = int(fetch_result[0][0]) + 1
     # Add the new curve to the database.
     sql_statement = str(
         "INSERT INTO %s VALUES(%s);" % (self._get_factory()._get_table_name(), str(self._get_data()).strip("[]"))
     )
     db.execute(sql_statement)
Beispiel #16
0
import streamlit as st
import numpy as np
import pandas as pd
import datetime
from datetime import timedelta

import db
from db import Model

# Example code for database:
models = db.fetch_all()
for model in models:
  print(model.name, model.data)
# st.write('The script generate_models was last run at', models[0].data)

st.title('Stock Predictor')

# Style
st.markdown(
    """
<style>
.sidebar .sidebar-content {
  padding: 45px;
}
.streamlit-table {
  width: 400px;
}
</style>
""",
  unsafe_allow_html=True,
)