Esempio n. 1
0
def index():
    created = False
    error = False
    if request.method == 'POST':
        try:
            assert request.form['username'] != ''
            assert request.form['fogbugz_token'] != ''
            assert request.form['trello_token'] != ''
        except:
            error = "Not all fields were filled in!"
        else:
            try:
                user = User(
                    username=request.form['username'],
                    trello_token=request.form['trello_token'],
                    fogbugz_token=request.form['fogbugz_token'],
                )
                db_session.add(user)
                db_session.commit()
            except TrelloTokenError:
                error = "Invalid Trello token!"
            except FogbugzTokenError:
                error = "Invalid Fogbugz Token!"
            except Exception as e:
                error = "Unexpected error! {0}".format(repr(e))
            else:
                created = True
    return render_template('submit.html', created=created, error=error)
Esempio n. 2
0
    def update_event(self, event_id, interest_key):
        user_id = UserController().current_user_id
        if user_id:
            user_event = UserEvent.query.filter(
                and_(UserEvent.user_id == user_id,
                     UserEvent.event_id == event_id)).first()

            if user_event:
                if interest_key == UserEvent.DONE:
                    if user_event.interest_key == interest_key:
                        user_event.interest = user_event.interest - 2
                    else:
                        user_event.interest = user_event.interest + 2
                elif user_event.interest_key == interest_key:
                    user_event.interest = None
                else:
                    user_event.interest = UserEvent.interest_level(
                        interest_key)
                db_session.merge(user_event)
            else:
                user_event = UserEvent(
                    user_id=user_id,
                    event_id=event_id,
                    interest=UserEvent.interest_level(interest_key))
                db_session.add(user_event)
            db_session.commit()

            return self.get_event(event_id)
        return None
Esempio n. 3
0
def index():
    created = False
    error = False
    if request.method == 'POST':
        try:
            assert request.form['username'] != ''
            assert request.form['fogbugz_token'] != ''
            assert request.form['trello_token'] != ''
        except:
            error = "Not all fields were filled in!"
        else:
            try:
                user = User(
                    username=request.form['username'],
                    trello_token=request.form['trello_token'],
                    fogbugz_token=request.form['fogbugz_token'],
                )
                db_session.add(user)
                db_session.commit()
            except TrelloTokenError:
                error = "Invalid Trello token!"
            except FogbugzTokenError:
                error = "Invalid Fogbugz Token!"
            except Exception as e:
                error = "Unexpected error! {0}".format(repr(e))
            else:
                created = True
    return render_template('submit.html', created=created, error=error)
Esempio n. 4
0
    def _request_user_info(self):
        credentials = google.oauth2.credentials.Credentials(
            **session['credentials'])

        people_service = build('people', 'v1', credentials=credentials)
        profile = people_service.people().get(
            resourceName='people/me',
            personFields='names,emailAddresses,photos').execute()

        primary_email = profile['emailAddresses'][0]
        for cur_email in profile['emailAddresses']:
            if cur_email['metadata']['primary']:
                primary_email = cur_email

        primary_name = profile['names'][0]
        for cur_name in profile['names']:
            if cur_name['metadata']['primary']:
                primary_name = cur_name

        primary_photo = profile['photos'][0]
        for cur_photo in profile['photos']:
            if cur_photo['metadata']['primary']:
                primary_photo = cur_photo

        google_auth_id = profile['resourceName'].split("/")[1]
        user = {
            'username': primary_email['value'].split("@")[0],
            'email': primary_email['value'],
            'display_name': primary_name['displayName'],
            'first_name': primary_name['givenName'],
            'last_name': primary_name['familyName'],
            'image_url': primary_photo['url'],
        }

        row_user_auth = UserAuth.query.filter(
            and_(UserAuth.auth_key == Auth.GOOGLE,
                 UserAuth.auth_id == google_auth_id)).first()
        if not row_user_auth:
            row_user = User(**user)
            db_session.add(row_user)
            db_session.commit()

            row_user_auth = UserAuth(user_id=row_user.user_id,
                                     auth_key=Auth.GOOGLE,
                                     auth_id=google_auth_id)
            db_session.add(row_user_auth)
            db_session.commit()
        else:
            row_user = row_user_auth.user
            for k, v in user.items():
                setattr(row_user, k, v)
            db_session.merge(row_user)
            db_session.commit()

        session['user'] = row_user.to_json()

        return session['user']
