def get_info_user(uid): """Returns an array with user information""" db = connection_database() collection = db['users_test'] cursor = collection.find({'email': uid}) info_user = list(cursor)[0] return info_user
def get_user_history(user_id): """Gets all the playback of an specific user""" db = connection_database() collection = db['playback_history'] cursor = collection.find({'user_id': user_id}) df = pd.DataFrame(cursor) return df
def get_all_history(): """Gets all the playback history of the application""" db = connection_database() collection = db['playback_history'] cursor = collection.find({}) df = pd.DataFrame(cursor) return df
def get_history_from_db(): """Returns all the raw history of the application""" db = connection_database() history = db['playback_history'] cursor = history.find({}) df = pd.DataFrame(cursor) return df
def save_multiple_user_histories(uid_list, id_playlist): """Create demo play histories for a user list from a playlist""" base_playlist = get_playback(id_playlist) for uid in uid_list: history_user = get_playback_history(uid, base_playlist) # Connects and write into DataBase db = connection_database() collection = db['playback_history'] collection.insert_many(history_user) print("A Sample of Playback-History was added to DataBase")
def save_sample_playback_history(uid, id_playlist): """Save an example history based on a Playlist for a specific user""" # Create a user playback history base_playlist = get_playback(id_playlist) history_user = get_playback_history(uid, base_playlist) # Connects and write into DataBase db = connection_database() collection = db['playback_history'] collection.insert_many(history_user) print("A Sample of Playback-History was added to DataBase")
def save_new_playlist(uid=None): """Gets and saves a New Playlist to a specific user""" # Creates a new playlist if uid: playlist = create_playlist_user(uid) else: playlist = create_playlist_general() # Connects and write into DataBase db = connection_database() collection = db['spot_playlists'] collection.insert_one(playlist) print("A new Playlist was added to DataBase")
import serial import time import struct, sys from connection import connection_database conn, cur = connection_database() ser = serial.Serial('COM7', 57600) pack = [0xef01, 0xffffffff, 0x1] def printx(): for i in l: print(i) print('') def readPacket(): time.sleep(1) w = ser.inWaiting() ret = [] if w >= 9: s = ser.read(9) #partial read to get length ret.extend(struct.unpack('!HIBH', s)) ln = ret[-1] time.sleep(1) w = ser.inWaiting() if w >= ln: s = ser.read(ln) form = '!' + 'B' * (ln - 2) + 'H'