Exemple #1
0
def aps_listener(event):
    text = ''
    
    if event.exception:
        rval = Profile().find_by_pk(int(event.job.name.replace('wj_', '')))['profile']
        data = {'type' : 'error',
                'event': 'scheduled_run',
                'created_at' : event.scheduled_run_time,
                'u_id': rval.get('u_id'),
                'j_id':rval.get('id')
        }
        text = '"%s" was failed due to %s' % (rval['title'], event.exception)
        data['text'] = text
    else:
        rval = event.retval
        data = {'type' : 'success',
                'event': 'scheduled_run',
                'created_at' : event.scheduled_run_time,
                'u_id': rval.get('u_id'),
                'j_id':rval.get('id')
        }
        text = '"%s" has been completed successfully' % rval['title']
        data['text'] = text
        
    q = EventlogModel.insert(**data)
    q.execute()
Exemple #2
0
def load_profiles():
    """ Load the user profiles into the DB """

    print "Profiles"

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Profile.query.delete()

    foodie = Profile(type_name="Foodie",
                     type_taste=['spicy', 'salty', 'sweet', 'umami'])
    starving_student = Profile(type_name="Starving Student", type_price=['1'])
    health_nut = Profile(type_name="Health Nut",
                         type_diet=['vegan', 'gluten_free'])
    heat_seeker = Profile(type_name="Heat Seeker",
                          type_taste=['spicy'],
                          type_temp=['hot'])
    garbage_disposal = Profile(type_name="Garbage Disposal")

    # We need to add to the session or it won't ever be stored
    db.session.add(foodie)
    db.session.add(starving_student)
    db.session.add(health_nut)
    db.session.add(heat_seeker)
    db.session.add(garbage_disposal)

    # Once we're done, we should commit our work
    db.session.commit()
Exemple #3
0
    def post(self):
        """Creates new user account if provided valid arguments"""
        parser = reqparse.RequestParser()
        parser.add_argument('first_name',
                            type=UserValidator.create('name'),
                            required=True)
        parser.add_argument('last_name',
                            type=UserValidator.create('name'),
                            required=True)
        parser.add_argument('email',
                            type=UserValidator.create('unique_email'),
                            required=True)
        parser.add_argument('password',
                            type=UserValidator.create('password'),
                            required=True)
        parser.add_argument('terms',
                            type=bool,
                            required=True,
                            help='Must agree to all terms and conditions')
        args = parser.parse_args()

        if not args.terms:
            return ApiException.error(107)

        count = 0
        username = util.create_username_from_email(args.email)
        while (True):  # get a unique username
            if User.is_username_available(username):
                break
            username += str(count)
            count += 1

        user_db = auth.create_user_db(
            auth_id=None,
            username=util.create_username_from_email(args.email),
            email=args.email,
            verified=True if not config.CONFIG_DB.verify_email else False,
            password=args.password,
            avatar_url=User.get_gravatar_url(args.email),
            roles=[User.Roles.MEMBER],
            first_name=args.first_name,
            last_name=args.last_name,
        )
        user_db.put()

        Profile.get_or_create(user_db)

        if config.CONFIG_DB.verify_email:
            task.verify_user_email_notification(user_db)

        # sign in user
        auth.signin_user_db(user_db, remember=True)
        return user_db.to_dict(include=User.get_private_properties())
Exemple #4
0
def profile():
    my_form = ProfileForm()  #初始化表单
    my_data = Profile(
    )  #初始化数据,没这行,数据无法放在form中,给该表单提交的数据起名为my_data,即first_name那列数据就叫my_data.first_name
    my_data.remove_none_values()  #call the function
    if my_form.validate_on_submit():  #意思是如果表单提交成功
        my_data.first_name = request.form.get('first_name')
        my_data.last_name = request.form.get('last_name')
        #print("first_name", my_data.first_name)
        #print("last_name", my_data.last_name)
        file = request.files.get('file_photo')
        if file:
            orig_filename = secure_filename(file.filename)
            new_filename = str(uuid.uuid1())  #生成uuid
            my_data.file_photo_filename = orig_filename  #To save the orignal file name
            my_data.file_photo_code = new_filename
            #上面这行是为了存储uuid,目的是如果不同用户上传的不用文件,起了同一个名,靠uuid来区分

            # save to upload folder
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], new_filename))

            #save to database
            db.session.add(my_data)
            db.session.commit()
            print("my_data", my_data.id)

            #redirect to display page
            return redirect('/profile/' +
                            str(my_data.id))  #这个意思是每个数据的特定URL,比如profile/5...

    return render_template("profile.html", my_form=my_form, my_data=my_data)
Exemple #5
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('cursor', type=ArgumentValidator.create('cursor'))
        args = parser.parse_args()

        profiles_future = Profile.query() \
            .order(-Profile.modified) \
            .fetch_page_async(10, start_cursor=args.cursor)

        total_count_future = Profile.query().count_async(keys_only=True)
        profiles, next_cursor, more = profiles_future.get_result()
        profiles = [u.to_dict(include=u.public_properties) for u in profiles]
        return make_list_response(profiles, next_cursor, more,
                                  total_count_future.get_result())
Exemple #6
0
def scrape_twitter_account(username):
    '''
    Scrape twitter bio data and create (or update) a profile.

    TODO The API call used here supports up to 100 usernames at a time. We
    could easily modify this function to populate many profiles at once.
    '''

    # Request from Twitter API.
    db_session = worker.get_session()

    api_url = 'https://api.twitter.com/1.1/users/lookup.json'
    params = {'screen_name': username}
    response = requests.get(
        api_url,
        params=params,
        proxies=_get_proxies(db_session),
        verify=False
    )
    response.raise_for_status()

    # Get Twitter ID and upsert the profile.
    data = response.json()[0] # TODO Only supports getting 1 profile right now...
    user_id = data['id_str']
    profile = Profile('twitter', user_id, data['screen_name'])
    db_session.add(profile)

    try:
        db_session.commit()
    except IntegrityError:
        # Already exists: use the existing profile.
        db_session.rollback()
        profile = db_session.query(Profile) \
                            .filter(Profile.site=='twitter') \
                            .filter(Profile.upstream_id==user_id) \
                            .one()

    _twitter_populate_profile(data, profile)
    profile.is_stub = False
    db_session.commit()

    # Schedule followup jobs.
    app.queue.schedule_avatar(profile, data['profile_image_url_https'])
    app.queue.schedule_index_profile(profile)
    app.queue.schedule_posts(profile, recent=True)
    app.queue.schedule_relations(profile)

    return profile.as_dict()