Esempio n. 5
0
def get_or_create(case_number):
    if not case_number:
        case_number = 0
    try:
        case = Case.query.filter(Case.case_number == case_number).one()
        case.doing = []
        return case
    except NoResultFound:
        case = Case(case_number)
        db_session.add(case)
        return case
Esempio n. 6
0
    def post(self):
        username = request.form['username']
        password = request.form['password']

        new_user = User(username, password)
        db_session.add(new_user)
        db_session.commit()

        session['loggedIn'] = True
        session['username'] = username
        return redirect('/')
Esempio n. 7
0
    def extract(self, start_date=None, end_date=None):
        discover = tmdb.Discover()

        event_params = {
            'include_adult': False,
            'include_video': False,
            'sort_by': 'release_date.asc',
            'with_original_language': 'en',
            'vote_average.gte': 7,
            'vote_count.gte': 1000
        }

        event_params.update(
            self.parse_time_args(start_date=start_date, end_date=end_date))

        print(json.dumps(event_params, indent=4))

        sentinel = True
        while sentinel:
            raw_events = discover.movie(**event_params)

            for i, event in enumerate(raw_events['results']):
                connector_event_id = str(event['id'])

                row_connector_event = ConnectorEvent.query.filter(
                    and_(
                        ConnectorEvent.connector_event_id ==
                        connector_event_id,
                        ConnectorEvent.connector_type == self.TYPE)).first()

                if not row_connector_event:
                    row_connector_event = ConnectorEvent(
                        connector_event_id=connector_event_id,
                        connector_type=self.TYPE,
                        data=event)
                    db_session.merge(row_connector_event)
                    db_session.commit()

                event_name = row_connector_event.data['title']
                event_description = row_connector_event.data['overview']
                event_short_name = row_connector_event.data['title']
                event_img_url = 'https://image.tmdb.org/t/p/w342{}'.format(
                    row_connector_event.data['poster_path'])
                event_backdrop_url = 'https://image.tmdb.org/t/p/original{}'.format(
                    row_connector_event.data['backdrop_path'])

                event_start_time = datetime.datetime.strptime(
                    row_connector_event.data['release_date'], "%Y-%m-%d")
                event_end_time = event_start_time + datetime.timedelta(
                    days=180)

                genres = self.genres_by_ids(
                    row_connector_event.data['genre_ids'])

                if row_connector_event.event_id:
                    row_event = Event.query.filter(
                        Event.event_id ==
                        row_connector_event.event_id).first()
                    row_event.name = event_name
                    row_event.description = event_description
                    row_event.short_name = event_name
                    row_event.img_url = event_img_url
                    row_event.backdrop_url = event_backdrop_url
                    row_event.start_time = event_start_time
                    row_event.end_time = event_end_time
                    db_session.merge(row_event)
                    db_session.commit()

                    row_event.remove_all_tags()
                else:
                    row_event = Event(name=event_name,
                                      description=event_description,
                                      short_name=event_short_name,
                                      img_url=event_img_url,
                                      backdrop_url=event_backdrop_url,
                                      start_time=event_start_time,
                                      end_time=event_end_time)
                    row_event.primary_type = Tag.TVM
                    db_session.add(row_event)
                    db_session.commit()

                    row_connector_event.event_id = row_event.event_id
                    db_session.merge(row_connector_event)
                    db_session.commit()

                for genre in genres:
                    row_event.add_tag(genre, Tag.TVM)

                row_event.update_meta(self.TYPE, event)
                db_session.merge(row_event)
                db_session.commit()

                yield row_event, "{} {}".format(row_event.name, genres)

            del raw_events['results']

            sentinel = raw_events['page'] < raw_events['total_pages']
            if sentinel:
                event_params['page'] = raw_events['page'] + 1