Exemplo n.º 1
0
def createClub(request=None):

        #When createClubRequest is called

        print("Request Entity for Create Club ", request)
        clubRequest = Club_Creation()


        collegeId = ndb.Key('CollegeDb',int(request.college_id))
        college = CollegeDb.query(CollegeDb.key == collegeId).fetch(1)

        college_key = college[0].key



        if request and college :

            for field in ('abbreviation','club_name','from_pid','to_pid','isAlumni','collegeId','description'):


                if field == "abbreviation":
                    clubRequest.abbreviation = request.abbreviation
                elif field == "club_name":
                    clubRequest.club_name = request.club_name
                elif field == "description":
                    clubRequest.description = request.description

                elif field == "from_pid":
                     print("Entered from_pid")
                     profile =  Profile(
                            name = 'SiddharthSend',
                            email = '*****@*****.**',
                            phone = '7760531993',
                            isAlumni='N',
                            collegeId=college_key
                            )
                     profile_key = profile.put()
                     print("Finished frompid")
                     setattr(clubRequest, field, profile_key)
                elif field == "to_pid":
                     print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',

                               isAlumni='N',
                               collegeId=college_key
                               )
                     profile_key = profile.put()

                     setattr(clubRequest, field, profile_key)
                elif field == "isAlumni":
                     setattr(clubRequest, field, "N")
                elif field == "collegeId":
                     setattr(clubRequest, field, college_key)
            clubRequest.put()

        return clubRequest
Exemplo n.º 2
0
    def get_or_create_profile(self, profile_name):
        profile_model = Profile()
        profile_model.name = profile_name

        profile_entity = Logic.database.get_profile_by_name(profile_model.name)
        if not profile_entity:
            profile_entity_id = Logic.database.create_profile(profile_model)
            profile_entity = Logic.database.get_profile_by_id(
                profile_entity_id)

        return profile_entity
Exemplo n.º 3
0
def _getProfileFromEmail(email):
    user_id = Profile.query(Profile.email == email).fetch(1)
    if len(user_id) > 0:
        print "User Existed"
        return user_id[0]

    else:
        print "New User"
        return Profile(
            name='',
            email='',
            phone='',
            isAlumni='N',
        )
Exemplo n.º 4
0
 def getProfile(self, request):
      """Return user profile."""
      email=getattr(request,"email")
      result = Profile.query(Profile.email==email)
      present =0
      isAdmin="N"
      isSuperAdmin="N"
      for y in result:
          if y.email == email:
              present = 1
              if y.admin is not None:
                  if len(y.admin)>0:
                      isAdmin="Y"
              if y.superadmin is not None:
                  if len(y.superadmin)>0:
                      isSuperAdmin="Y"
      if present ==1:
          success="True"
          a = _doProfile(email)
          return ProfileResponse(success=success,result=a,isAdmin=isAdmin,isSuperAdmin=isSuperAdmin)
      else:
          success="False"
          a = ProfileMiniForm(name = '',
                         email = '',
                         phone = '',
                         isAlumni='',
                         collegeId =''
                         )
          return ProfileResponse(success=success,result=a,isAdmin=isAdmin,isSuperAdmin=isSuperAdmin)
Exemplo n.º 5
0
def read_profile(filename: str):
    """
    Liest das angegebene Profil aus. Dort ist auch das verwendete Insulin angegeben.

    :return: Gibt das verwendete Profil zurück.
    """
    # TODO: read the actual Profile instead of Dummy-Object

    return Profile("Humalog", "mg/dl")
Exemplo n.º 6
0
def changeGcm(request):
    email = request.email

    profile = Profile.query(Profile.email == email)
    print type(profile)

    for y in profile:
        print y.gcmId

        y.gcmId = request.gcmId
        y.put()

    return
Exemplo n.º 7
0
   def insertUnique(self,request):

        #This method is just a reference in order for you to reuse this code in order to insert unique entries in the DB
        college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        college_key = college.put()
        query = CollegeDb.query()

        profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= college_key)

        profileret = Profile.query(Profile.pid == profile.pid).fetch(1)
        print("A is ", profileret)
        if profileret:
          print("Not inserting")
        else :
          print("Inserting")
          profile_key = profile.put()
Exemplo n.º 8
0
def changeGcm(request):
    email = request.email

    profile = Profile.query(Profile.email==email)
    print  type(profile)

    for y in profile:
        print y.gcmId

        y.gcmId = request.gcmId
        y.put()

    return