Exemple #7
0
 def get(self):
     template_values = {
         'profile': Profile.all(),
         'servicos': servicesMount(),
     }
     path = os.path.join(os.path.dirname(__file__), 'index.html')
     self.response.out.write(template.render(path, template_values))
Exemple #8
0
def addprofile():
    """ process post request to add new profile to db"""
    name = request.form.get('name')
    birthdate = request.form.get('birthdate')
    gender = request.form.get('gender')

    gender_bool = False

    if gender == 'Male':
        gender_bool = False
    elif gender == 'Female':
        gender_bool = True

    new_profile = Profile(name=name,
                          birthdate=birthdate,
                          gender=gender_bool,
                          user_id=session.get('userid'))
    db.session.add(new_profile)
    db.session.commit()
    flash("New profile {} has been created".format(name))

    profile_obj = Profile.query.filter(Profile.name == name).filter(
        Profile.user_id == session.get('userid')).first()

    return redirect('/profile/{}/{}'.format(session['userid'],
                                            profile_obj.profile_id))
Exemple #9
0
def main():

    start_mapper()

    # create all tables
    metadata.create_all(bind=engine)

    # initiate repository
    user_repo = SqlRepository(session)

    user = User("ed", "secret")
    profile = Profile("John", "Doe", "*****@*****.**")

    user.profile = profile

    # add user and profile to database
    user_repo.add(user)

    # save
    session.commit()

    # query database
    user = user_repo.get(username="******")

    print(user, user.profile)
Exemple #10
0
def profil_actions():
    act = request.args.get('act')
    p_id = request.args.get('p_id')
    try:
        if act == 'active':
            schedule_job(p_id)
            return resp_format.from_dict(resp_format.MSG_OK,
                                         msg='Profile successfully activated')
        elif act == 'pause':
            unschedule_job(p_id)
            return resp_format.from_dict(resp_format.MSG_OK,
                                         msg='Profile successfully paused')
        elif act == 'delete':
            unschedule_job(p_id)
            Profile().delete_by_pk(p_id)
            return resp_format.from_dict(resp_format.MSG_OK,
                                         msg='Profile hase been deleted')
        elif act == 'run':
            profile_execute(p_id)
            return resp_format.from_dict(resp_format.MSG_OK,
                                         msg='Job completed successfully')

    except Error.ProfileException as e:
        return resp_format.from_dict(resp_format.MSG_FAIL, msg=str(e))
    except Exception, e:
        return resp_format.from_dict(resp_format.MSG_FAIL, msg=str(e))
Exemple #11
0
def profile():
    if request.method == 'GET':
        return profile_list()

    try:
        s = {}
        d = {}
        o = {}
        for k, v in request.form.iteritems():
            if k.startswith('src_'):
                s[k] = v
            elif k.startswith('dst_'):
                d[k] = v
            elif k.startswith('opt_'):
                o[k] = v

        p_id = Profile().create(s, d, o)
        schedule_job(p_id)

        return resp_format.from_dict(resp_format.MSG_OK,
                                     msg='Profile successfully created')
    except Error.ProfileException as e:
        return resp_format.from_dict(resp_format.MSG_FAIL, msg=str(e))
    except Error.TestConfigException as e:
        return resp_format.from_dict(resp_format.MSG_FAIL, msg=str(e))
Exemple #12
0
    def get_search(self, parameters, fields=[]):
        """
        Use the People Search API to find LinkedIn profiles using keywords,
        company, name, or other methods. This returns search results,
        which are an array of matching member profiles.

        You can specify the fields you want to see using the field list (:people...)

        Request URL Structure:
        http://api.linkedin.com/v1/people-search[:(people:(id,first-name,last-name,headline,connections,positions,picture-url,public-profile-url))]?first-name=[first name]&last-name=[last name] ...

        To learn more refer to https://developer.linkedin.com/documents/people-search-api .

        Note that the search API was deprecated a while ago and replaced by the people-search API. The result structure changes slightly because people-search returns the entire response in a new people-search tag.

        people-search returns a slightly different structure --

        search returned..

        <people>
          <person/>
          <person/>
          ...
          <person/>
        </people>

        but people_search returns
        <people-search>
            <people>
                <person/>
                <person/>
                ...
                <person/>
            </people>
        </people_search>

        So users will have to update their code to reflect this new structure.
        """

        self._check_tokens()
        fields = ":(people:(id,first-name,last-name,headline,positions,public-profile-url,picture-url,location:(name)))"
        response = self._do_normal_query("/v1/people-search" + fields, params=parameters)

        error = self._parse_error(response)
        if error:
            self._error = error
            #logging.error("Parsing Error")
            return None

        # Parse the response and list out all of the Person elements
        document = minidom.parseString(response)

        connections = document.getElementsByTagName("person")
        result = []

        for connection in connections:
            profile = Profile.create(connection, self._debug)
            if profile is not None:
                result.append(profile)
        return result
Exemple #13
0
    def get_connections(self, member_id = None, public_url = None, fields=()):
        """
        Fetches the connections of a user whose id is the given member_id or url is the given public_url
        If none of the parameters given, the connections of the current user are fetched.
        @Returns: a list of Profile instances or an empty list if there is no connection.

        Example urls:
        * http://api.linkedin.com/v1/people/~/connections (for current user)
        * http://api.linkedin.com/v1/people/id=12345/connections (fetch with member_id)
        * http://api.linkedin.com/v1/people/url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Flbeebe/connections (fetch with public_url)
        """
        self._check_tokens()

        raw_url = "/v1/people/%s/connections"
        if member_id:
            raw_url = raw_url % ("id=" + member_id)
        elif public_url:
            raw_url = raw_url % ("url=" + self._quote(public_url))
        else:
            raw_url = raw_url % "~"
        fields = ":(%s)" % ",".join(fields) if len(fields) > 0 else None
        if fields:
            raw_url = raw_url + fields

        response = self._do_normal_query(raw_url)
        document = minidom.parseString(response)
        connections = document.getElementsByTagName("person")
        result = []
        for connection in connections:
            profile = Profile.create(connection, self._debug)
            if profile is not None:
                result.append(profile)

        return result
