Example #1
0
def follow():
    follower = session["other_user"]
    following = session["username"]
    followerId = op.get("USERNAME", follower)
    followingId = op.get("USERNAME", following)
    val = users.addFollowers(followerId["uid"], followingId["uid"])
    return redirect(url_for("get_userline"))
Example #2
0
def user_exist(emailid,username):
	value1 = op.get('USERS',emailid)
	value2 = op.get('USERNAME',username)
	if 'status' in value1 or 'status' in value2:
		return str(1)
	else :
		return str(0)
Example #3
0
def check_follow(follower,following):
        followerId = op.get('USERNAME',follower)
        followingId = op.get('USERNAME',following)
        val = op.get('FOLLOWING',followingId['uid'])
        l=val.keys()
        if followerId['uid'] in l:
                return 1
        else:
                return 0
Example #4
0
def followers():
    other_uid = op.get("USERNAME", session["other_user"])
    d = op.get("FOLLOWER", other_uid["uid"])
    d1 = {}
    if not (d.has_key("status")):
        for uid in d.iterkeys():
            val = op.get("USERS", uid)
            d1[uid] = val["username"]
    return render_template("followers.html", d=d1, username=session["username"], other_user=session["other_user"])
Example #5
0
def check_follow():
    follower = session["other_user"]
    following = session["username"]
    followerId = op.get("USERNAME", follower)
    followingId = op.get("USERNAME", following)
    val = op.get("FOLLOWING", followingId)
    l = val.keys()
    if followerId in l:
        return redirect(url_for("get_userline", follow_flag=1))
    else:
        return redirect(url_for("get_userline", follow_flag=0))
Example #6
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})
Example #7
0
def get_userline():
    d = {}
    follow_flag = 0
    if "username" not in session or session["username"] is None:
        return render_template("login.html")
    if request.method == "GET":
        if session["username"] != session["other_user"]:
            follow_flag = users.check_follow(session["other_user"], session["username"])
            val = op.get("USERNAME", session["other_user"])
            uid = val["uid"]
        else:
            uid = session["emailid"]
        if uid is not None:
            d, l = get.get_userline(uid)
            d1, l1 = get.get_favourite(session["emailid"])
            d2 = get.get_retweets(session["emailid"])
            return render_template(
                "tweets.html",
                follow_flag=follow_flag,
                d=d,
                l=l,
                f=l1,
                username=session["username"],
                other_user=session["other_user"],
                retweet=d2,
            )
        else:
            return render_template("login.html")
Example #8
0
def myfavourites():
    user = session["other_user"]
    val = op.get("USERNAME", user)
    uid = val["uid"]
    d, l = get.get_favourite(uid)
    # 	session['other_user'] = session['username']
    return render_template("favourite.html", d=d, l=l, username=session["username"], other_user=session["other_user"])
Example #9
0
def checkUser(emailid,pwd):
	value = op.get('USERS',emailid)
	if 'status' in value:
		return str(0)
	if value['password']==pwd:
		return value['username']
	else:
		return str(0)
Example #10
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})
Example #11
0
def is_favourite(uid,tid):
	"check if tweet has already been marked as favourite"
	d = op.get('FAVORITE_OF', uid)
	values = d.values()
	if tid in values:
		return True
	else:
		return False
Example #12
0
def parseNode(arr, ctr): 
	label  = int(arr[_n_label_idx])
	opCode = int(arr[_n_code_idx])
	node   = None

	operation = operations.get(opCode)
	node = IGR.createOperationNode(environment.getSubGraph(), operation)

	environment.addNode(label, node)
Example #13
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
Example #14
0
class InfixCalculator(object):
    ops = operations.get()
    symbols_allowed = [op for op in ops.keys()] + ['(', ')']

    def help(self) -> str:
        return 'Please provide a valid statement with '\
                'operators i.e. {} and positive integers'.format(self.symbols_allowed)

    def calculate(self, args) -> int:
        """
        args support parentheses, operators {+, -, *, /} and integers
        """
        if not len(args):
            raise InvalidInputError(self.help())

        result = self.__transform(args)
        calc = PrefixCalculator.PrefixCalculator()
        return calc.calculate(result)

    def __transform(self, args) -> list:
        output = deque()
        operators = deque()

        while len(args):
            arg = args.pop()
            validation.validate(arg, self.symbols_allowed)

            if arg == ')':
                operators.append(arg)
            elif arg == '(':
                found = False
                while len(operators):
                    val = operators.pop()
                    if val == ')':
                        found = True
                        break
                    output.append(val)

                if not found:
                    raise InvalidInputError('Parentheses mismatch')

            elif arg in self.ops.keys():
                operators.append(arg)

            else:
                output.append(arg)

        while len(operators):
            val = operators.pop()
            if not val in self.ops.keys():
                raise InvalidInputError('Parentheses mismatch')

            output.append(val)

        output.reverse()
        return output
