Exemple #1
0
def check_for_hashtag(body,t,timestamp):
	body = body.split("#");
	body = body[1:]
	for text in body:
		text = text.split(" ")
		text = text[0]
		value = {timestamp:t}
		op.insert('HASH_TAGS', text , value)
Exemple #2
0
def check_for_reference(body,t,timestamp):
	body = body.split("@");
	body = body[1:]
	for text in body:
		text = text.split(" ")
		text = text[0]
		value = op.get('USERNAME',text)
		op.insert('TIMELINE',value['uid'],{timestamp:t})
Exemple #3
0
def mark_as_favorite(uid,tid):
	val = is_favourite(uid,tid)
	if val:
		d = op.get('FAVORITE_IS', tid)
		t = d[uid]
		op.remove_column('FAVORITE_OF', uid,[t])
		op.remove_column('FAVORITE_IS', tid,[uid])		
	else:
		val = op.get('TWEETS',tid)
		timestamp = long(time.time() * 1e6)
		timestamp = str(timestamp)
		op.insert('FAVORITE_OF', uid, {timestamp:tid})
		op.insert('FAVORITE_IS', tid, {uid:timestamp})
Exemple #4
0
def addUser(emailid, username, pwd) :
        "add a user to the network"
	print "add user function"
        value = {'uid':emailid, 'username':username, 'password':pwd}        
	try:
		print emailid, value, username
		op.insert('USERS', emailid, value)
		val={'uid':emailid}
		op.insert('USERNAME', username, val)
	except:
		print "inside execp"
		return 0
	return 1
def insert(sheet):
    if request.method == "POST":
        data = request.get_data().decode('utf-8')
        data = urllib.parse.unquote(data)
        data = data.replace('&', ' ')
        print(data)
        print(sheet)
        insertvalue = {}
        for i in data.split():
            insertvalue[i.split('=')[0]] = i.split('=')[1]
        print(insertvalue)
        operations.insert(sheet, **insertvalue)
        return jsonify(insertvalue)

    else:
        pass
Exemple #6
0
 def mutate(self, s):
     op = random.randint(0, 5)
     if op == 0:
         return operations.insert(s)
     elif op == 1:
         return operations.delete(s)
     else:
         return operations.bit_flip(s)
Exemple #7
0
def post_reply(tid, uid, msg) :
        "reply to a tweet"
        t = str(uuid.uuid4())
        timestamp = long(time.time() * 1e6)
        timestamp = str(timestamp)	
        value = {'body':msg, 'user':uid, 'timestamp':timestamp}
        op.insert('TWEETS', t, value)
	timestamp = timestamp + ":" + uid
        op.insert('REPLY_TO_TWEET', tid, {timestamp:t})
	op.insert('USERLINE',uid, {timestamp:t})
	for followerID in op.get('FOLLOWER', uid):
		if 'status' != followerID:
               	   op.insert('TIMELINE', followerID, {timestamp:t})		#DO
Exemple #8
0
def retweet(tid, uid):
	"retweet an existing tweet"
        timestamp = long(time.time() * 1e6)
	timestamp = str(timestamp) + ":" + str(uid)	
	t = str(uuid.uuid4())

	d = op.get('TWEETS',tid)
        value = {'body':d['body'], 'user':d['user'], 'timestamp':str(timestamp)}
        op.insert('TWEETS', t, value)

	op.insert('USERLINE', uid, {timestamp:t})
	op.insert('RETWEET', uid, {tid:t})
	print "retweeting"
	for followerID in op.get('FOLLOWER', uid):
		print followerID
		if 'status' != followerID:
			tweet=str(t)+"!"+str(uid)
			op.insert('TIMELINE', followerID, {timestamp:tweet})		#DO
Exemple #9
0
def addFollowers(followerID, followingID) :
        "follower and following a user"
        t = str(long(time.time() * 1e6))
        value = {followingID: t}        
	try:
		op.insert('FOLLOWER', followerID, value)
        	value = {followerID: t}        
        	op.insert('FOLLOWING', followingID, value)
		val = op.get('USERLINE',followerID)
                op.insert('TIMELINE',followingID,val)
	except:
		return 0
	return 1