Exemple #14
0
def get_settings() -> Profile:
    """Gets the user settings profile for the application, or exits on failure.

    :return: The user settings profile.
    """

    settings_path: str = "~/lecture-hoarder-settings.yaml"
    if len(sys.argv) > 1:
        settings_path = sys.argv[
            1]  # User has specified custom settings file location

    settings: Profile = Profile()
    try:
        settings.load_from_file(settings_path)
    except IOError:
        # Could not open settings file, use default values
        print("Using default settings")
    except YAMLError as err:
        # Parser error occurred
        if hasattr(err, "context_mark") and hasattr(err, "problem"):
            print(
                f"Could not parse settings file - bad syntax at line {err.context_mark.line + 1} char "
                f"{err.context_mark.column + 1}: {err.problem}")
        else:
            print("Could not parse settings file")
        sys.exit(2)
    except TypeError as err:
        # Syntax fine, bad param type
        print(f"Could not load settings file - {err}")
        sys.exit(2)

    return settings
Exemple #15
0
    def get(self):
        creator = self.request.get('creator', '')
        logging.info("Creator: %s", creator)
        logging.info(self.request.arguments())
        distance = self.request.get('distance', '')
        msg = ""
        found = []
        matches = Profile.all().filter('creator =', creator).fetch(1)
        if matches:
            user = matches[0]
        else:
            user = None
        results = []
        query = Profile.all()

        keys = dict(INTERESTS)
        for interest in self.request.arguments():
            if interest in keys:
                query = query.filter("interests =", interest)
                logging.info("interests = %s" % interest)
        if user and distance:
            if user.location is None:
                msg = "You need to enter your position on the map in your People Finder Profile wave before doing a location based search"
                results = query.fetch(20)
            else:
                max_distance = distance_to_meters(
                    distance, self.request.get('units', ''))
                results = Profile.proximity_fetch(
                    query,
                    user.location,  # Or db.GeoPt
                    max_results=20,
                    max_distance=max_distance  # meters
                )
        else:
            results = query.fetch(20)

        if user:
            found = [{
                'name': r.name,
                'id': r.creator
            } for r in results if r.key().name() != user.key().name()]
        else:
            found = [{'name': r.name, 'id': r.creator} for r in results]
        gtugs = simplejson.dumps({'msg': msg, 'results': found})
        logging.info("response: %s" % gtugs)
        self.response.headers.add_header('Content-type', 'application/json')
        self.response.out.write(gtugs)
Exemple #16
0
 def get(self):
   user = users.get_current_user()
   login_url = users.create_login_url()
   if user:
     profiles = Profile.query(Profile.user_id==user.user_id()).fetch()
     self.render_json(profiles)
   else:
     self.redirect('/')
Exemple #17
0
 def get(self):
   user = users.get_current_user()
   logout_url = users.create_logout_url(self.request.uri)
   login_url = users.create_login_url(self.request.uri) # raise NotAllowedError
   profile=''
   if user:
     profile = Profile.query(Profile.user_id==user.user_id())
     if profile.count() <= 0:
       profile = Profile()
       profile.user_id = user.user_id()
       profile.email = user.email()
       profile.firstname = user.nickname()
       profile_key = profile.put()
     else:
       profile_key = Profile.query(Profile.user_id==user.user_id())
     profile = profile_key.get()
     current_user = '******'+ user.nickname()
     user_url = logout_url
     title = "Click to logout from Google."
   else:
     current_user = '******'
     user_url = login_url 
     title = "Click to sign in with your Google Account."
   values = {
     'current_user' : current_user,
     'user_url' : user_url,
     'profile' : profile,
   }
   self.render_html('index.html',values)
Exemple #18
0
 def post(self): 
   s = self.request.get('s').title().strip()
   user = users.get_current_user()
   logout_url = users.create_logout_url(self.request.uri)
   login_url = users.create_login_url(self.request.uri)
   profiles = Profile.query(ndb.OR(Profile.firstname==s,Profile.lastname==s))
   resumes = Resumes.query(Resumes.position==s)
   jobs = Jobs.query(ndb.OR(Jobs.position==s,Jobs.company==s))
   self.render_multi_json(resumes=resumes,profiles=profiles,jobs=jobs)
Exemple #19
0
def get_profiles(search_string):
    ''' get a list of profile names that satisfy a mandatory search string '''
    if search_string == None or len(search_string) < 1:
        raise ActionException('You must provide a search string')
    upper_search = search_string.upper();
    return [p.name for p in 
        Profile.query(query.AND(
        Profile.name_order >= upper_search,
        Profile.name_order <= upper_search + "ZZZZZZ")).order(Profile.name_order).fetch(10)]
Exemple #20
0
    def post(self, key, item_type,
             item_key):  # updates an existing profile item
        user_id = g.model_db.id()
        profile = Profile.get_by('user_id', user_id)
        if auth.current_user_db().id(
        ) != user_id:  # check profile belongs to current_user
            return ApiException.error(108)

        return self.update_item(profile, item_type, item_key)
Exemple #21
0
def create_plant_profile(user_id, plant_id):
    """Create and return a new plant greenhouse for user."""

    plant_profile = Profile(user_id=user_id, plant_id=plant_id)

    db.session.add(plant_profile)
    db.session.commit()

    return plant_profile
Exemple #22
0
    def get_profile_raw(self, raw_url, params=None):
        """
        Use the profile API of linked in. Just append the raw_url string to the v1/people/ url
        and the dictionary params as parameters for the GET request
        """

        self._check_tokens()

        response = self._do_normal_query("/v1/people/" + raw_url, params=params)
        return Profile.create(minidom.parseString(response), self._debug)
