def generategmusicplaylist(**kwargs):
    station = kwargs.get('station', None)
    genre = kwargs.get('genre', None)
    if 'station' in kwargs:
        dbtable = kwargs.get('dbtable', 'gmusicstations')
    else:
        dbtable = kwargs.get('dbtable', 'gmusicgenres')
    create_db_connection('gmusiclibrary.db')
    querystring = "SELECT id FROM " + dbtable
    if (station is not None) or (genre is not None):
        querystring = querystring + " WHERE"
    if (station is not None):
        querystring = querystring + " name LIKE '%" + station.lower(
        ).translate(removepunct).strip() + "%' AND"
    if (genre is not None):
        querystring = querystring + " name LIKE '%" + genre.lower().translate(
            removepunct).strip() + "%' AND"
    querystring = querystring + " id IS NOT NULL;"
    item_ids = read_db_table(querystring)
    for item in item_ids:
        if (station is not None):
            generateplaylistfromstation(item[0])
        else:
            generateplaylistfromgenre(item[0])
    close_db_connection()
def creategmusicplaylist(**kwargs):
    clearplaylists()
    global musicplaylisttype
    musicplaylisttype = 'gmusic'
    song = kwargs.get('song', None)
    artist = kwargs.get('artist', None)
    album = kwargs.get('album', None)
    playlist = kwargs.get('playlist', None)
    podcast = kwargs.get('podcast', None)
    if 'playlist' in kwargs and playlist is not None:
        dbtable = kwargs.get('dbtable', 'gmusicplaylists')
    elif 'podcast' in kwargs and podcast is not None:
        dbtable = kwargs.get('dbtable', 'gmusicpodcasts')
    else:
        dbtable = kwargs.get('dbtable', 'gmusicsongs')
    create_db_connection('gmusiclibrary.db')
    querystring = "SELECT id FROM " + dbtable
    if (artist is not None) or (album is not None) or (song is not None) or (
            playlist is not None) or (podcast is not None):
        querystring = querystring + " WHERE"
    if (artist is not None):
        querystring = querystring + " albumArtist LIKE '%" + artist.lower(
        ).translate(removepunct).strip() + "%' AND"
    if (album is not None):
        querystring = querystring + " album LIKE '%" + album.lower().translate(
            removepunct).strip() + "%' AND"
    if (song is not None):
        querystring = querystring + " title LIKE '%" + song.lower().translate(
            removepunct).strip() + "%' AND"
    if (playlist is not None):
        querystring = querystring + " name LIKE '%" + playlist.lower(
        ).translate(removepunct).strip() + "%' AND"
    if (podcast is not None):
        querystring = querystring + " name LIKE '%" + podcast.lower(
        ).translate(removepunct).strip() + "%' AND"
    querystring = querystring + " id IS NOT NULL"
    if (podcast is not None):
        querystring = querystring + " ORDER BY time DESC"
    querystring = querystring + ";"
    songs_ids = read_db_table(querystring)
    playlist = []
    for song in songs_ids:
        playlist.append(song[0])
    close_db_connection()
    if playlist:
        with open('gmusicplaylist.json', 'w') as output_file:
            json.dump(playlist, output_file)
Пример #3
0
    def __init__(self):

        self.db = db.create_db_connection()
        self.items = []
        self.session_data = {}

        if globals.system_log == None:
            globals.system_log = logger.create("service")

        self.data_sync = DataSync(self)
Пример #4
0
    def __init__(self):
        if globals.system_log == None:
            globals.system_log = logger.create("service")

        self.db = db.create_db_connection()

        self.controllers = controllers.Controllers(self.db)
        self.stats = DataLoggerStats()

        self.terminate_event = threading.Event()
        threading.Thread.__init__(self)