Exemplo n.º 9
0
def _getProfileFromEmail(email):
        user_id=Profile.query(Profile.email==email).fetch(1)
        if len(user_id)>0:
            print "User Existed"            
            return user_id[0]
            
        else:
            print "New User"
            return Profile(name = '',
                           email = '',
                           phone = '',
                           isAlumni='N',
                           )
Exemplo n.º 10
0
    def map_profile_query_result(self, query_result):
        profiles = []
        for row in query_result:
            profile = Profile()

            profile.id = int(row[0])
            profile.name = row[1]
            profile.ranked_pp = float(row[2])
            profile.unranked_pp = float(row[3])
            profile.total_pp = float(row[4])
            profile.rank = int(row[5])

            profiles.append(profile)

        return profiles
Exemplo n.º 11
0
   def setSuperAdmin(self,request):
       collegeKey = ndb.Key('CollegeDb',int(request.collegeId))
       college = collegeKey.get()
       emailId = college.sup_emailId
       retrievedProfile = Profile.query(Profile.email==emailId).fetch(1)
       print ("retrievedProfile is",retrievedProfile[0])

       if not retrievedProfile[0].superadmin:
          retrievedProfile[0].superadmin.append(collegeKey)
          retrievedProfile[0].put()
          print("inserted into profile table")       



       return message_types.VoidMessage()
Exemplo n.º 12
0
def _getProfileFromUser():
        """Return user Profile from datastore"""
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required f**k you')

        user_id=Profile.query(Profile.email==user.email()).fetch(1)
        if len(user_id)>0:
            return user_id[0]
            #p_key = ndb.Key(Profile, user_id[0])
            #profile = p_key.get()

        else:
            return Profile(name = '',
                           email = '',
                           phone = '',
                           isAlumni='N',
                           )
Exemplo n.º 13
0
def createCollege(requestentity=None):

        newCollege = CollegeDb()
        query = CollegeDb.query()
        print "The data got on querying is " , query , " type is ", type(query), "\n"
        count = 0
        names = []
        location = []

        """profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= 'NIoTK')
        profile_key = profile.put()
        """

        for records in query:
           print"The name of the college is ", records.name , " and location is " , records.location
           names.append(records.name)
           location.append(records.location)
           count += 1
           #print "\n"

        print "count is, " , count

        collegeName = ""
        if requestentity:
            for field in ('name','abbreviation','location','student_sup','alumni_sup','email'):
                val = getattr(requestentity, field)
                if field == "name":
                    collegeName = getattr(requestentity, field).strip()
                if val:
                    val = val.strip()
                    print("Value is",val)
                    setattr(newCollege, field, str(val))
            #Now setting the attributes not recieved from the front-end.
            setattr(newCollege, 'student_count', 0)
            setattr(newCollege, 'group_count', 0)
            newlist = []
            setattr(newCollege, 'group_list', newlist)
            setattr(newCollege,'sup_emailId',requestentity.email)
            # Making CollegeId
            newString = ""
            newString = collegeName[0]
            for x in xrange(len(collegeName)):
                if(collegeName[x]==' '):
                    newString+=collegeName[x+1]

            setattr(newCollege, 'collegeId', newString)

        print(newCollege)
        flag = 0
        for var in xrange(count):
            if(newCollege.name==names[var] and newCollege.location==location[var]):
                flag=1

        if(flag):
            print "Sorry already existing record"

        else:
            print "Unique"
            email = getattr(requestentity, "email")
            phone = getattr(requestentity, "phone")
            if(getattr(requestentity, "student_sup")==None):
                isAlumni = "Yes"
                person_name = getattr(requestentity, "alumni_sup")
            else:
                isAlumni = "No"
                person_name = getattr(requestentity, "student_sup")

            collegeId = newCollege.put()
            profile =  Profile(name = person_name ,
                            email = email,
                            phone = phone,
                            isAlumni=isAlumni,
                            collegeId= collegeId)
            profile.superadmin.append(collegeId)
            key1 = profile.put()
            return newCollege
Exemplo n.º 14
0
import Models.Profile as Profile
import pymongo
import json
import requests
import datetime
import Models.Outbound as Outbound

app = FastAPI()


client = pymongo.MongoClient("mongodb+srv://redants:[email protected]/Whatsapp?retryWrites=true&w=majority")
db = client["Whatsapp"]
collection = db["Profile"]


UserProfile = Profile.Profile()
MessageArray = []


msgg = Outbound.TextMessage()
msgg.type = "text"
msgg.text = "Another one!"