Exemple #10
0
def post_tweet(msg,uid):
        "post a tweet"
        t = str(uuid.uuid4())
        timestamp = long(time.time() * 1e6)
        value = {'body':msg, 'user':uid, 'timestamp':str(timestamp)}
        op.insert('TWEETS', t, value)
	timestamp = str(timestamp) + ":" + str(uid)
        op.insert('USERLINE', uid, {timestamp:t})
#       op.insert('TIMELINE', uid, {timestamp:t})
	parse(t,uid)
	for followerID in op.get('FOLLOWER', uid):
		if 'status' != followerID:
               	   op.insert('TIMELINE', followerID, {timestamp:t})		#DO
	
	return jsonify({'tid':t,'body':msg,'user':uid})
Exemple #11
0
  def candidate_set(self):
    """
    Genrate a list of candidate set using the noisy
    channel step 1 fact that each spelling mistake can
    be corrected by making just one insertion, deletion,
    substitution or transposition.

    ALGORITHM
    =========
    Given an observation, say 'abck', an Insertion can be
    made at n+1 positions. [a-z]abck, a[a-z]bck, ..., abck[a-z]
    Substituition can be made in n ways. [a-zbck], ...
    Deletion in n ways
    Transposition in n ways
    Use regex to match everything

    @param None
    @return dict with each key mapping to 0
    """
    obs = self.obs
    size = self.size
    regexes = []

    #iterate over list and generate regexes
    for i in range(0, size+1):
      regexes.append(operations.insert(obs, i, self.alphabets)) #insertion candidates
      if(i<size):
        regexes.append(operations.sub(obs, i, self.alphabets)) #substituition candidates
        d = operations.delete(obs, i)
        regexes.append(d)#deletion candidates
        #send deletion to fallbacks as well
        self.fallback.append(d)
    regexes += operations.all_trans(obs) #transposition candidates
    pattern = "|".join(regexes)
    candidates = list( set( re.findall(pattern, self.words) ) ) #set removes duplicates
    c_set = {}
    [c_set.update({w:0}) for w in candidates]
    return c_set
Exemple #12
0
def title():
    result =''
    if request.method == 'POST':
        post_id = operations.insert(request.form) 
        print 'Successfully inserted ' + str (post_id)
    return render_template('titles.html',data = operations.get_titles()) 
Exemple #13
0
def ImplementOperations(parameters):

    if (parameters["operation"] == "create"):
        field_names, data_types = GetFieldNamesAndDatatypes(
            parameters["parameter2"])
        operations.CreateTable(parameters["parameter1"], field_names,
                               data_types)
        return True

    elif (parameters["operation"] == "insert"):
        try:
            operations.insert(parameters["parameter1"])
        except FileNotFoundError:
            print("No such table found")
        except PermissionError:
            print("Please close the file", parameters["parameter1"])
        return True

    elif (parameters["operation"] == "select"):
        try:
            operations.Select(parameters)
        except KeyError:
            print("No such column found")
        except FileNotFoundError:
            print("No such table found")
        return True

    elif (parameters["operation"] == "exit"):
        return False

    elif (parameters["operation"] == "help"):
        operations.PrintSyntaxes()
        return True

    elif (parameters["operation"] == "join"):
        try:
            operations.join(parameters)
        except FileNotFoundError:
            print("No such table found")
        except IndexError:
            print("No common fields")
        return True

    elif (parameters["operation"] == "sort"):
        try:
            operations.sortby(parameters)
        except PermissionError:
            print("Please close the file", parameters["parameter1"])
        return True

    elif (parameters["operation"] == "find"):
        try:
            operations.find(parameters)
        except PermissionError:
            print("Please close the file", parameters["parameter3"])
        return True

    elif (parameters["operation"] == "cls"):
        os.system("cls")
        return True

    elif (parameters["operation"] == "drop"):
        operations.drop(parameters)
        return True
Exemple #14
0
def insertS(name, rollNo):
    new_image = face_recognition.load_image_file("saved_img.jpg")
    new_face_encoding = face_recognition.face_encodings(new_image)[0]
    message = op.insert(new_face_encoding, name, rollNo)
    return message