Exemple #23
0
  def get(self):
    creator = self.request.get('creator', '')
    logging.info("Creator: %s", creator);
    logging.info(self.request.arguments())
    distance = self.request.get('distance', '')
    msg = ""
    found = []
    matches = Profile.all().filter('creator =', creator).fetch(1)
    if matches:
      user = matches[0]
    else:
      user = None
    results = []
    query = Profile.all()

    keys = dict(INTERESTS)
    for interest in self.request.arguments():
      if interest in keys:
        query = query.filter("interests =", interest)
        logging.info("interests = %s" % interest)
    if user and distance:
      if user.location is None:
        msg = "You need to enter your position on the map in your People Finder Profile wave before doing a location based search"
        results = query.fetch(20)
      else:
        max_distance = distance_to_meters(distance, self.request.get('units', ''))
        results = Profile.proximity_fetch(
          query,
          user.location,  # Or db.GeoPt
          max_results=20,
          max_distance=max_distance # meters
        ) 
    else:
      results = query.fetch(20)

    if user:
      found = [{'name': r.name, 'id': r.creator} for r in results if r.key().name() != user.key().name()]
    else:
      found = [{'name': r.name, 'id': r.creator} for r in results]
    gtugs = simplejson.dumps({'msg': msg, 'results': found})
    logging.info("response: %s" % gtugs)
    self.response.headers.add_header('Content-type', 'application/json')
    self.response.out.write(gtugs)
Exemple #24
0
def get_profile():
    user = users.get_current_user()

    if user:
        user_id = user.user_id()
        p_key = ndb.Key(Profile, user_id)
        profile = p_key.get()
        # create a Profile if not found
        if not profile:
            profile = Profile(
                key=p_key,
                nickName=user.nickname(),
                eMail=user.email(),
            )
            profile.put()

        return profile
    else:
        return None
Exemple #25
0
def load_profile():
    Profile.query.delete()

    kellie1 = Profile(user_id=1,
                      name="Matthew",
                      birthdate="2016-08-06",
                      gender=False)

    db.session.add(kellie1)

    db.session.commit()
Exemple #26
0
    def get_latest_profiles(self, total=3):
        """

        :param total: 需要的文章数量
        :return: 获取到的文章
        """
        sql = 'SELECT * FROM bai_profile ORDER BY publishTime DESC LIMIT {0}'.format(total)
        CrawlerLogger.logger.info('get latest ' + str(total) + ' profiles: ' + sql)
        MysqlLogger.logger.info('get latest ' + str(total) + ' profiles: ' + sql)
        profile_records = self.db.query(sql)  # db.query 又不是这个类的方法,为什么要 self 而不是 tornado.db.query呢?
        profiles = Profile.to_profiles(profile_records)
        return profiles  # <type 'list'>
Exemple #27
0
    def create(name):
        currentProfiles = session.query(Profile).all()
        #From the Class ProfileSchema
        schema = ProfileSchema(many=True)
        profiles = schema.dump(currentProfiles).data

        for p in json.loads(json.dumps(profiles)):
            print(p.get('name'))

        profile = Profile(name)
        session.add(profile)
        session.commit()
Exemple #28
0
    def put(self, key):
        user_id = g.model_db.id()
        profile = Profile.get_by('user_id', user_id)
        if auth.current_user_db().id() != user_id:  # logged in
            return ApiException.error(108)

        new_profile_data = _.pick(request.json,
                                  Profile.ALL_NON_STRUCTURED_PROPERTIES)
        profile.populate(**new_profile_data)
        profile.put()

        return profile.to_dict(include=profile.get_all_properties())
Exemple #29
0
def aps_listener(event):
    text = ''

    if event.exception:
        rval = Profile().find_by_pk(int(event.job.name.replace('wj_',
                                                               '')))['profile']
        data = {
            'type': 'error',
            'event': 'scheduled_run',
            'created_at': event.scheduled_run_time,
            'u_id': rval.get('u_id'),
            'j_id': rval.get('id')
        }
        text = '"%s" was failed due to %s' % (rval['title'], event.exception)
        data['text'] = text
    else:
        rval = event.retval
        data = {
            'type': 'success',
            'event': 'scheduled_run',
            'created_at': event.scheduled_run_time,
            'u_id': rval.get('u_id'),
            'j_id': rval.get('id')
        }
        text = '"%s" has been completed successfully' % rval['title']
        data['text'] = text

    q = EventlogModel.insert(**data)
    q.execute()
Exemple #30
0
 def post(self):
   s = self.request.get('s')
   user = users.get_current_user()
   logout_url = users.create_logout_url(self.request.uri)
   login_url = users.create_login_url(self.request.uri)
   profiles = Profile.query(ndb.OR(Profile.firstname==s,Profile.lastname==s))
   resumes = Resumes.query(Resumes.position==s)
   jobs = Jobs.query(ndb.OR(Jobs.position==s,Jobs.company==s))
   if user:
     user_profile = Profile.query(Profile.user_id==user.user_id()).get()
     current_user = '******'+ user_profile.firstname()
     user_url = logout_url
     title = "Click to logout from Google."
   values = {
     'current_user' : current_user,
     'user_url' : user_url,
     'profiles' : profiles,
     'resumes' : resumes,
     'jobs' : jobs,
     's' : self.request.get('s'),
   }
   self.render_html('search.html',values)
    def add_new(self, user_id, email, name, password, token):
        new_profile = Profile(
            user_id=user_id,
            email=email,
            is_logged=True,
            name=name,
            password=password,
            token=token,
        )

        db_session.add(new_profile)
        db_session.commit()

        return new_profile
Exemple #32
0
    def delete(self, key, item_type, item_key):
        user_id = g.model_db.id()
        profile = Profile.get_by('user_id', user_id)
        if auth.current_user_db().id(
        ) != user_id:  # check profile belongs to current_user
            return ApiException.error(108)

        ModelClass = Profile.ALL_STRUCTURED_PROPERTIES.get(item_type)

        success, value = ModelClass.delete(profile, item_key)
        if success:
            return value
        else:
            return ApiException.error(200, value)
 def testNextSignup(self):
     setCurrentUser("*****@*****.**", "Administrator")
     self.assertRaises(NoUserNameException, _get_my_profile)
     self.assertRaises(NoUserNameException, _get_my_profile)
     register_new_user('SiteAdmin')
     self.assertIsInstance(_get_my_profile(), Profile)
     self.assertEquals('SiteAdmin', get_my_profile_name())
     self.assertEquals(1, SiteMasterProfile.query().count())
     self.assertEquals(1, Profile.query().count())
     logoutCurrentUser()
     self.assertRaises(NoUserException, _get_my_profile)
     setCurrentUser("*****@*****.**", "NewUser1")
     self.assertRaises(NoUserNameException, _get_my_profile)
     self.assertRaises(NoUserNameException, _get_my_profile)
     '''Should create a GameMaster for this new profile with its own Place for private conversations'''
     register_new_user('NewUserOne')
     '''Should have an profile now'''
     self.assertIsInstance(_get_my_profile(), Profile)
     '''Should be called whatever it was set up as'''
     self.assertEquals('NewUserOne', get_my_profile_name())
     self.assertEquals(2, Profile.query().count())
     logoutCurrentUser()
     self.assertRaises(NoUserException, _get_my_profile)