@app.post('/webhook/',  status_code=200)
async def index(DBMessage: Inbound.Message):
    if DBMessage.type == 'message':
        # Check if User Phone number already exists, if exists then add message to user else create user and add message. Search DB for Sender Phone
        DBMessage.payload.payload.direction = "Received"
        DBMessage.payload.payload.type = DBMessage.payload.type
        DBMessage.payload.payload.timestamp = DBMessage.timestamp
Exemplo n.º 15
0
def postEntry(requestentity=None,check=0):

        newPost = Post()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        club_name = Club.query()
        if check==0:
            print "The request entity key is " + requestentity.club_id
            key1 = ndb.Key('Club',int(requestentity.club_id))
            key2 = ndb.Key('Profile',int(requestentity.from_pid))
        else:
            key1 = requestentity.club_id
            key2 = requestentity.from_pid

        persons = Profile.query()
        #print club_name[0]
        #print "The key is " + club_name[0].key
        club_key = key1
        profile_key = key2
        flag = 0
        flag1 = 0
        clubs = Club.query()

        print "Profile Key " + str(profile_key)
        for x in persons:
            print x.key
            if(x.key == profile_key):
                print "Same"
                flag=1
            else:
                print "NOPE"

        for x in clubs:
            print x.key
            if(x.key == club_key):
                print "Same"
                flag1=1
            else:
                print "NOPE"

                    #setattr(clubRequest, field, profile_key)

        if(flag==1 and flag1==1):
            if requestentity:
                for field in ('title','description','club_id','from_pid','likes','views','timestamp','photo','photoUrl'):

                    if hasattr(requestentity, field):
                        print(field,"is there")
                        val = getattr(requestentity, field)
                        if(field=="club_id"):
                            print "Club_Id stage"
                            setattr(newPost, field, club_key)

                        elif field == "from_pid":
                            print "Entered here"
                            person = profile_key.get()
                            print "Person's email-id ", person.email
                            person_collegeId = person.collegeId
                            print "His college Id ", person.collegeId
                            college_details = person_collegeId.get()
                            print "The sup is ", college_details.student_sup
                            setattr(newPost, field, profile_key)
                            print "Put PID"
                            setattr(newPost,'collegeId',person_collegeId)
                            print "Put college id"

                        elif field=="timestamp":
                            setattr(newPost, field, val)

                        elif val:
                            print("Value is",val)
                            setattr(newPost, field, str(val))



                    else:
                        if field == "timestamp":
                            temp = datetime.strptime(getattr(requestentity,"date"),"%Y-%m-%d").date()
                            temp1 = datetime.strptime(getattr(requestentity,"time"),"%H:%M:%S").time()
                            setattr(newPost,field,datetime.combine(temp,temp1))

                        setattr(newPost, "likes", 0)
                        setattr(newPost, "views", 0)

            print("About to create Post")
            print(newPost)
            newPost.put()


        else:
             print "Invalid Entry"



        return newPost
Exemplo n.º 16
0
def createClub(request=None):

    #When createClubRequest is called

    print("Request Entity for Create Club ", request)
    clubRequest = Club_Creation()

    collegeId = ndb.Key('CollegeDb', int(request.college_id))
    college = CollegeDb.query(CollegeDb.key == collegeId).fetch(1)

    college_key = college[0].key

    if request and college:

        for field in ('abbreviation', 'club_name', 'from_pid', 'to_pid',
                      'isAlumni', 'collegeId', 'description',
                      'approval_status', 'photoUrl', 'timestamp'):

            if field == "abbreviation":
                clubRequest.abbreviation = request.abbreviation
            elif field == "club_name":
                clubRequest.club_name = request.club_name
            elif field == "description":
                clubRequest.description = request.description

            elif field == "from_pid":
                profile_key = ndb.Key('Profile', int(request.from_pid))
                print("Finished frompid")
                setattr(clubRequest, field, profile_key)
            elif field == "to_pid":
                '''print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               isAlumni='N',
                               collegeId=college_key
                               )'''
                #get the college of the from_pid guy
                #Get the email of the college
                #correspond it to the SUP profile
                #get his key and save it

                from_pid_key = ndb.Key('Profile', int(request.from_pid))
                from_profile = from_pid_key.get()

                print("From Profile is", from_profile)
                college_key = from_profile.collegeId
                college = college_key.get()

                email = college.sup_emailId

                print("Email is", email)

                query = Profile.query(Profile.email == email).fetch(1)

                if (query[0]):
                    to_pid_key = query[0].key
                    print("to_pid_key", to_pid_key)
                    setattr(clubRequest, field, to_pid_key)
            elif field == "isAlumni":
                setattr(clubRequest, field, "N")
            elif field == "collegeId":
                setattr(clubRequest, field, college_key)
            elif field == "approval_status":
                setattr(clubRequest, field, "N")
            elif field == "photoUrl":
                if (request.photoUrl):
                    setattr(clubRequest, field, str(request.photoUrl))

            elif field == "timestamp":
                print("Going to enter timestamp")
                setattr(clubRequest, field,
                        dt.datetime.now().replace(microsecond=0))

        clubRequest.put()

    return clubRequest
