def main(): # Get the list of files files = getGzList('data/') for day in files: day = getDay(day) # Make a db connection and the tables conn = db.makeConnection() cursor = db.makeCursor(conn) db.makeTables(cursor) # Get the tweets tweets = processDay(day) # Find new hashtags. Handle first run where db is empty try: currenthashtags = [item[1] for item in db.getHashtags(cursor)] except IndexError: currenthashtags = [] newhashtags = findNewHashtags(tweets, currenthashtags) # Find new users. Handle first run where db is empty try: currentusers = [item for item in db.getUsers(cursor)] except IndexError: currentusers = [] newusers = findNewUsers(tweets, currentusers) print(newusers) # Write new tags to the db for tag in newhashtags: cursor.execute('insert into hashtags (text) values (%s)', (tag,)) conn.commit() # Write new users to the db for user in newusers: cursor.execute('insert into users (idUser) values (%s)', (user,)) conn.commit() users = [item for item in db.getUsers(cursor)] print(users) hashtags = db.getHashtags(cursor) for tweet in tweets: cursor.execute('insert into tweets (idUser, tweetText, tweetDate, retweetCount, idTweet, cand_retweet, source_tweet_id) values (%s, %s, %s, %s, %s, %s, %s)', tweet.buildDbRow()) if len(tweet.hashtags) != 0: tweet_hashtags = [(hashtag[0],tweet.tweet_id) for tag in tweet.hashtags for hashtag in hashtags if tag == hashtag[1]] for item in tweet_hashtags: cursor.execute('insert into tweet_hashtags (hashtag_id,tweet_id) values (%s,%s)', item) for user in tweet.user_mentions: cursor.execute('insert into user_mentions (mentioner, mentionee, tweet_id) values (%s,%s,%s)', (tweet.user_id, user, tweet.tweet_id)) conn.commit() conn.close()
def test_getUsers(self): db.wipeDatabase() db.addUser("test1", "password", "*****@*****.**") db.addUser("test2", "password", "*****@*****.**") db.addUser("test3", "password", "*****@*****.**") numUsers = db.getUsers() self.assertEqual(len(numUsers), 3)
def submit_data(self): cl = self.cl.get() pl = self.pl.get() sql = "SELECT * FROM users where email='" + cl + "' and password='******'" flag = read_data(sql) if (flag == 1): global current_user print("login successful ") active_user = getUsers(sql) print("current user id is ") print(active_user) current_user = active_user today = datetime.date.today() end_date = today + datetime.timedelta(days=7) #sql1 = "SELECT * FROM p_cal WHERE user_id="+"'"+current_user+"'" #flag2 = read_data(sql) db.setId(current_user) messagebox.showinfo("Login Message", "Successfully Logged In ") d = data("current_user") d.setName("current_user") self.master.destroy() #os.system('python3 pcal.py') else: print("login failed") messagebox.showerror("Login Message", "Please Try Again")
def CheckUsers(): if request.method == 'GET': return getUsers(request) elif request.method == 'POST': return createUsers(request) else: return 'ELSE'
def onEditUser(): if request.method == 'POST': editUser(request.form['username'].rstrip(), request.form['password'].rstrip(), request.form['fullName'].rstrip()) users = getUsers() return render_template('admin.html', users=users)
def getUser(userId): sleep(app.config['DELAY']) try: return jsonify(db.getUsers(userId=userId)) except KeyError: return (jsonify({ "type": "ResourceNotFound", "message": "User ID {} not found".format(userId) }), 404, { "Content-Type": "application/json" })
def queue(): if 'username' in session: users = db.getUsers(g.db) if request.method <> 'POST': debug('Getting bugList for user : '******'username']) bugList = db.getBugList(g.db, session['username']) return render_template('queue.html', bugs = bugList, other_username = session['username'], users= users, queue_user = session['username']) else: if request.form['other_username'] <> 'all': debug('Getting bugList for user : '******'other_username']) bugList = db.getBugList(g.db, request.form['other_username']) return render_template('queue.html', bugs = bugList, other_username = request.form['other_username'], users = users, queue_user = request.form['other_username']) else: debug('Getting all queues') #get a visible drop down of all users. #avallark working from here... #create an list of list of users all_queues = db.getAllQueues(g.db) return render_template('all_queues.html', all_queues = all_queues, users=users, other_username = "******") else: return render_template('login.html', error = 'Login first')
def POST(self): rel1 = False rel3 = False web.header('Content-Type','application/json') dat = web.data() input = json.loads(dat) act = input['action'] print "data: "+act if act == 'Relay 1 on' : ser.write('1') rel1 = True rv = {'status' : 'True', 'message' : 'Relay 1 is ON!'} return json.dumps(rv) elif act == 'Relay 1 off' : ser.write('!') rel1 = False rv = {'status':'True', 'message': 'Relay 1 is OFF!'} return json.dumps(rv) elif act == 'Relay 2 on' : ser.write('2') #rel2 = True rv = {'status':'True', 'message':'Relay 2 is ON!'} return json.dumps(rv) elif act == 'Relay 3 on' : ser.write('3') rel3 = True rv = {'status': 'True', 'message' : 'Relay 3 is ON!' } return json.dumps(rv) elif act == 'Relay 3 off' : ser.write('#') rel3 = False rv = {'status' : 'True', 'message' : 'Relay 3 is OFF!'} return json.dumps(rv) elif act == 'CHECK' : ser.write('5') sta = ser.readline() stat = int(sta,2) if stat == 0 : rel1=False; #rel2=False; rel3=False; elif stat == 1 : rel1=False; #rel2=False; rel3=True; elif stat == 2 : rel1=True; #rel2=True; rel3=False; elif stat == 3 : rel1=True; #rel2=True; rel3=True; '''elif stat == 4 : rel1=True; rel2=False; rel3=False; elif stat == 5 : rel1=True; rel2=False; rel3=True; elif stat == 6 : rel1=True; rel2=True; rel3=False; elif stat == 7 : rel1=True; rel2=True; rel3=True;''' rv = {'status':'True', 'message' : stat} return json.dumps(rv) elif act == 'loginF': idata = input['data'] image = open('imageFromPhone.jpg','wb') image.write(idata.decode('base64')) image.close() image = cv2.imread('imageFromPhone.jpg') recog = fileH.trainRecog() [label , dist] = fileH.recognize(image,recog) rv = {} if label == -1: rv = {'status': 'False'} else: conn = db.Connect() [status,uname,pswd] = db.checkFace(conn,label) conn.close() rv = {'status':str(status),'uname':uname,'pswd':pswd} #rv = {'status':'True', 'message' : 'label : '+str(label)+'\ndist : '+str(dist)} return json.dumps(rv) elif act == 'login': uname = input['username'] pswd = input['password'] conn = db.Connect() if db.checkUser(conn,uname,pswd): print "User Exists!" flag = True for names in self.users: if names == uname : flag = False break else: flag = True if flag : self.users.append(uname) rv={'stat':'True'} conn.close() return json.dumps(rv) else: rv={'stat':'False'} conn.close() return json.dumps(rv) elif act == 'logout': uname = input['username'] flag = False for name in self.users: if name == uname: self.users.remove(name) flag = True break else: flag = False rv={'stat':'abc'} ser.write('4') if flag: rv={'stat':'True'} else: rv={'stat':'False'} return json.dumps(rv) elif act == 'getUsers': conn = db.Connect() usernames = db.getUsers(conn) conn.close() rv={'users':usernames} return json.dumps(rv) elif act == 'register': flag = input['pic'] uname = input['uname'] pswd = input['pswd'] name = input['name'] #logging.warning(str(flag)+' '+uname+' '+pswd+' '+name) if flag == 'False': #logging.warning('Entered False') try: #logging.warning('Entered Try') conn = db.Connect() db.insertUser(conn,uname,pswd,name,'') conn.commit() conn.close() rv={'stat':'True'} return json.dumps(rv) except: #logging.warning('Entered Except') rv={'stat':'False'} return json.dumps(rv) elif flag == 'True': im1 = input['img1'] im2 = input['img2'] im3 = input['img3'] im4 = input['img4'] path = fileH.getPath() im = open('image.jpg','wb') im.write(im1.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) im = open('image.jpg','wb') im.write(im2.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) im = open('image.jpg','wb') im.write(im3.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) im = open('image.jpg','wb') im.write(im4.decode('base64')) im.close() img = cv2.imread('image.jpg') fileH.saveFace(img,path) fileH.createCSV() face = fileH.getLabel() logging.warning('label '+str(face)) con = db.Connect() db.insertUser(con,uname,pswd,name,face) con.commit() con.close() #fileH.trainRecog() rv={'stat':'True'} return json.dumps(rv) else : rv={'message':'Invalid Request'} return json.dumps(rv)
def onDeleteUser(username): deleteUser(username.rstrip()) users = getUsers() return render_template('admin.html', users=users)
def admin(): users = getUsers() return render_template('admin.html', users=users)
def review(oid=1): if request.method=='GET': places = db.getPlaces() oid = int(oid) return render_template('reviews.html', oid=oid, place=db.getPlaces()[oid], name=db.getUser(session['user']), reviews=db.getReviews(oid), users=db.getUsers(), plat = float(places[oid]['lat']), plng = float(places[oid]['lng'])) else: ## get the review from the HTML form rating = request.form['stars'] content = request.form['myTextBox'] authorID = db.getUser(session['user'])['oid'] title = "no title" ## no comment title in HTML form placeID = oid ## add comment to database db.addReview(title,content,int(rating),authorID,placeID) ## flash success flash('Thank you for your review!') ## return template places = db.getPlaces() oid = int(oid) return render_template('reviews.html', oid=oid, place=places[oid], name=db.getUser(session['user']), reviews=db.getReviews(oid), users=db.getUsers(), plat = float(places[oid]['lat']), plng = float(places[oid]['lng']))
def bug(): bug_id = request.args.get('bug_id', '') if request.method <> 'POST': debug('Calling getBugHeader') bugh = db.getBugHeader(g.db, bug_id) debug('Calling getBugBody') bugb = db.getBugBody(g.db, bug_id) all_status = db.getStatuses(g.db) all_users = db.getUsers(g.db) return render_template('bug.html', bugh = bugh, bugb = bugb, all_status = all_status, all_users = all_users) else: debug('Creating dictionary of bug to update the header for '+str(bug_id)) assigned_to_user_id = db.getUser(g.db, request.form['assigned_to_username'])['user_id'] updating_user_id = db.getUser(g.db, session['username'])['user_id'] bug = dict(title = request.form['title'], customer=request.form['customer'], updated_by_username = session['username'], assigned_to_user_id = assigned_to_user_id ,assigned_to_username = request.form['assigned_to_username'], description = request.form['description'], priority = request.form['priority'], status = request.form['status'], updating_user_id = updating_user_id, bug_id = bug_id) # creating list of header updates onto the body debug(str(bug_id)) bugh = db.getBugHeader(g.db, bug_id) changedString = "" if bugh['title'] <> bug['title']: changedString += "** Changed Title from "+bugh['title']+" to "+ bug['title'] + "\n" #if bugh['description'] <> bug['description']: # changedString += "** Changed Description from "+bugh['description']+" to "+ bug['description'] + "\n" if bugh['assigned_to_user_id'] <> bug['assigned_to_user_id']: to = db.getUserEmail(g.db,bug['assigned_to_user_id']) debug('Sending email to notify assignation to : '+to) changedString += "** Changed Assigned from "+ bugh['assigned_to_username'] + " to "+ request.form['assigned_to_username'] + "\n" debug (changedString) emails.bugAssignNotify(bug, to) if bugh['description'] <> bug['description']: changedString += "** Changed Bug Description from " + "\n" + bugh['description'] if bugh['customer'] <> bug['customer']: changedString += "** Changed Customer from "+bugh['customer']+" to "+ bug['customer'] + "\n" if bugh['status'] <> bug['status']: changedString += "** Changed Status from "+bugh['status']+" to "+ bug['status'] + "\n" if str(bugh['priority']) <> str(bug['priority']): changedString += "** Changed Priority from "+str(bugh['priority'])+" to "+ str(bug['priority']) + "\n" debug(changedString) # Now updating the header with changes db.updateBugHeader(g.db, bug) newUpdate = changedString + "\n" + request.form['newupdate'] bugUpdate = dict(update = newUpdate, updated_by_user_id = updating_user_id, bug_id = bug_id) db.insertBugUpdate(g.db, bugUpdate) return redirect(url_for('queue'))
def getUsersCollection(): sleep(app.config['DELAY']) users = db.getUsers(searchName=request.args.get('name'), searchRole=request.args.get('role')) return jsonify(users)
def submit_data(self): global reg_user name = self.name.get() email = self.email.get() contact = self.contact.get() dob_year = self.dob_year.get() dob_month = self.dob_month.get() dob_day = self.dob_day.get() print(dob_month) mth = '' if (dob_month == 'jan'): mth = '1' elif (dob_month == 'feb'): mth = '2' elif (dob_month == 'mar'): mth = '3' elif (dob_month == 'apr'): mth = '4' elif (dob_month == 'may'): mth = '5' elif (dob_month == 'jun'): mth = '6' elif (dob_month == 'jul'): mth = '7' elif (dob_month == 'aug'): mth = '8' elif (dob_month == 'sept'): mth = '9' elif (dob_month == 'oct'): mth = '10' elif (dob_month == 'nov'): mth = '11' elif (dob_month == 'dec'): mth = '12' date_str = mth + '-' + dob_day + '-' + dob_year print(date_str) date_object = datetime.strptime(date_str, '%m-%d-%Y').date() print(type(date_object)) print(date_object) password = self.password.get() if (name and email and contact and date_object and password): print("test") print(name) print(email) print(contact) print(date_object) print(password) sql = "INSERT INTO users(uname,email,dob,contact,password) VALUES (%s,%s,%s,%s,%s)" val = (name, email, date_object, contact, password) success = insert_data(sql, val) db.setEmail(email) if (success == 1): sql2 = "SELECT * FROM users where email='" + email + "' and password='******'" reg_user = getUsers(sql2) print("current registered id is ") print(reg_user) #os.system('python3 RegisterPeriod.py') messagebox.showinfo("Registration Message", "Successfully Registered ") self.master.destroy() else: print("Error Occured") messagebox.showerror("User Registration", "Some Error Occured Please Try Again")