Exemple #34
0
 def get_profile_by_title(self, title):
     """
     根据 title 从数据库表 bai_profile 里取一行(python会自动处理成字典类型),转换成程序中的一篇 profile
     :param title: 一个 key, 编码为 unicode
     :return:  Profile 类的一个实例
     """
     sql = 'select * from bai_profile where title=%s'
     sql_str = sql % title.encode('utf-8')
     CrawlerLogger.logger.info('get: {0}\n'.format(sql_str))
     MysqlLogger.logger.info('get: {0}\n'.format(sql_str))
     profile_record = self.db.get(sql, title)
     if profile_record:
         return Profile.to_profile(profile_record)  # 这里其实不用 return 实例吧?return true 给 is_exist 判断就行了吧?
     return None
Exemple #35
0
def addUser():
    user=request.get_json()
    pro=Profile(user['username'],user['email'],user['firstname'],user['lastname'],user['password'])
    db.session.add(pro)
    try:
        db.session.commit()      
    except Exception as e:
        db.session.rollback()
        logger.error("cannot insert object"+str(e))
        return jsonify("object not validated,"+str(e))
    finally:
        db.session.close()

    return jsonify("objects added to db success")
Exemple #36
0
 def get(self):
   user = users.get_current_user()
   logout_url = users.create_logout_url(self.request.uri)
   login_url = users.create_login_url(self.request.uri)
   if user:
     profile = Profile.query(Profile.user_id==user.user_id()).get()
     values = {
       'user' : user,
       'profile' : profile,
       'logout_url' : logout_url,
       'user_id' : user.user_id(),
     }
     self.render_html('profile-update.html',values)
   else:
     self.redirect(login_url)
Exemple #37
0
def create_profile(about, experience, skill, project, education, contact,
                   user_id):
    """Create and return a new profile."""

    profile = Profile(about=about,
                      experience=experience,
                      skill=skill,
                      project=project,
                      education=education,
                      contact=contact,
                      user_id=user_id)

    db.session.add(profile)
    db.session.commit()

    return profile
Exemple #38
0
def profile_update():
    """Profile updation process"""

    first_name = request.form.get("Firstname")
    last_name = request.form.get("Lastname")
    display_name = request.form.get("Displayname")
    email = request.form.get("Email")
    phonenumber = request.form.get("Phonenumber")
    date_of_birth_str = request.form.get("Birthday")
    date_of_birth = datetime.strptime(date_of_birth_str, '%Y-%m-%d')
    address_1 = request.form.get("Address1")
    address_2 = request.form.get("Address2")
    city = request.form.get("City")
    state = request.form.get("State")
    zipcode = request.form.get("Zipcode")
    country = request.form.get("Country")
    married = request.form.get("Marital_Status")
    marriage_date_str = request.form.get("Marriage_Anniversary")
    marriage_date = datetime.strptime(marriage_date_str, '%Y-%m-%d')
    kids = int(request.form.get("Kids"))
    userid = session["user_id"]

    user_profile = Profile(display_name=display_name,
                           user_id=userid,
                           email=email,
                           phonenumber=phonenumber,
                           date_of_birth=date_of_birth,
                           address_1=address_1,
                           address_2=address_2,
                           city=city,
                           state=state,
                           zipcode=zipcode,
                           country=country,
                           married=married,
                           marriage_date=marriage_date,
                           kids=kids)
    db.session.add(user_profile)
    db.session.commit()
    text = f"Birthday for {first_name} {last_name}"
    user_event = Event(profile_id=user_profile.profile_id,
                       event_type='Birthday',
                       event_date=date_of_birth,
                       event_text=text)
    db.session.add(user_event)
    db.session.commit()

    return redirect("/homepage")
Exemple #39
0
def create_profile(user,
                   description,
                   instagram,
                   twitter,
                   website,
                   profile_photo="https://picsum.photos/500/350?nocache"):

    profile = Profile(user=user,
                      description=description,
                      instagram=instagram,
                      twitter=twitter,
                      website=website,
                      profile_photo=profile_photo)

    db.session.add(profile)
    db.session.commit()
    return profile
Exemple #40
0
    def post(self, key, item_type):
        user_id = g.model_db.id()
        profile = Profile.get_by('user_id', user_id)
        if auth.current_user_db().id(
        ) != user_id:  # check profile belongs to current_user
            return ApiException.error(108)

        ModelClass = Profile.ALL_STRUCTURED_PROPERTIES.get(item_type)
        data = request.json
        if not data:
            return ApiException.error(200)

        success, value = ModelClass.create(profile, data)
        if success:
            return value
        else:
            return ApiException.error(200, value)
Exemple #41
0
def OnDocumentChanged(event, wavelet):
  blip = event.blip

  interests = []
  for e in blip.elements:
    if isinstance(e, element.Check):
      if e.value == 'true':
        interests.append(e.name)

  fullname = ''
  nameinput = blip.first(element.Input, name='fullname')
  if nameinput:
    fullname = nameinput.get('value','')
  profile = Profile.get_or_insert(wavelet.wave_id)
  profile.name = fullname
  profile.creator = wavelet.creator
  profile.interests = interests
  profile.put()
 def testFirstSignup(self):
     setCurrentUser("*****@*****.**", "Administrator")
     '''Should fail repeatedly with a NoUserNameException'''
     self.assertRaises(NoUserNameException, _get_my_profile)
     self.assertRaises(NoUserNameException, _get_my_profile)
     '''Should create the Site Administrator with its own place for template Roles'''
     register_new_user('SiteAdmin')
     '''Should have a SiteAdmin now'''
     self.assertIsInstance(_get_my_profile(), SiteMasterProfile)
     self.assertEquals(SiteMasterProfile.query().count(), 1)
     self.assertEquals(Profile.query().count(), 1)
     '''Should be called whatever it was set up as'''
     self.assertEquals('SiteAdmin', get_my_profile_name())
     '''Check number of entities'''
     self.assertEquals(1, SiteMasterProfile.query().count())
     '''Should just fail with a NoUserException if logged out'''
     logoutCurrentUser()
     self.assertRaises(NoUserException, _get_my_profile)