Example #15
0
def untweet(tid, uid):
	"untweet a retweeted tweet"
	
	d = op.get('RETWEET',uid)
	print d
	for k in d.keys():
		if d[k]==tid or k==tid:
			t1,t2 = k,d[k]

	op.remove_column('RETWEET', uid, [t1])
	delete_tweet(t2,uid)
Example #16
0
def login(uid, password) :
	"check if a user is valid"
	print "inside login"
	try:
        	d = op.get('USERS', uid)
		if (d['password'] == password) :
			return 1
		else :
			return 2
	except:
		return 0
	return 1
Example #17
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
Example #18
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
Example #19
0
def delete_tweet(tweetid,uid) :
	"to delete a tweet"
	val = op.get('TWEETS',tweetid)
	op.remove_row('TWEETS', tweetid)
	key = str(val['timestamp']) + ":" + uid
	op.remove_column('USERLINE', uid, [key])				#delete from timeline and userline
	op.remove_column('TIMELINE', uid, [key])
	print "during delete " + key
	for followerID in op.get('FOLLOWER', uid):
		print followerID
		if 'status' != followerID:
			op.remove_column('TIMELINE', followerID, [key])		#delete from followers timeline

	d = op.get('FAVORITE_IS', tweetid)					#delete from favourites list
	op.remove_row('FAVORITE_IS', tweetid)
	for key in d:
		v = str(d[key])
		op.remove_column('FAVORITE_OF',key,[v])
	d = op.get_all('HASH_TAGS')
        for k,v in d:
                for key,val in v.items():
                        if 'status' != key:
                                if str(tweetid) == str(val):
                                        op.remove_column('HASH_TAGS',k,[key])
Example #20
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})
Example #21
0
def get_people(val,uid): 
	"get people" 
	d = op.get('FOLLOWING',uid)
	result1 = {}
	if 'status' not in d.keys():
		e = op.multi_get('USERS',d.keys())
		for k in e.keys():	 
			if e[k]['username'].lower().find(val.lower()) != -1:
				result1[k] = e[k]['username']

	d = op.get_all('USERNAME') 
	result = {} 
	for k,v in d:	 
		if k.lower().find(val.lower()) != -1:
			if v['uid'] not in result1:
				result[v['uid']] = k
	return result1,result
class PrefixCalculator(object):
    ops = operations.get()

    def __init__(self):
        self.stack = deque()

    def help(self) -> str:
        return 'Please provide a valid statement with '\
            'operators i.e. {} and positive integers'.format([ op for op in self.ops.keys()])

    def calculate(self, args) -> int:
        """
        args support operators {+, -, *, /} and integers
        """
        if not len(args):
            raise InvalidInputError(self.help())

        self.stack.clear()

        while len(args):
            arg = args.pop()
            validation.validate(arg, self.ops.keys())
            self.__step(arg)

        if len(self.stack) > 1:
            raise InvalidInputError(
                'Not enough operations to perform calculation')

        return self.stack.pop()

    def __step(self, arg) -> None:
        if not arg in self.ops.keys():
            self.stack.append(int(arg))
            return

        if len(self.stack) < 2:
            raise InvalidInputError('Too many operations for given operands')

        top = self.stack.pop()
        bottom = self.stack.pop()
        val = self.ops[arg](top, bottom)
        self.stack.append(val)
Example #23
0
def unfollow():
    "inside unfollow"
    follower = session["other_user"]
    following = session["username"]
    followerId = op.get("USERNAME", follower)
    followingId = op.get("USERNAME", following)
    d = op.get("FOLLOWING", followingId["uid"])
    uid1 = followerId["uid"]
    uid2 = followingId["uid"]
    op.remove_column("FOLLOWING", followingId["uid"], [uid1])
    t = op.get("FOLLOWER", followerId["uid"])
    op.remove_column("FOLLOWER", followerId["uid"], [uid2])
    d = op.get("TIMELINE", uid2)
    for key, value in d.iteritems():
        val = op.get("TWEETS", value)
        if "status" not in val:
            if val["user"] == str(uid1):
                t = str(val["timestamp"]) + ":" + uid1
                op.remove_column("TIMELINE", uid2, [t])
    return redirect(url_for("get_userline"))
Example #24
0
def get_retweets(uid):
	"get retweets of a user"
	d = op.get('RETWEET',uid)
	return d
Example #25
0
def get_reply(tid):
	d = op.get('REPLY_TO_TWEET', tid)
	replies = d.values()
	tweets = op.multi_get('TWEETS',replies)
	original_tweet = op.get('TWEETS',tid)
	return tweets, replies, original_tweet
Example #26
0
def parse(tid,uid):
	val = op.get('TWEETS',tid)
	timestamp = str(val['timestamp']) + ":" + str(val['user'])
	check_for_hashtag(val['body'],tid,timestamp)
	check_for_reference(val['body'],tid,timestamp)