def updategmusiclibrary():
    try:
        create_db_connection('gmusiclibrary.db')
        drop_db_table('gmusicsongs')
        drop_db_table('gmusicplaylists')
        drop_db_table('gmusicstations')
        drop_db_table('gmusicgenres')
        drop_db_table('gmusicpodcasts')
        create_db_table('gmusicsongs', ['album', 'albumArtist', 'id', 'title'])
        getsongsfromlibraryandsavetodb('gmusicsongs')
        create_db_table('gmusicplaylists',
                        ['name', 'id', 'album', 'albumArtist', 'title'])
        getsongsfromplaylistandsavetodb('gmusicplaylists')
        create_db_table('gmusicstations', ['name', 'id'])
        getstationsandsavetodb('gmusicstations')
        create_db_table('gmusicgenres', ['name', 'id'])
        getgenresandsavetodb('gmusicgenres')
        create_db_table('gmusicpodcasts', ['name', 'id', 'time'])
        getpodcastsandsavetodb('gmusicpodcasts')
        commit_db_connection()
        close_db_connection()
        return True
    except Exception:
        return False
Пример #6
0
def db_DeviceDetails_by_rfiduid():

    print("Create a database connection to the DB file .db")
    conn = db.create_db_connection(database)

    #print tag_id
    print("Query the database to read Vehicle Details by RFUID")
    #vehDetail = db.select_DeviceDetails_by_rfiduid(conn, "RFID 1")

    with conn:
        vehDetail = db.select_DeviceDetails_by_rfiduid(conn, tag_id)

    if (vehDetail != None):
        vehID = vehDetail[0]
        vehName = vehDetail[1]
        BUID = vehDetail[2]
        RFUID = vehDetail[3]

        #print vehID, vehName, BUID, RFUID

    return vehID, vehName, BUID, RFUID
Пример #7
0
import logging
import configparser
from random import shuffle
from db import get_leaderboard, create_db_connection, db_get_question, post_score

from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)
logger = logging.getLogger(__name__)

config = configparser.ConfigParser()
config.read('config.ini')
database = config['bot']['db_file']
conn = create_db_connection(database)

global question_no
question_no = dict()


def start(bot, update):
    """
    Send a message when the command /start is issued.

    :return: None
    """
    nickname = str(update.message.from_user.first_name)
    update.message.reply_text('Hi,' + nickname)
    chat_id = str(update.message.chat_id)
    question_no[chat_id] = dict()
Пример #8
0
Файл: app.py Проект: theorm/apfa
from flask import Flask, render_template
from werkzeug.exceptions import NotFound
from context import Context
import db as database
import settings
from flaskext.markdown import Markdown

# from admin import admin, generate_admin_photo_set_url

app = Flask(__name__)
# app.register_blueprint(admin)
Markdown(app)

db = database.create_db_connection(settings)
ctx = Context(settings)


def generate_photo_set_url(photoset):
    return "/photo/%s" % (photoset["slug"],)


def generate_video_url(video):
    return "/video/%s" % (video["slug"],)


def shorten_blog_content(text):
    return text[0:200] + "..."