Exemple #43
0
def register():
    form = CreateProfileForm(request.form)

    print "###NAME{}".format(form.firstname.data)
    if request.method == 'POST':#and form.validate():
        print "###############################################################"
        profile = Profile(form.firstname.data, form.lastname.data, form.username.data, form.gender.data, form.age.data, form.bio.data, form.password.data, datetime.utcnow())
        print "LETS see{}".format(profile)
        print "###############################################################"
        print form.firstname.data
        db.session.add(profile)
        db.session.commit()
        file = request.files['file']
        filename = file.filename#form.username.data#file.filename
        file.save(os.path.join("app/static/profilepics", filename))
        flash('Thank you for registering')
        return redirect(url_for('login'))
    return render_template('register.html',form=form)
Exemple #44
0
 def import_from_lines(self, lines):
     """
         从多行数据录入数据库
         :param lines: 待处理数据
         :return:  读取到的记录数量,成功录入的记录数量
         """
     (total, succ) = (0, 0)
     for line in lines:
         total += 1
         items = line.decode('utf-8').strip().split('\t')  # 数据库接收的是 unicode,所以要解码
         if len(items) < 7:
             CrawlerLogger.logger.info('line format error: {0}'.format(line))
             continue
         tmp_profile = Profile(0, items[0], items[1], items[2], items[3], items[4], items[5], items[6])
         if not self.insert_one_profile(tmp_profile):
             CrawlerLogger.logger.info('insert line failed: {0}'.format(line))
         else:
             succ += 1
     return total, succ
 def create(self):
     name = self.text_entry.text
     if len(name) > 0:
         today = date.today().isoformat()
         profile = Profile(name=name,
                           created_date=today,
                           modified_date=today)
         session = context['db_session']
         session.add(profile)
         # TODO: when supporting multiple characters per profile, move these
         character = Character(profile=profile,
                               name=name,
                               created_date=today,
                               modified_date=today,
                               gold=0,
                               enemies=0)
         session.add(character)
         session.commit()
         self.manager.set_screen('list_profiles')
def OnBlipSubmitted(event, wavelet):
  """The map gadget can only be edited when the blip
  is in write mode, so we can safely handle updates
  to the user location in the BlipSubmitted event.
  """
  blip = event.blip

  mapgadget = blip.all(element.Gadget).value()
  coord = None
  for key in mapgadget.keys():
    if key.startswith('overlay-'):
      mapdata = simplejson.loads(getattr(mapgadget, key))
      if mapdata['type'] == 'point':
        coord = mapdata['coordinates'][0]

  profile = Profile.get_or_insert(wavelet.wave_id)
  oldlocation = profile.location
  if coord:
    profile.location = db.GeoPt(coord['lat'], coord['lng']) 
    profile.update_location()
    logging.debug(profile.location)
    if ( oldlocation is None ) or ( oldlocation != profile.location ):
      if oldlocation:
        logging.debug(oldlocation)
      # search for gtugs
      logging.debug(profile.location)
      results = GTUG.proximity_fetch(
          GTUG.all(),
          profile.location,
          max_results=5,
          max_distance=80467
          ) 
      if results:
        gtugblip = blip.reply()
        gtugblip.append_markup("<p>Great news, we found a Google Technology User Group near you!</p>")
        gtugblip.append(element.Line())
        gtugblip.append(element.Line())
        gtugblip.append_markup("<p>The group name is </p>")
        gtugblip.append(results[0].key().name(), [
          ('link/manual', results[0].url)
          ])
  profile.put()
Exemple #47
0
def register_new_user(name):
    ''' register a Profile for the current user as long as the name hasn't been used and the user doesn't already have a Profile '''
    if name is None:
        raise ActionException('Name is required')
    if len(Profile.query(Profile.name_order == name.upper()).fetch(1)) > 0:
        raise ActionException('Name has been used by someone else')
    profile, userid = _get_profile()
    if profile is None:
        sm = _get_site_master()
        if sm is None:
            profile = SiteMasterProfile(id=userid)
            profile.free_games = 1
            profile.free_places = 2
        else:
            profile = Profile(id=userid)
    else:
        raise ActionException('User already has a profile')
    profile.name = name
    profile.name_order = name.upper()
    profile.updated = datetime.now()
    profile.playing = profile.key
    profile.put()
    return profile.key.urlsafe()
Exemple #48
0
def config():
  profile = Profile(name = "Wallowsss")
  profile.title = "...a geek dreamer..."
  profile.subtitle = "I'm a human that promised to himself that will realize all dreams that had been dreamed."
  profile.description = "I'm starting again in my professional life as trainee of an important global consulting, before that I was a Programmer Analyst. Studying information security mobile, project management, some programming languages and all important things that I'm sure are bringing benefits to my growth."
  profile.put()
  services = Services(service = "Twitter")
  services.tumbnail = "/images/twitter.png"
  services.link = "http://www.twitter.com/wallowsss"
  services.put()
  services = Services(service = "Facebook")
  services.tumbnail = "/images/facebook.png"
  services.link = "http://www.facebook.com/wallowsss"
  services.put()
  services = Services(service = "Google Plus")
  services.tumbnail = "/images/gplus.png"
  services.link = "http://www.google.com/profiles/coutinho90"
  services.put()
  services = Services(service = "Linkedin")
  services.tumbnail = "/images/linkedin.png"
  services.link = "http://br.linkedin.com/in/wallacebarbosa"
  services.put()