Exemplo n.º 17
0
def postEntry(requestentity=None,check=0):

        newPost = Post()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        club_name = Club.query()
        if check==0:
            print "The request entity key is " + requestentity.club_id
            key1 = ndb.Key('Club',int(requestentity.club_id))
            key2 = ndb.Key('Profile',int(requestentity.from_pid))
        else:
            key1 = requestentity.club_id
            key2 = requestentity.from_pid

        persons = Profile.query()
        #print club_name[0]
        #print "The key is " + club_name[0].key
        club_key = key1
        profile_key = key2
        flag = 0
        print "Profile Key " + str(profile_key)
        for x in persons:
            print x.key
            if(x.key == profile_key):
                print "Same"
                flag=1
            else:
                print "NOPE"
                    #setattr(clubRequest, field, profile_key)

        if(flag==1):
            if requestentity:
                for field in ('title','description','club_id','from_pid','likes','views'):

                    if hasattr(requestentity, field):
                        print(field,"is there")
                        val = getattr(requestentity, field)
                        if(field=="club_id"):
                            print "Club_Id stage"
                            setattr(newPost, field, club_key)

                        elif field == "from_pid":
                            print "Entered here"
                            person = profile_key.get()
                            print "Person's email-id ", person.email
                            person_collegeId = person.collegeId
                            print "His college Id ", person.collegeId
                            college_details = person_collegeId.get()
                            print "The sup is ", college_details.student_sup
                            setattr(newPost, field, profile_key)
                            print "Put PID"
                            setattr(newPost,'collegeId',person_collegeId)
                            print "Put college id"

                        elif val:
                            print("Value is",val)
                            setattr(newPost, field, str(val))


                    else:
                        setattr(newPost, "likes", 0)
                        setattr(newPost, "views", 0)

            print("About to create Post")
            print(newPost)
            newPost.put()


        else:
             print "Invalid Person"



        return
Exemplo n.º 18
0
def createClub(request=None):

    # When createClubRequest is called

    print("Request Entity for Create Club ", request)
    clubRequest = Club_Creation()

    collegeId = ndb.Key("CollegeDb", int(request.college_id))
    college = CollegeDb.query(CollegeDb.key == collegeId).fetch(1)

    college_key = college[0].key

    if request and college:

        for field in (
            "abbreviation",
            "club_name",
            "from_pid",
            "to_pid",
            "isAlumni",
            "collegeId",
            "description",
            "approval_status",
            "photoUrl",
            "timestamp",
        ):

            if field == "abbreviation":
                clubRequest.abbreviation = request.abbreviation
            elif field == "club_name":
                clubRequest.club_name = request.club_name
            elif field == "description":
                clubRequest.description = request.description

            elif field == "from_pid":
                profile_key = ndb.Key("Profile", int(request.from_pid))
                print("Finished frompid")
                setattr(clubRequest, field, profile_key)
            elif field == "to_pid":
                """print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               isAlumni='N',
                               collegeId=college_key
                               )"""
                # get the college of the from_pid guy
                # Get the email of the college
                # correspond it to the SUP profile
                # get his key and save it

                from_pid_key = ndb.Key("Profile", int(request.from_pid))
                from_profile = from_pid_key.get()

                print("From Profile is", from_profile)
                college_key = from_profile.collegeId
                college = college_key.get()

                email = college.sup_emailId

                print("Email is", email)

                query = Profile.query(Profile.email == email).fetch(1)

                if query[0]:
                    to_pid_key = query[0].key
                    print("to_pid_key", to_pid_key)
                    setattr(clubRequest, field, to_pid_key)
            elif field == "isAlumni":
                setattr(clubRequest, field, "N")
            elif field == "collegeId":
                setattr(clubRequest, field, college_key)
            elif field == "approval_status":
                setattr(clubRequest, field, "N")
            elif field == "photoUrl":
                if request.photoUrl:
                    setattr(clubRequest, field, str(request.photoUrl))

            elif field == "timestamp":
                print("Going to enter timestamp")
                setattr(clubRequest, field, dt.datetime.now().replace(microsecond=0))

        clubRequest.put()

    return clubRequest