app.jinja_env.filters["photo_set_url"] = generate_photo_set_url
app.jinja_env.filters["video_url"] = generate_video_url
Пример #9
0
def fun():
    print("Main Function")

    try:
        #print("RFID Module Read TAG ID Function")
        #tag_id = rfid.RFIDUHFQueryTag()

        #if tag_id1 != None:
        #tag_id = tag_id1
        #else:
        #print("RFID Module Read TAG ID Function")
        #tag_id = rfid.RFIDUHFQueryTag()

        if (tag_id != None):
            print("Create a database connection to the DB file .db")
            if (database != None):
                dbConn = db.create_db_connection(database)

                if (dbConn != None):
                    #vehID, vehName, BUID, RFUID = db_DeviceDetails_by_rfiduid(dbConn, tag_id)
                    vehDetails = db_DeviceDetails_by_rfiduid(dbConn, tag_id)
                    #print("Create a database connection to the DB file--- ", vehDetails)

                    if (vehDetails != None):
                        print(
                            "Query the Database to read Tyre Details, Sensor ID, Position by vehID"
                        )

                        vehID = vehDetails[0]
                        vehName = vehDetails[1]
                        BUID = vehDetails[2]
                        RFUID = vehDetails[3]

                        #Query DB DeviceDetail in VehDetails Table to read vehID, vehName, BUID, RFUID
                        if (vehID != None):
                            print dbConn
                            DBSensorVariable = db_DeviceDetails_by_vehID(
                                dbConn, vehID)

                            #print DBSensorVariable
                            #dbConn.close()
                        else:
                            my_logger.warning(
                                "Vehicle ID not Available or None Function :%s ",
                                vehID)
                    else:
                        my_logger.warning(
                            "RFID Tag ID is not available in DB :%s ", tag_id)
                else:
                    my_logger.warning("No DB Connection ")
            else:
                my_logger.warning("Database path Not Available ")
        #else:
        #my_logger.warning ("RFID Tag ID is not available in DB %s: ", tag_id)

        #Query DB Device Detail to read vehID, vehName, BUID, RFUID
            if (BUID != None):
                print("Connect socket RFCOMM to Bluetooth Controller by BUID")
                print("Create a Bluetooth connection")
                bleConn = blecontroller.connect_ble(BUID)

                if (bleConn != None):

                    if ((DBSensorVariable != None)):
                        print(
                            "Configure BT SensorUID, tirePosition based on DB "
                        )

                        RetValCompare = configure_BTController(
                            bleConn, DBSensorVariable)

                    else:
                        my_logger.warning(
                            "DBSensorVariable  not Available or None Function : %s",
                            DBSensorVariable)

                    mylist = Connect_Socket_Bluetooth_by_BUID(bleConn)

                    #Current date and time
                    #t = datetime.utcnow()
                    #date_time = time.strftime('%H:%M:%S %d/%m/%Y')
                    date_time = int(
                        datetime.datetime.now().strftime("%s")) * 1000
                    print date_time

                    if mylist != None:

                        print("displayLEDBoard ")
                        #Display this data in LED Display with Commands
                        dispVar = display.displayLEDBoardParameters(mylist)
                        print dispVar

                        #display.displayLEDBoard(vehName, dispCommand, date_time, dispVar)
                        display.displayLEDBoard(vehName, dispCommand,
                                                date_time, dispVar)

                        #dbConn = db.create_db_connection(database)
                        with dbConn:

                            db.update_Latest_data_by_VehId(
                                dbConn, int(vehID), date_time, mylist)

                        dbConn.close()

    except:
        e = sys.exc_info()[0]
        my_logger.error("Failed - Main Function Crashed:%s ", e)
        print("Failed - Main Function Crashed: ", e)

        return ("Failed - Main Function Crashed:%s ", e)
        '''               
Пример #10
0
#Shutdown bp
async def shutdown():
	await Emitter.emit('Bot shutdown phase', 'Bot is now turning off')
	await Emitter.shutdown()

	

def main(loop):
	#Shared lock for keeping database information safe
	lock = asyncio.Lock()

	phi = PhiBot(lock)

	#Manage the asyncio event loop
	try:
		loop.run_until_complete(phi.start(config.DISCORD_TOKEN))
	except KeyboardInterrupt:
		phi.set_running(False)
		loop.run_until_complete(phi.logout())
		loop.run_until_complete(shutdown())
	finally:
		loop.close()


if __name__ == '__main__':
	#Create database connection and then start all asynchronous actions
	db.create_db_connection()
	event_loop = asyncio.get_event_loop()
	main(event_loop)
Пример #11
0
def db_DeviceDetails_by_vehID(vehID1):

    print("Create a database connection to the DB file .db")
    conn = db.create_db_connection(database)

    #print vehID
    print("Query the database to read Tyre Details by vehID")
    #vehDetail = db.select_DeviceDetails_by_rfiduid(conn, vehID)

    with conn:
        TyreDetail = db.select_TyreDetails_by_VehId(conn, vehID1)
        #print TyreDetail
    if (TyreDetail != None):

        if (TyreDetail[0] != None):
            Tyre_row1 = TyreDetail[0]

            SID1 = Tyre_row1[0]

            if Tyre_row1[1] == "FL":
                L1 = "01"
            elif Tyre_row1[1] == "FR":
                L1 = "02"
            elif Tyre_row1[1] == "RLO":
                L1 = "03"
            elif Tyre_row1[1] == "RLI":
                L1 = "04"
            elif Tyre_row1[1] == "RRO":
                L1 = "05"
            elif Tyre_row1[1] == "RRI":
                L1 = "06"

            #print SID1, L1

        if (TyreDetail[1] != None):
            Tyre_row2 = TyreDetail[1]

            SID2 = Tyre_row2[0]

            if Tyre_row2[1] == "FL":
                L2 = "01"
            elif Tyre_row2[1] == "FR":
                L2 = "02"
            elif Tyre_row2[1] == "RLO":
                L2 = "03"
            elif Tyre_row2[1] == "RLI":
                L2 = "04"
            elif Tyre_row2[1] == "RRO":
                L2 = "05"
            elif Tyre_row2[1] == "RRI":
                L2 = "06"

            #print SID2, L2

        if (TyreDetail[2] != None):
            Tyre_row3 = TyreDetail[2]

            SID3 = Tyre_row3[0]

            if Tyre_row3[1] == "FL":
                L3 = "01"
            elif Tyre_row3[1] == "FR":
                L3 = "02"
            elif Tyre_row3[1] == "RLO":
                L3 = "03"
            elif Tyre_row3[1] == "RLI":
                L3 = "04"
            elif Tyre_row3[1] == "RRO":
                L3 = "05"
            elif Tyre_row3[1] == "RRI":
                L3 = "06"

            #print SID3, L3

        if (TyreDetail[3] != None):
            Tyre_row4 = TyreDetail[3]

            SID4 = Tyre_row4[0]

            if Tyre_row4[1] == "FL":
                L4 = "01"
            elif Tyre_row4[1] == "FR":
                L4 = "02"
            elif Tyre_row4[1] == "RLO":
                L4 = "03"
            elif Tyre_row4[1] == "RLI":
                L4 = "04"
            elif Tyre_row4[1] == "RRO":
                L4 = "05"
            elif Tyre_row4[1] == "RRI":
                L4 = "06"

            #print SID4, L4

        if (TyreDetail[4] != None):
            Tyre_row5 = TyreDetail[4]

            SID5 = Tyre_row5[0]

            if Tyre_row5[1] == "FL":
                L5 = "01"
            elif Tyre_row5[1] == "FR":
                L5 = "02"
            elif Tyre_row5[1] == "RLO":
                L5 = "03"
            elif Tyre_row5[1] == "RLI":
                L5 = "04"
            elif Tyre_row5[1] == "RRO":
                L5 = "05"
            elif Tyre_row5[1] == "RRI":
                L5 = "06"

            #print SID5, L5

        if (TyreDetail[5] != None):
            Tyre_row6 = TyreDetail[5]

            SID6 = Tyre_row6[0]

            if Tyre_row6[1] == "FL":
                L6 = "01"
            elif Tyre_row6[1] == "FR":
                L6 = "02"
            elif Tyre_row6[1] == "RLO":
                L6 = "03"
            elif Tyre_row6[1] == "RLI":
                L6 = "04"
            elif Tyre_row6[1] == "RRO":
                L6 = "05"
            elif Tyre_row6[1] == "RRI":
                L6 = "06"

            #print SID6, L6

    print("Close a database connection to the DB file .db")
    conn.close()
    return SID1, L1, SID2, L2, SID3, L3, SID4, L4, SID5, L5, SID6, L6
Пример #12
0
def before_request():
    """Connect to database before each request.
    """
    g.db = db.create_db_connection()
Пример #13
0
def init_database():
    """Create database if it doesn't exist.
    """
    db.create_db_connection(migrate=True)
Пример #14
0
def before_request():
    """Connect to database before each request.
    """
    g.db = db.create_db_connection()
Пример #15
0
def init_database():
    """Create database if it doesn't exist.
    """
    db.create_db_connection(migrate=True)