Exemple #49
0
  def text_message(self, message):
    access_token_key = 'access_token_%s' % message.sender.partition('/')[0]
    access_token = gdata.gauth.ae_load(access_token_key)
    gcal.auth_token = access_token
    
    if message.body.startswith('.'):
      current_calendar = message.body.lstrip('.').strip()
      feed = gcal.GetOwnCalendarsFeed()
      gdata.calendar.data.CalendarEntry
      for i, a_calendar in enumerate(feed.entry):
        if a_calendar.title.text == current_calendar:
          query = db.GqlQuery(
                              "SELECT * FROM Profile WHERE email = :1", 
                              message.sender.partition('/')[0])
          profiles = query.fetch(100)
          for profile in profiles:
            profile.current_calendar = current_calendar
            profile.save()
            xmpp.send_message(
                              jids=message.sender, 
                              body='Current calendar switched to %s' % profile.current_calendar, 
                              from_jid="*****@*****.**")
            return

          profile = Profile(
                            email = message.sender.partition('/')[0],
                            current_calendar = current_calendar)
          profile.put()
          xmpp.send_message(
                            jids=message.sender, 
                            body='Current calendar switched to %s' % profile.current_calendar, 
                            from_jid="*****@*****.**")
          return
      xmpp.send_message(jids=message.sender, body='calendar not found', from_jid="*****@*****.**")
      return

    format = '%Y-%m-%dT%H:%M:%S.000Z'

    start_time = time.gmtime()
    end_time = time.gmtime(time.time() + 3600)
    
    str_start_time = time.strftime(format, start_time)
    str_end_time = time.strftime(format, end_time)
    
    prev_event_end_time = time.gmtime(time.time() - 60)

    profile = Profile.all().filter("email =", message.sender.partition('/')[0]).get()
    
    event = gdata.calendar.data.CalendarEventEntry()
    event.title = atom.data.Title(text=message.body)
    event.content = atom.data.Content(text="createdby:talk")
    event.when.append(gdata.calendar.data.When(start=str_start_time, end=str_end_time))

    own_calendars_feed = gcal.GetOwnCalendarsFeed()    
    if (profile is None):
      event = gcal.InsertEvent(event)
    else:
      for i, a_calendar in enumerate(own_calendars_feed.entry):
        if (profile.current_calendar == a_calendar.title.text):
          calendar_id = a_calendar.link[0].href
          calendar_event_feed = gcal.get_calendar_event_feed(uri=calendar_id)
          event = gcal.InsertEvent(event, insert_uri=calendar_id)
    
    for when in event.when:
      str_start_time = when.start
      str_end_time = when.end

    query = gdata.calendar.client.CalendarEventQuery()
    query.start_max = str_start_time
    
    #fix latest event
    for i, a_calendar in enumerate(own_calendars_feed.entry):
      calendar_id = a_calendar.link[0].href
      calendar_event_feed = gcal.get_calendar_event_feed(uri=calendar_id, q=query)
    
      for i, an_event in enumerate(calendar_event_feed.entry):
        for a_when in an_event.when:
          if a_when.end >= str_start_time and an_event.content.text is not None and "createdby:talk" in an_event.content.text:
            try:
              a_when.end = time.strftime(format, prev_event_end_time)
              gcal.Update(an_event)
            except:
              continue

    xmpp.send_message(jids=message.sender, body=message.body, from_jid="*****@*****.**")      
Exemple #50
0
def scrape_instagram_account(username):
    ''' Scrape instagram bio data and create (or update) a profile. '''

    # Getting a user ID is more difficult than it ought to be: you need to
    # search for the username and iterate through the search results results to
    # find an exact match.
    db_session = worker.get_session()
    proxies = _get_proxies(db_session)

    api_url = 'https://api.instagram.com/v1/users/search'
    params = {'q': username}

    response = requests.get(
        api_url,
        params=params,
        proxies=proxies,
        verify=False
    )

    response.raise_for_status()
    search_results = response.json()
    username_lower = username.lower()
    user_id = None

    for user_result in search_results['data']:
        if user_result['username'].lower() == username_lower:
            user_id = user_result['id']
            break

    if user_id is None:
        raise ScrapeException('Can\'t find Instagram user named {}.'
                              .format(username))

    # Now make another request to get this user's profile data.
    api_url = 'https://api.instagram.com/v1/users/{}'.format(user_id)

    response = requests.get(
        api_url,
        proxies=proxies,
        verify=False
    )

    response.raise_for_status()
    data = response.json()['data']
    profile = Profile('instagram', user_id, data['username'])
    db_session.add(profile)

    try:
        db_session.commit()
    except IntegrityError:
        # Already exists: use the existing profile.
        db_session.rollback()
        profile = db_session.query(Profile) \
                            .filter(Profile.site=='instagram') \
                            .filter(Profile.upstream_id==user_id) \
                            .one()

    profile.description = data['bio']
    profile.follower_count = int(data['counts']['followed_by'])
    profile.friend_count = int(data['counts']['follows'])
    profile.homepage = data['website']
    profile.name = data['full_name']
    profile.post_count = int(data['counts']['media'])
    profile.is_stub = False
    db_session.commit()

    # Schedule followup jobs.
    app.queue.schedule_avatar(profile, data['profile_picture'])
    app.queue.schedule_index_profile(profile)
    app.queue.schedule_posts(profile, recent=True)
    app.queue.schedule_relations(profile)

    return profile.as_dict()
