def profile(self, user): #profile page functions.checkLogged() #Open and read html file Page = functions.readHtml("profile") #Get online user list Page = functions.getUsers(cherrypy.session['username'], Page) data = functions.readUserData(user) #Displays user info Page += '<img src={} width="400" height="400"><br/>'.format(data[5]) Page += u"<b>Name: {}</b><br/>".format(data[1]) Page += u"<b>Position: {}</b><br/>".format(data[2]) Page += u"<b>Description: {}</b><br/>".format(data[3]) Page += u"<b>Location: {}</b><br/>".format(data[4]) if (cherrypy.session['username'] == user): #Button for profile editing Page += '<form action="/editProfile" method="post" enctype="multipart/form-data">' Page += '<input class= "button" type="submit" value="Edit Profile"/></form>' #Button to signout Page += '<form action="/logoff?username={0}&password={1}" method="post" enctype="multipart/form-data">'.format( cherrypy.session['username'], cherrypy.session['password']) Page += '<input class= "button" type="submit" value="Signout"/></form>' else: Page += '<form action="/profile" method="post" enctype="multipart/form-data">' Page += '<button name="user" value="{}" class="button"/>Return to Profile</button></form>'.format( cherrypy.session['username']) return Page
def run(self): wait_time = 1 userlist = list() userlist.extend(functions.getUsers(functions.getHtml())) print ('Daemon started.\n') functions.notification(summary, 'The daemon has started. Now watching for new users in the wlan...') print('The users in the WLAN right now are:') for u in userlist: print (str(u[0]) + ' ' + str(u[1])) print ('\n') while(True): users = functions.getUsers(functions.getHtml()) for u in users: if u not in userlist: note = functions.print_user(u) + ' has connected to the wlan' print (note) functions.notification(summary, note) userlist.append(u) if len(users) < len(userlist): for u in userlist: if u not in users: note = functions.print_user(u) + ' has disconnected from the wlan' print (note) functions.notification(summary, note) userlist.remove(u) sleep(wait_time)
def messaging(self, destination): functions.checkLogged() #Read the message html Page = functions.readHtml("messaginghead").format( cherrypy.session['username']) #Get online user list Page = functions.getUsers(cherrypy.session['username'], Page) db = sqlite3.connect("db/Conversation.db") cursor = db.cursor() #If it is the first time the user uses messaging, create a new table for that user cursor.execute( 'CREATE TABLE IF NOT EXISTS {}(UPI TEXT NOT NULL, Sender TEXT NOT NULL, Message TEXT NOT NULL, Stamp TEXT NOT NULL, Type TEXT NOT NULL)' .format(cherrypy.session['username'])) cursor.execute( 'SELECT * FROM {} WHERE UPI = ?'.format( cherrypy.session['username']), (destination, )) all_rows = cursor.fetchall() Page += '<div id="message-box" class="message-box">' for row in all_rows: #Display your messages in blue if (row[1] == cherrypy.session['username']): Page += '<span class="font-color1">' Page = functions.formatMessage(row[1], row[2], row[3], row[4], Page) Page += '</span>' #Display other person's message in red else: Page = functions.formatMessage(row[1], row[2], row[3], row[4], Page) db.close() Page += "</div>" #User input for message, and the send button Page += '<form action="/sendMessage"method="post" enctype="multipart/form-data">' Page += 'Message: <input type="text" id="input-box" name="message" required class="message-input"/><button name="destination" value="{0}" class="message-button"/>Send</button></form>'.format( destination) Page += '<form action="/sendFile"method="post" enctype="multipart/form-data">' Page += '<input type="file" name="fData" id="upload" required><button name="destination" value="{0}" class="message-button"/>Send File</button></form>'.format( destination) return Page
import matplotlib.pyplot as plt import pandas as pd import sys import os from functions import importMappedData, trackMeta, mbzMeta, getUsers from collections import OrderedDict, Counter from operator import itemgetter user = sys.argv[1] data = importMappedData() userData = getUsers() userInfo = userData[userData["user_id"] == user] gender = "" age = 0 country = "" try: gender = userInfo['gender'].values[0] age = userInfo['age'].values[0] country = userInfo['country'].values[0] except IndexError as err: pass print(user) print("gender: " + gender) print("age: " + str(age)) print("country: " + country) # Create a DF with data relevant to the specified user userPlays = pd.DataFrame(data[data["user_id"] == user],
async def on_message(message): # prevent bot from talking to itself if message.author == client.user: return # commands # TODO: make commands based on DB # skips comparisons if message is not command if message.content.lower().startswith('!noticebot'.lower()): # output commands list if message.content.lower() == '!noticebot'.lower(): msg = 'these are my commands: !noticeBot, !noticeBot sub, !noticeBot unsub, !noticeBot clearDB, !noticeBot announce'.format(message) await client.send_message(message.channel, msg) # clears database elif message.content.lower() == '!noticeBot clearDB'.lower(): # TODO: make user id compare to list of authorized user ids if message.author.id == '174602020672503808': functions.clearStorage() msg = 'authorized user {0.author.mention}, clearing database'.format(message) else: msg = 'unauthorized user {0.author.mention}'.format(message) await client.send_message(message.channel, msg) # subscribes user to follow channel which message was sent in elif message.content.lower() == '!noticeBot sub'.lower(): user1 = classes.User(message.author.name, message.author.id, [message.channel.id], message.author) if functions.userInList(user1, message.channel.id): msg = ('user {0.author.mention} already subbed to channel "' + message.channel.name + '"').format(message) else: msg = ('adding user {0.author.mention} to sublist for channel "' + message.channel.name +'"').format(message) functions.addUser(user1, message.channel.id) await client.send_message(message.channel, msg) elif message.content.lower() == '!noticeBot unsub'.lower(): user1 = classes.User(message.author.name, message.author.id, [message.channel.id], message.author) if functions.userInList(user1, message.channel.id): msg = ('unsubbing user {0.author.mention} from sublist for channel "' + message.channel.name +'"').format(message) functions.removeUser(user1, message.channel.id) else: msg = ('User {0.author.mention} not in sublist for channel "' + message.channel.name +'"').format(message) await client.send_message(message.channel, msg) elif message.content.lower() == '!noticeBot announce'.lower(): if message.author.id == '174602020672503808': msg = 'authorized user {0.author.mention}, announcing message'.format(message) await client.send_message(message.channel, msg) msg = 'enter channel ID'.format(message) await client.send_message(message.channel, msg) msg = await client.wait_for_message(author=message.author, channel=message.channel) channelID = msg.content msg = 'enter message'.format(message) await client.send_message(message.channel, msg) msg = await client.wait_for_message(author=message.author, channel=message.channel) announceMSG = msg.content msg = ('Sending message to channel with ID ' + channelID).format(message) await client.send_message(message.channel, msg) await client.send_message(client.get_channel(channelID), announceMSG) else: msg = 'unauthorized user {0.author.mention}'.format(message) await client.send_message(message.channel, msg) # sends messages to subscribed users for someUser in functions.getUsers(): if (message.channel.id in someUser.subbedChannels and message.author.name != someUser.name): msg = message.author.name + " har skickat ett meddelande i servern " + message.server.name + " i kanalen " + message.channel.name.format(message) await client.send_message(someUser.userClassObject, msg)
# sends messages to subscribed users for someUser in functions.getUsers(): if (message.channel.id in someUser.subbedChannels and message.author.name != someUser.name): msg = message.author.name + " har skickat ett meddelande i servern " + message.server.name + " i kanalen " + message.channel.name.format(message) await client.send_message(someUser.userClassObject, msg) @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') client.run(TOKEN) # functions.addUser(user1) list = functions.getUsers() if (list != []): print("dessa är användarna") for user in list: print(user.name) else: print("no users after")