Exemple #51
0
def scrape_instagram_relations(id_):
    '''
    Fetch friends and followers for the Instagram user identified by `id_`.
    The number of friends and followers to fetch is configured in Admin.
    '''
    redis = worker.get_redis()
    db = worker.get_session()
    profile = db.query(Profile).filter(Profile.id==id_).first()
    proxies = _get_proxies(db)
    friends_results = 0
    followers_results = 0
    #max_results = _get_max_relations(db)['instagram']
    max_results = get_config(db, 'max_relations_instagram', required=True).value

    try:
        max_results = int(max_results)
    except:
        raise ScrapeException(
            'Value of max_relations_instagram must be an integer'
        )

    friends_params = {}
    followers_params = {}
    total_results = max_results*2

    if profile is None:
        raise ValueError('No profile exists with id={}'.format(id_))

    # Get friends currently stored in db for this profile.
    friends_query = \
        db.query(Profile.upstream_id) \
            .join(\
                profile_join_self, \
                (profile_join_self.c.friend_id == Profile.id)
            ) \
            .filter(profile_join_self.c.follower_id == id_)
    current_friends_ids = [friend.upstream_id for friend in friends_query]

    # Get followers currently stored in db for this profile.
    followers_query = \
        db.query(Profile.upstream_id) \
            .join(\
                profile_join_self, \
                (profile_join_self.c.follower_id == Profile.id)
            ) \
            .filter(profile_join_self.c.friend_id == id_)
    current_followers_ids = [follower.upstream_id for follower in followers_query]

    worker.start_job(total=total_results)

    # Get friend IDs.
    friends_url = 'https://api.instagram.com/v1/users/{}/follows' \
                  .format(profile.upstream_id)

    while friends_results < max_results:
        # Get friends from Instagram API
        friends_response = requests.get(
            friends_url,
            params=friends_params,
            proxies=proxies,
            verify=False
        )
        friends_response.raise_for_status()
        pagination = friends_response.json()['pagination']

        for friend in friends_response.json()['data']:
            # Only store friends that are not already in db.
            if friend['id'] not in current_friends_ids:
                related_profile = Profile(
                    'instagram',
                    friend['id'],
                    friend['username'],
                    is_stub=True
                )

                db.add(related_profile)

                try:
                    db.commit()
                except IntegrityError:
                    db.rollback()
                    related_profile = db \
                            .query(Profile) \
                            .filter(Profile.site=='instagram') \
                            .filter(Profile.upstream_id==friend['id']) \
                            .one()

                related_profile.name = friend['full_name']
                profile.friends.append(related_profile)
                friends_results += 1
                worker.update_job(current=friends_results)

                if friends_results == max_results:
                    break

        # If there are more results, set the cursor paramater, otherwise finish
        if 'next_cursor' in pagination:
            friends_params['cursor'] = pagination['next_cursor']
        else:
            break # No more results

    # Get follower IDs.
    followers_url = 'https://api.instagram.com/v1/users/{}/followed-by' \
                    .format(profile.upstream_id)

    # Get followers from Instagram API
    while followers_results < max_results:
        # Get friends from Instagram API
        followers_response = requests.get(
            followers_url,
            params=followers_params,
            proxies=proxies,
            verify=False
        )
        followers_response.raise_for_status()
        pagination = followers_response.json()['pagination']

        for follower in followers_response.json()['data']:
            # Only store followers that are not already in db.
            if follower['id'] not in current_followers_ids:
                related_profile = Profile(
                    'instagram',
                    follower['id'],
                    follower['username'],
                    is_stub=True
                )

                db.add(related_profile)

                try:
                    db.commit()
                except IntegrityError:
                    db.rollback()
                    related_profile = db \
                            .query(Profile) \
                            .filter(Profile.site=='instagram') \
                            .filter(Profile.upstream_id==follower['id']) \
                            .one()

                related_profile.name = follower['full_name']
                profile.followers.append(related_profile)
                followers_results += 1
                worker.update_job(current=friends_results + followers_results)

                if followers_results == max_results:
                    break

        # If there are more results, set the cursor paramater, otherwise finish
        if 'next_cursor' in pagination:
            followers_params['cursor'] = pagination['next_cursor']
        else:
            break # No more results

    worker.finish_job()
    redis.publish('profile_relations', json.dumps({'id': id_}))
Exemple #52
0
    def _create_sample_profiles(self, config):
        ''' Create some sample profiles. '''

        session = app.database.get_session(self._db)
        sample_dir = os.path.join(os.path.dirname(__file__), 'sample-data')

        # Maurice Moss
        moss_twitter = Profile(
            site='twitter',
            upstream_id='12345',
            username=ProfileUsername('maurice.moss', start_date='2014-04-01')
        )

        moss_twitter.usernames.append(ProfileUsername(
            'maurice',
            start_date='2013-06-01',
            end_date='2014-03-31'
        ))

        moss_twitter.usernames.append(ProfileUsername(
            'maurie',
            start_date='2013-02-15',
            end_date='2013-05-30'
        ))

        Post(
            author=moss_twitter,
            content='Going to the grocery store.',
            upstream_id='1234',
            upstream_created='2015-02-04 12:34:50'
        )

        post = Post(
            author=moss_twitter,
            content='Love this band!.',
            upstream_id='2345',
            upstream_created='2015-03-01'
        )

        post.attachments.append(File(
            name='helloworld.txt',
            mime='text/plain',
            content='Hello world!\n\n'.encode('utf8')
        ))

        moss_twitter.posts.append(post)

        with open(os.path.join(sample_dir, 'moss.jpg'), 'rb') as moss_jpg:
            moss_twitter.avatars.append(Avatar(
                url='http://foobar.com/moss-avatar.jpg',
                mime='image/jpeg',
                image=moss_jpg.read()
            ))

        moss_twitter.description = "I do IT at Reynholm Industries."
        moss_twitter.post_count = 1205
        moss_twitter.friend_count = 1
        moss_twitter.follower_count = 3
        moss_twitter.join_date = dateutil.parser.parse('2013-06-01')
        moss_twitter.join_date_is_exact = False

        session.add(moss_twitter)

        # Jen Barber
        jen_twitter = Profile(
            site='twitter',
            upstream_id='23456',
            username=ProfileUsername('jen.barber', start_date='2013-11-12')
        )

        jen_twitter.usernames.append(ProfileUsername(
            'jenb',
            start_date='2013-06-14',
            end_date='2013-11-12'
        ))

        jen_twitter.usernames.append(ProfileUsername(
            'jenny',
            start_date='2013-03-15',
            end_date='2013-06-14'
        ))

        with open(os.path.join(sample_dir, 'jen.jpg'), 'rb') as jen_jpg:
            jen_twitter.avatars.append(Avatar(
                url='http://foobar.com/jen-avatar.jpg',
                mime='image/jpeg',
                image=jen_jpg.read()
            ))

        jen_twitter.description = "Relationship Manager for the IT department."
        jen_twitter.post_count = 1543
        jen_twitter.friend_count = 1
        jen_twitter.follower_count = 1
        jen_twitter.join_date = dateutil.parser.parse('2013-03-15')
        jen_twitter.join_date_is_exact = True

        moss_twitter.followers.append(jen_twitter)

        session.add(jen_twitter)

        # A couple of randos.
        moss_twitter.followers.append(Profile(
            site='twitter',
            upstream_id='345678',
            username='******'
        ))

        moss_twitter.followers.append(Profile(
            site='twitter',
            upstream_id='456789',
            username='******'
        ))

        jen_twitter.followers.append(Profile(
            site='twitter',
            upstream_id='567890',
            username='******'
        ))

        session.commit()